]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
backup-and-restore: various fixes v6.0.27.6
authorGuillaume Abrioux <gabrioux@redhat.com>
Tue, 5 Jul 2022 07:58:02 +0000 (09:58 +0200)
committerGuillaume Abrioux <gabrioux@redhat.com>
Tue, 5 Jul 2022 12:47:11 +0000 (14:47 +0200)
- preserve mode and ownership on main directories
- make sure the directories are well present prior to restoring files.

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2051640
Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
(cherry picked from commit 047af3a3f66b6135cf7ab6a7c28b9c30dea3c836)
(cherry picked from commit f5020f61309d92be3527c78c110cbb0b1591d24e)

infrastructure-playbooks/backup-and-restore-ceph-files.yml

index 2913310ceafff30c26d8df7059c9e1151305c342..30da772d992a24e2fa260e360f95b6443bb68f3d 100644 (file)
@@ -71,7 +71,7 @@
           loop: "{{ file_to_backup.files }}"
           delegate_to: "{{ target_node }}"
 
-        - name: preserve mode
+        - name: preserve mode on files
           file:
             path: "{{ backup_dir }}/{{ hostvars[target_node]['ansible_facts']['hostname'] }}/{{ item.path }}"
             mode: "{{ item.mode }}"
     - name: restore mode
       when: mode == 'restore'
       block:
+        - name: stat directories
+          stat:
+            path: "{{ backup_dir }}/{{ hostvars[target_node]['ansible_facts']['hostname'] }}{{ item }}"
+          register: dir_stat
+          loop:
+            - /etc/ceph
+            - /var/lib/ceph
+
         - name: get a list of files to be restored
           find:
             paths:
             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 }}"