Rename bootstrap workflow. Improve backup_ovh1.yml.

This commit is contained in:
yohan 2023-10-22 11:29:34 +02:00
parent 2cf10f848d
commit 105b622f56
3 changed files with 76 additions and 3 deletions

51
backup_ovh1.yml Executable file
View File

@ -0,0 +1,51 @@
---
- name: backup_ovh1
hosts: localhost
gather_facts: false
vars_files: main.yml
tasks:
- name: Assert environment variable is not empty
ansible.builtin.include_tasks: "tasks/assert_env_var_not_empty.yml"
with_items: "{{ BACKUP_OVH1_REQUIRED_ENV_VARS }}"
- name: Create backup directory
ansible.builtin.file:
path: "{{ WORKDIR }}/backup"
state: directory
- name: Archive volumes
ansible.builtin.command: "tar -czf {{ WORKDIR }}/backup/{{ item }}.tar.gz -C /mnt/volumes {{ item }}"
with_items: "{{ BACKUP_OVH1_VOLUMES }}"
- name: Find lastest MySQL DB dump
ansible.builtin.shell: "ls -tr /mnt/volumes/mysql-server_dumps/data/mysql_dump-mysql_*"
register: MySQL_dump
- name: Find lastest applications DB dump
ansible.builtin.shell: "ls -tr /mnt/volumes/mysql-server_dumps/data/mysql_dump_*"
register: DBs_dump
- debug: var=MySQL_dump
- debug: var=DBs_dump
- ansible.builtin.meta: end_play
- name: Archive DB dumps
ansible.builtin.command: "tar -czf {{ WORKDIR }}/backup/mysql-server_dumps.tar.gz -C /mnt/volumes ${name_mysql_dump} ${name_dbs_dump}"
with_items: "{{ BACKUP_OVH1_VOLUMES }}"
#name_mysql_dump=$(ls -tr ${name}/data/mysql_dump-mysql_*|tail -n1)
#name_dbs_dump=$(ls -tr ${name}/data/mysql_dump_*|tail -n1)
# python3-swiftclient is a requirement of duplicity
- name: Install python3-swiftclient
ansible.builtin.package:
name: python3-swiftclient
state: present
- name: Backup with duplicity
ansible.builtin.command: "duplicity --num-retries 3 --full-if-older-than 1M --progress --archive-dir {{ ARCHIVE_DIR }} --name {{ lookup('env','BACKUP_WORKFLOW') }} --allow-source-mismatch '{{ WORKDIR }}/backup' 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 {{ lookup('env','BACKUP_WORKFLOW') }} --allow-source-mismatch --force swift://{{ lookup('env','BACKUP_WORKFLOW') }}"
environment: "{{ DUPLICITY_ENVIRONMENT }}"

View File

@ -1,5 +1,5 @@
--- ---
- name: gen_bootstrap - name: backup bootstrap
hosts: localhost hosts: localhost
gather_facts: false gather_facts: false
vars_files: main.yml vars_files: main.yml
@ -121,9 +121,9 @@
state: present state: present
- name: Backup with duplicity - name: Backup with duplicity
ansible.builtin.command: "duplicity --num-retries 3 --full-if-older-than 1M --progress --archive-dir {{ ARCHIVE_DIR }} --name bootstrap --allow-source-mismatch '{{ WORKDIR }}/backup' swift://bootstrap" ansible.builtin.command: "duplicity --num-retries 3 --full-if-older-than 1M --progress --archive-dir {{ ARCHIVE_DIR }} --name {{ lookup('env','BACKUP_WORKFLOW') }} --allow-source-mismatch '{{ WORKDIR }}/backup' swift://{{ lookup('env','BACKUP_WORKFLOW') }}"
environment: "{{ DUPLICITY_ENVIRONMENT }}" environment: "{{ DUPLICITY_ENVIRONMENT }}"
- name: Clean old duplicity backups - name: Clean old duplicity backups
ansible.builtin.command: "duplicity remove-older-than 2M --archive-dir {{ ARCHIVE_DIR }} --name bootstrap --allow-source-mismatch --force swift://bootstrap" ansible.builtin.command: "duplicity remove-older-than 2M --archive-dir {{ ARCHIVE_DIR }} --name {{ lookup('env','BACKUP_WORKFLOW') }} --allow-source-mismatch --force swift://{{ lookup('env','BACKUP_WORKFLOW') }}"
environment: "{{ DUPLICITY_ENVIRONMENT }}" environment: "{{ DUPLICITY_ENVIRONMENT }}"

View File

@ -25,6 +25,28 @@ BOOTSTRAP_REQUIRED_ENV_VARS:
- DUPLICITY_PASSPHRASE - DUPLICITY_PASSPHRASE
- KEY - KEY
- DOC_KEY - DOC_KEY
- 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
BACKUP_OVH1_REQUIRED_ENV_VARS:
- OS_AUTH_URL
- OS_IDENTITY_API_VERSION
- OS_TENANT_NAME
- OS_USERNAME
- OS_PASSWORD
- OS_REGION_NAME
- DUPLICITY_PASSPHRASE
- BACKUP_WORKFLOW
PLAYBOOK_REQUIRED_ENV_VARS: PLAYBOOK_REQUIRED_ENV_VARS:
- KEY - KEY