From 53069fddb9f84750e7c0a046518a418cb6710a27 Mon Sep 17 00:00:00 2001 From: yohan <783b8c87@scimetis.net> Date: Sun, 28 Apr 2024 10:28:53 +0200 Subject: [PATCH] Backup MySQL_DB in its own bucket. --- backup_ovh1.yml | 12 +++++-- tasks/backup_mysql_db.yml | 24 ------------- tasks/backup_volume.yml | 19 +++++----- tasks/prepare_MySQL_DB_backup_volume.yml | 16 +++++++++ vars/main.yml | 45 ++++++++++++++++-------- 5 files changed, 65 insertions(+), 51 deletions(-) delete mode 100755 tasks/backup_mysql_db.yml create mode 100755 tasks/prepare_MySQL_DB_backup_volume.yml diff --git a/backup_ovh1.yml b/backup_ovh1.yml index 47436da..e7d5957 100755 --- a/backup_ovh1.yml +++ b/backup_ovh1.yml @@ -19,9 +19,15 @@ name: python3-swiftclient state: present - - name: Archive volume + - name: Backup standard volume ansible.builtin.include_tasks: "tasks/backup_volume.yml" with_items: "{{ BACKUP_OVH1_VOLUMES }}" - - name: Archive MySQL DB - ansible.builtin.include_tasks: "tasks/backup_mysql_db.yml" + - name: Prepare MySQL_DB backup volume + 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" diff --git a/tasks/backup_mysql_db.yml b/tasks/backup_mysql_db.yml deleted file mode 100755 index b79cb69..0000000 --- a/tasks/backup_mysql_db.yml +++ /dev/null @@ -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 }}" diff --git a/tasks/backup_volume.yml b/tasks/backup_volume.yml index 202ad5f..5cdf00b 100755 --- a/tasks/backup_volume.yml +++ b/tasks/backup_volume.yml @@ -1,25 +1,26 @@ --- -- name: Find hard links in /mnt/volumes/{{ item }}/data - ansible.builtin.command: "find '/mnt/volumes/{{ item }}/data' -type f -links +1" +- name: Find hard links in {{ item.dir }} + ansible.builtin.command: "find '{{ item.dir }}' -type f -links +1" register: find_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: that: - find_hard_links.stdout | length == 0 msg: "Duplicity does not support hard links." -- name: Create SWIFT bucket {{ item }} +- name: Create SWIFT bucket {{ item.name }} openstack.cloud.object_container: - name: "{{ item }}" + name: "{{ item.name }}" state: present environment: "{{ DUPLICITY_ENVIRONMENT }}" -- name: Backup /mnt/volumes/{{ item }}/data 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 }}" +- 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.name }} --allow-source-mismatch '{{ item.dir }}' swift://{{ item.name }}" environment: "{{ DUPLICITY_ENVIRONMENT }}" -- name: Clean old duplicity backups for {{ item }} - ansible.builtin.command: "duplicity remove-older-than 2M --archive-dir {{ ARCHIVE_DIR }} --name {{ item }} --allow-source-mismatch --force swift://{{ item }}" +- name: Clean old duplicity backups for {{ item.name }} + 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 }}" + diff --git a/tasks/prepare_MySQL_DB_backup_volume.yml b/tasks/prepare_MySQL_DB_backup_volume.yml new file mode 100755 index 0000000..c6e326e --- /dev/null +++ b/tasks/prepare_MySQL_DB_backup_volume.yml @@ -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/" diff --git a/vars/main.yml b/vars/main.yml index fe1505a..a2d6e8f 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -27,21 +27,36 @@ BOOTSTRAP_REQUIRED_ENV_VARS: - BACKUP_WORKFLOW BACKUP_OVH1_VOLUMES: - - elasticsearch_data - - gogs_data - - mail_data - - nextcloud - - reverse-proxy_conf - - reverse-proxy_conf_enabled - - reverse-proxy_letsencrypt - - scuttle_code - - scuttle_php5-fpm_conf - - etc_grafana - - var_lib_grafana - - var_log_grafana - - registry_data - - registry_auth - - registry_certs + - name: elasticsearch_data + dir: /mnt/volumes/elasticsearch_data/data + - name: gogs_data + dir: /mnt/volumes/gogs_data/data + - name: mail_data + dir: /mnt/volumes/mail_data/data + - name: nextcloud + dir: /mnt/volumes/nextcloud/data + - name: reverse-proxy_conf + dir: /mnt/volumes/reverse-proxy_conf/data + - name: reverse-proxy_conf_enabled + dir: /mnt/volumes/reverse-proxy_conf_enabled/data + - name: reverse-proxy_letsencrypt + dir: /mnt/volumes/reverse-proxy_letsencrypt/data + - 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: - OS_AUTH_URL