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
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"

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
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 }}"

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_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