diff --git a/backup_ovh1.yml b/backup_ovh1.yml new file mode 100755 index 0000000..93174b3 --- /dev/null +++ b/backup_ovh1.yml @@ -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 }}" diff --git a/gen_bootstrap.yml b/bootstrap.yml similarity index 93% rename from gen_bootstrap.yml rename to bootstrap.yml index cfe25a9..98d0e0e 100755 --- a/gen_bootstrap.yml +++ b/bootstrap.yml @@ -1,5 +1,5 @@ --- -- name: gen_bootstrap +- name: backup bootstrap hosts: localhost gather_facts: false vars_files: main.yml @@ -121,9 +121,9 @@ state: present - 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 }}" - 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 }}" diff --git a/vars/main.yml b/vars/main.yml index 6c9e320..1974f17 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -25,6 +25,28 @@ BOOTSTRAP_REQUIRED_ENV_VARS: - DUPLICITY_PASSPHRASE - 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: - KEY