Backup MySQL_DB in its own bucket.

This commit is contained in:
yohan 2024-04-28 10:28:53 +02:00
parent 822d7ce5c3
commit 53069fddb9
5 changed files with 65 additions and 51 deletions

View File

@ -19,9 +19,15 @@
name: python3-swiftclient name: python3-swiftclient
state: present state: present
- name: Archive volume - name: Backup standard volume
ansible.builtin.include_tasks: "tasks/backup_volume.yml" ansible.builtin.include_tasks: "tasks/backup_volume.yml"
with_items: "{{ BACKUP_OVH1_VOLUMES }}" with_items: "{{ BACKUP_OVH1_VOLUMES }}"
- name: Archive MySQL DB - name: Prepare MySQL_DB backup volume
ansible.builtin.include_tasks: "tasks/backup_mysql_db.yml" ansible.builtin.include_tasks: "tasks/prepare_MySQL_DB_backup_volume.yml"
- name: Backup last MySQL dumps
ansible.builtin.include_tasks: "tasks/backup_volume.yml"
with_items:
- name: MySQL_DB
dir: "{{ WORKDIR }}/backup/MySQL_DB"

View File

@ -1,24 +0,0 @@
---
- name: Create backup directory
ansible.builtin.file:
path: "{{ WORKDIR }}/backup/MySQL_DB"
state: directory
- name: Find lastest MySQL DB dump
ansible.builtin.shell: "cd /mnt/volumes; ls -tr mysql-server_dumps/data/mysql_dump-mysql_*"
register: MySQL_dump
- name: Find lastest applications DB dump
ansible.builtin.shell: "cd /mnt/volumes; ls -tr mysql-server_dumps/data/mysql_dump_*"
register: DBs_dump
- name: Archive DB dumps
ansible.builtin.command: "cp -a /mnt/volumes/{{ MySQL_dump.stdout_lines | last }} /mnt/volumes/{{ DBs_dump.stdout_lines | last }} {{ WORKDIR }}/backup/MySQL_DB/"
- name: Backup with duplicity
ansible.builtin.command: "duplicity --num-retries 3 --full-if-older-than 1M --progress --archive-dir {{ ARCHIVE_DIR }} --name MySQL_DB --allow-source-mismatch '{{ WORKDIR }}/backup/MySQL_DB' swift://{{ lookup('env','BACKUP_WORKFLOW') }}"
environment: "{{ DUPLICITY_ENVIRONMENT }}"
- name: Clean old duplicity backups
ansible.builtin.command: "duplicity remove-older-than 2M --archive-dir {{ ARCHIVE_DIR }} --name MySQL_DB --allow-source-mismatch --force swift://{{ lookup('env','BACKUP_WORKFLOW') }}"
environment: "{{ DUPLICITY_ENVIRONMENT }}"

View File

@ -1,25 +1,26 @@
--- ---
- name: Find hard links in /mnt/volumes/{{ item }}/data - name: Find hard links in {{ item.dir }}
ansible.builtin.command: "find '/mnt/volumes/{{ item }}/data' -type f -links +1" ansible.builtin.command: "find '{{ item.dir }}' -type f -links +1"
register: find_hard_links register: find_hard_links
# Duplicity does not support hard links # Duplicity does not support hard links
- name: Assert that there is no hard links in /mnt/volumes/{{ item }}/data - name: Assert that there is no hard links in {{ item.dir }}
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- find_hard_links.stdout | length == 0 - find_hard_links.stdout | length == 0
msg: "Duplicity does not support hard links." msg: "Duplicity does not support hard links."
- name: Create SWIFT bucket {{ item }} - name: Create SWIFT bucket {{ item.name }}
openstack.cloud.object_container: openstack.cloud.object_container:
name: "{{ item }}" name: "{{ item.name }}"
state: present state: present
environment: "{{ DUPLICITY_ENVIRONMENT }}" environment: "{{ DUPLICITY_ENVIRONMENT }}"
- name: Backup /mnt/volumes/{{ item }}/data with duplicity - name: Backup {{ item.dir }} with duplicity
ansible.builtin.command: "duplicity --num-retries 3 --full-if-older-than 1M --progress --archive-dir {{ ARCHIVE_DIR }} --name {{ item }} --allow-source-mismatch '/mnt/volumes/{{ item }}/data' swift://{{ item }}" ansible.builtin.command: "duplicity --num-retries 3 --full-if-older-than 1M --progress --archive-dir {{ ARCHIVE_DIR }} --name {{ item.name }} --allow-source-mismatch '{{ item.dir }}' swift://{{ item.name }}"
environment: "{{ DUPLICITY_ENVIRONMENT }}" environment: "{{ DUPLICITY_ENVIRONMENT }}"
- name: Clean old duplicity backups for {{ item }} - name: Clean old duplicity backups for {{ item.name }}
ansible.builtin.command: "duplicity remove-older-than 2M --archive-dir {{ ARCHIVE_DIR }} --name {{ item }} --allow-source-mismatch --force swift://{{ item }}" ansible.builtin.command: "duplicity remove-older-than 2M --archive-dir {{ ARCHIVE_DIR }} --name {{ item.name }} --allow-source-mismatch --force swift://{{ item.name }}"
environment: "{{ DUPLICITY_ENVIRONMENT }}" environment: "{{ DUPLICITY_ENVIRONMENT }}"

View File

@ -0,0 +1,16 @@
---
- name: Create backup directory
ansible.builtin.file:
path: "{{ WORKDIR }}/backup/MySQL_DB"
state: directory
- name: Find lastest MySQL DB dump
ansible.builtin.shell: "cd /mnt/volumes; ls -tr mysql-server_dumps/data/mysql_dump-mysql_*"
register: MySQL_dump
- name: Find lastest applications DB dump
ansible.builtin.shell: "cd /mnt/volumes; ls -tr mysql-server_dumps/data/mysql_dump_*"
register: DBs_dump
- name: Copy last DB dumps in backup directory
ansible.builtin.command: "cp -a /mnt/volumes/{{ MySQL_dump.stdout_lines | last }} /mnt/volumes/{{ DBs_dump.stdout_lines | last }} {{ WORKDIR }}/backup/MySQL_DB/"

View File

@ -27,21 +27,36 @@ BOOTSTRAP_REQUIRED_ENV_VARS:
- BACKUP_WORKFLOW - BACKUP_WORKFLOW
BACKUP_OVH1_VOLUMES: BACKUP_OVH1_VOLUMES:
- elasticsearch_data - name: elasticsearch_data
- gogs_data dir: /mnt/volumes/elasticsearch_data/data
- mail_data - name: gogs_data
- nextcloud dir: /mnt/volumes/gogs_data/data
- reverse-proxy_conf - name: mail_data
- reverse-proxy_conf_enabled dir: /mnt/volumes/mail_data/data
- reverse-proxy_letsencrypt - name: nextcloud
- scuttle_code dir: /mnt/volumes/nextcloud/data
- scuttle_php5-fpm_conf - name: reverse-proxy_conf
- etc_grafana dir: /mnt/volumes/reverse-proxy_conf/data
- var_lib_grafana - name: reverse-proxy_conf_enabled
- var_log_grafana dir: /mnt/volumes/reverse-proxy_conf_enabled/data
- registry_data - name: reverse-proxy_letsencrypt
- registry_auth dir: /mnt/volumes/reverse-proxy_letsencrypt/data
- registry_certs - name: scuttle_code
dir: /mnt/volumes/scuttle_code/data
- name: scuttle_php5-fpm_conf
dir: /mnt/volumes/scuttle_php5-fpm_conf/data
- name: etc_grafana
dir: /mnt/volumes/etc_grafana/data
- name: var_lib_grafana
dir: /mnt/volumes/var_lib_grafana/data
- name: var_log_grafana
dir: /mnt/volumes/var_log_grafana/data
- name: registry_data
dir: /mnt/volumes/registry_data/data
- name: registry_auth
dir: /mnt/volumes/registry_auth/data
- name: registry_certs
dir: /mnt/volumes/registry_certs/data
BACKUP_OVH1_REQUIRED_ENV_VARS: BACKUP_OVH1_REQUIRED_ENV_VARS:
- OS_AUTH_URL - OS_AUTH_URL