45 lines
2.0 KiB
YAML
Executable File
45 lines
2.0 KiB
YAML
Executable File
---
|
|
- 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
|
|
|
|
- name: Archive DB dumps
|
|
ansible.builtin.command: "tar -czf {{ WORKDIR }}/backup/mysql-server_dumps.tar.gz -C /mnt/volumes {{ MySQL_dump.stdout_lines | last }} {{ DBs_dump.stdout_lines | last }}"
|
|
with_items: "{{ BACKUP_OVH1_VOLUMES }}"
|
|
|
|
# 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 }}"
|