From a7176ae4212d2f7f6e21cfd96ec19fd4b0c00c22 Mon Sep 17 00:00:00 2001 From: Juan Larriba Date: Mon, 3 May 2021 14:50:15 +0200 Subject: [PATCH] After SFTP backup, the backup file and the iso must be deleted from the machine Currently, the SFTP backup leaves huge archives on the machine that the backup has been taken. This change adds a cleanup task to the backup&restore role. Also, to perform an SFTP backup, it is needed that the SSH fingerprint of the storage node is downloaded on the node. Although this could be done by hand, this change automates also this action. bz#1955495 Change-Id: I7b8df9cf8a56606f3db54f00af547378e4f4e472 (cherry picked from commit afe69e3dbf1aa27873e9c6c8c67dee02f6ec4564) --- .../backup_and_restore/tasks/run_backup.yml | 31 +++++++++++++++++ .../backup_and_restore/tasks/setup_rear.yml | 33 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/tripleo_ansible/roles/backup_and_restore/tasks/run_backup.yml b/tripleo_ansible/roles/backup_and_restore/tasks/run_backup.yml index ab8a51a1c..26f574f48 100644 --- a/tripleo_ansible/roles/backup_and_restore/tasks/run_backup.yml +++ b/tripleo_ansible/roles/backup_and_restore/tasks/run_backup.yml @@ -45,3 +45,34 @@ var: tripleo_backup_and_restore_rear_output tags: - bar_create_recover_image + +- name: Add the node to the pacemaker cluster + command: pcs node unstandby + when: + - pacemaker_enabled + - tripleo_backup_and_restore_enable_snapshots|bool + tags: + - bar_create_recover_image + +- name: Wait until pacemaker has Galera up&running + shell: netstat -tunlp | grep ":3306 " | sed -e 's/.*\///' + register: mysql_result + retries: 10 + until: mysql_result is search('mysqld') + delay: 5 + when: + - pacemaker_enabled + - tripleo_backup_and_restore_enable_snapshots|bool + tags: + - bar_create_recover_image + +- name: Clean old backups + shell: | + set -o pipefail + rm -rf /tmp/rear.* || true + rm -rf /var/lib/rear/output/* + failed_when: false + args: + warn: false + tags: + - bar_create_recover_image diff --git a/tripleo_ansible/roles/backup_and_restore/tasks/setup_rear.yml b/tripleo_ansible/roles/backup_and_restore/tasks/setup_rear.yml index 0b7b7a5d4..69d868f94 100644 --- a/tripleo_ansible/roles/backup_and_restore/tasks/setup_rear.yml +++ b/tripleo_ansible/roles/backup_and_restore/tasks/setup_rear.yml @@ -109,3 +109,36 @@ backup: true tags: - bar_setup_rear + +- name: Load rear config + become: true + slurp: + src: /etc/rear/local.conf + register: rear_config + tags: + - bar_setup_rear + +- name: Extract OUTPUT_URL from rear config + set_fact: + output_url: "{{ rear_config.content | b64decode | regex_findall('OUTPUT_URL=(.+)') | first }}" + tags: + - bar_setup_rear + +- name: Check if this is a SFTP backup + set_fact: + sftp_backup: "{{ output_url is search ('sftp://') }}" + tags: + - bar_setup_rear + +- name: Extract the SFTP hostname + set_fact: + sftp_host: "{{ output_url | regex_search('(?<=@)(.*?)(?=/)') }}" + when: sftp_backup + tags: + - bar_setup_rear + +- name: Retrieve host ssh fingerprint + shell: "ssh-keyscan -H {{ sftp_host }} >> ~/.ssh/known_hosts" + when: sftp_backup + tags: + - bar_setup_rear