From 392ddec2d7aaffbbaab91bf9296ca82fc620806a Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Thu, 7 Jul 2022 17:03:34 +0200 Subject: [PATCH] backup-and-restore: use archive/unarchive approach current approach is too complex and causes too many issues permission issues. Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2051640 Signed-off-by: Guillaume Abrioux (cherry picked from commit dffe7b47de70b6eeec71a3fa86f8c407adb4dd8e) --- .../backup-and-restore-ceph-files.yml | 89 +++++++------------ 1 file changed, 34 insertions(+), 55 deletions(-) diff --git a/infrastructure-playbooks/backup-and-restore-ceph-files.yml b/infrastructure-playbooks/backup-and-restore-ceph-files.yml index 30da772d99..aec8f47f8c 100644 --- a/infrastructure-playbooks/backup-and-restore-ceph-files.yml +++ b/infrastructure-playbooks/backup-and-restore-ceph-files.yml @@ -54,74 +54,53 @@ - name: backup mode when: mode == 'backup' block: - - name: find files - find: - paths: - - /etc/ceph - - /var/lib/ceph - recurse: yes - register: file_to_backup + - name: create a temp directory + ansible.builtin.tempfile: + state: directory + suffix: ansible-archive-ceph + register: tmp_dir + delegate_to: "{{ target_node }}" + + - name: archive files + archive: + path: "{{ item }}" + dest: "{{ tmp_dir.path }}/backup{{ item | replace('/', '-') }}.tar" + format: tar delegate_to: "{{ target_node }}" + loop: + - /etc/ceph + - /var/lib/ceph + + - name: create backup directory + become: false + file: + path: "{{ backup_dir }}/{{ hostvars[target_node]['ansible_facts']['hostname'] }}" + state: directory - name: backup files fetch: - src: "{{ item.path }}" - dest: "{{ backup_dir }}/{{ hostvars[target_node]['ansible_facts']['hostname'] }}/{{ item.path }}" + src: "{{ tmp_dir.path }}/backup{{ item | replace('/', '-') }}.tar" + dest: "{{ backup_dir }}/{{ hostvars[target_node]['ansible_facts']['hostname'] }}/backup{{ item | replace('/', '-') }}.tar" flat: yes - loop: "{{ file_to_backup.files }}" + loop: + - /etc/ceph + - /var/lib/ceph delegate_to: "{{ target_node }}" - - name: preserve mode on files + - name: remove temp directory file: - path: "{{ backup_dir }}/{{ hostvars[target_node]['ansible_facts']['hostname'] }}/{{ item.path }}" - mode: "{{ item.mode }}" - owner: "{{ item.uid }}" - group: "{{ item.gid }}" - loop: "{{ file_to_backup.files }}" + path: "{{ tmp_dir.path }}" + state: absent + delegate_to: "{{ target_node }}" - name: restore mode when: mode == 'restore' block: - - name: stat directories - stat: - path: "{{ backup_dir }}/{{ hostvars[target_node]['ansible_facts']['hostname'] }}{{ item }}" - register: dir_stat + - name: unarchive files + ansible.builtin.unarchive: + src: "{{ backup_dir }}/{{ hostvars[target_node]['ansible_facts']['hostname'] }}/backup{{ item | replace('/', '-') }}.tar" + dest: "{{ item | dirname }}" loop: - /etc/ceph - /var/lib/ceph - - - name: get a list of files to be restored - find: - paths: - - "{{ backup_dir }}/{{ hostvars[target_node]['ansible_facts']['hostname'] }}" - recurse: yes - register: file_to_restore - - - name: create a list of directories to create - set_fact: - dir_to_create: "{{ dir_to_create | default([]) | union([{'path': item.item | replace(backup_dir + '/' + hostvars[target_node]['ansible_facts']['hostname'], ''), 'uid': item.stat.uid, 'gid': item.stat.gid, 'mode': item.stat.mode}]) }}" - loop: "{{ dir_stat.results }}" - delegate_to: "{{ target_node }}" - - - name: create a liste of sub-directories to create - set_fact: - subdir_to_create: "{{ subdir_to_create | default([]) | union([{'path': item.path | dirname | replace(backup_dir + '/' + hostvars[target_node]['ansible_facts']['hostname'], ''), 'uid': item.uid, 'gid': item.gid, 'mode': item.mode}]) }}" - loop: "{{ file_to_restore.files }}" - - - name: ensure directories are created - file: - state: directory - path: "{{ item.path }}" - mode: "{{ item.mode }}" - owner: "{{ item.uid }}" - group: "{{ item.gid }}" - loop: "{{ dir_to_create + subdir_to_create }}" delegate_to: "{{ target_node }}" - - - name: restore files - copy: - src: "{{ item.path }}" - dest: "{{ item.path | replace(backup_dir + '/' + hostvars[target_node]['ansible_facts']['hostname'], '') }}" - mode: preserve - loop: "{{ file_to_restore.files }}" - delegate_to: "{{ target_node }}" \ No newline at end of file