Selaa lähdekoodia

Added option to restore, but it won't happen automatically

Till Klocke 7 vuotta sitten
vanhempi
commit
44ac5e2142
2 muutettua tiedostoa jossa 9 lisäystä ja 1 poistoa
  1. 1 0
      roles/common-restic/defaults/main.yml
  2. 8 1
      roles/common-restic/tasks/main.yml

+ 1 - 0
roles/common-restic/defaults/main.yml

@@ -1,2 +1,3 @@
 restic_backup_now: false
+restic_restore: false
 restic_repo_environment:

+ 8 - 1
roles/common-restic/tasks/main.yml

@@ -45,8 +45,15 @@
     - name: "AWS_SECRET_ACCESS_KEY"
       value: "{{ restic_repo_environment.AWS_SECRET_ACCESS_KEY }}"
 
+# The target directory shall not already exist on the host
+- name: Restore previous backup of stateful data
+  when: not restic_backup_now and restic_restore
+  shell: /usr/local/bin/restic -p /root/.restic.password -r {{ restic_repo }} restore --path {{ item }} -t {{ item }} latest
+  environment: "{{ restic_repo_environment }}"
+  with_items: "{{ restic_stateful_dirs }}"
+
 - name: Create initial backup of statefule dirs
-  when: restic_backup_now
+  when: restic_backup_now and not restic_restore
   shell: /usr/local/bin/restic -p /root/.restic.password -r {{ restic_repo }} backup {{ item.dir }}
   environment: "{{ restic_repo_environment }}"
   with_items: "{{ restic_stateful_dirs }}"