You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hetzner-ansible/roles/maria/tasks/_create_backup.yml

83 lines
2.4 KiB
YAML

---
- name: "Create destination backup directory"
become: yes
ansible.builtin.file:
path: '{{ backup_dest_dir }}'
state: directory
mode: '0755'
owner: root
group: root
- name: "Create {{ my_cnf_file }} file"
become: yes
copy:
dest: '{{ my_cnf_file }}'
mode: '0600'
content: |
[client]
user={{ mysql_root_username }}
password={{ mysql_root_password }}
- name: "Block: gpg stuff"
block:
- name: Create temp dir
ansible.builtin.tempfile:
state: directory
suffix: gitcheckout
path: /tmp
register: tempdir
- name: "Checkout repo for gpg communication-keys"
ansible.builtin.git:
repo: "{{ backup_communication_keys_repository }}"
dest: "{{ tempdir.path }}"
version: master
# there is no ansible gpg module already in place
# linting violation needs to be whitelisted
- name: "Importing stage specific automation gpg-key" # noqa command-instead-of-shell
shell: 'gpg --import {{ tempdir.path }}/{{ backup_communication_keys_stage_gpg_key }}'
become: yes
# there is no ansible module already in place for (mariabackup|gpg)
# so using shell module
- name: "Creating mariabackup ... + doing async check if successful or not"
become: yes
vars:
backup_file: '{{ backup_dest_dir }}/mariabackupstream_{{ current_date_time }}.gz'
shell: |
set -o pipefail
/usr/bin/mariabackup --defaults-file={{ my_cnf_file }} --backup --stream=xbstream | gzip > {{ backup_file }} && \
gpg --encrypt --recipient "smardigo automation DEV" --trust-model always {{ backup_file }} && \
rm {{ backup_file }}
args:
executable: /bin/bash
async: 3600 # allows duration for task up to 3600sec
poll: 30 # rechecks every 30sec if task has finished yet
changed_when: false
# just to make it easier to detect potential failures.
# maybe: can be removed later
- name: "Create STATUS file for successful backup"
become: yes
file:
path: '{{ backup_status_file }}_{{ current_date_time }}'
state: touch
mode: '0644'
owner: root
group: root
- name: "Prepare backup dir..."
become: yes
ansible.builtin.file:
path: '{{ backup_dest_dir }}'
owner: '{{ backupuser_user_name }}'
group: '{{ backupuser_user_name }}'
recurse: yes
- name: "Remove {{ my_cnf_file }} file"
become: yes
file:
path: '{{ my_cnf_file }}'
state: absent