From 4f0d7981536a1f4ede7498a460bce3ac07dd5dc7 Mon Sep 17 00:00:00 2001 From: Julien Gomes Dias Date: Wed, 30 Mar 2022 10:42:38 +0200 Subject: [PATCH 1/3] add restore wip for Nextcloud --- roles/nextcloud_instance/tasks/restore.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/roles/nextcloud_instance/tasks/restore.yml b/roles/nextcloud_instance/tasks/restore.yml index e69de29b..5a1a5632 100644 --- a/roles/nextcloud_instance/tasks/restore.yml +++ b/roles/nextcloud_instance/tasks/restore.yml @@ -0,0 +1,19 @@ +--- +- name: Restore a snapshot from restic if a snapshot id is provided (only application) + block: + - name: Restore the snapshot in /tmp + command: "/usr/bin/restic restore {{ snapshot_id }} --target /tmp" + environment: + RESTIC_REPOSITORY: "sftp:{{ st_h_box_host }}:srv/{{ ansible_hostname }}-restic" + RESTIC_PASSWORD: "{{ restic_password }}" + - name: Restore application + block: + - name: Restore the folder from the tmp folder + shell: "/bin/mv /tmp/{{ app_instance_root }} {{ app_instance_root }}" + when: app_snapshot is defined + - name: Restore data + block: + - name: Restore data folder + shell: "/bin/mv /tmp/{{ app_data }} {{ app_data }}" + when: data_snapshot is defined + when: restic_restore == "yes" \ No newline at end of file -- GitLab From 822fb15a2a3ba7c0f8b4dd18185bf35cd8e0e6bc Mon Sep 17 00:00:00 2001 From: Julien Gomes Dias Date: Wed, 30 Mar 2022 11:05:27 +0200 Subject: [PATCH 2/3] add restore wip for Nextcloud --- roles/nextcloud_instance/tasks/restore.yml | 33 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/roles/nextcloud_instance/tasks/restore.yml b/roles/nextcloud_instance/tasks/restore.yml index 5a1a5632..f47206ca 100644 --- a/roles/nextcloud_instance/tasks/restore.yml +++ b/roles/nextcloud_instance/tasks/restore.yml @@ -1,18 +1,41 @@ --- - name: Restore a snapshot from restic if a snapshot id is provided (only application) block: - - name: Restore the snapshot in /tmp - command: "/usr/bin/restic restore {{ snapshot_id }} --target /tmp" - environment: - RESTIC_REPOSITORY: "sftp:{{ st_h_box_host }}:srv/{{ ansible_hostname }}-restic" - RESTIC_PASSWORD: "{{ restic_password }}" + - name: "check {{ app_instance_root }} exists" + stat: + path: "{{ app_instance_root }}" + register: instance_root_dir + - name: "check {{ app_instance_root }} exists" + stat: + path: "{{ app_data }}" + register: instance_data_dir + - name: create app_folder if app_folder was deleted + file: + path: "{{ app_instance_root }}" + state: directory + when: not(instance_root_dir.stat.exists) + - name: create data_folder if data_folder was deleted + file: + path: "{{ app_data }}" + state: directory + when: not(instance_data_dir.stat.exists) - name: Restore application block: + - name: Restore the snapshot in /tmp + command: "/usr/bin/restic restore {{ app_snapshot }} --target /tmp" + environment: + RESTIC_REPOSITORY: "sftp:{{ st_h_box_host }}:srv/{{ ansible_hostname }}-restic" + RESTIC_PASSWORD: "{{ restic_password }}" - name: Restore the folder from the tmp folder shell: "/bin/mv /tmp/{{ app_instance_root }} {{ app_instance_root }}" when: app_snapshot is defined - name: Restore data block: + - name: Restore the snapshot in /tmp + command: "/usr/bin/restic restore {{ data_snapshot }} --target /tmp" + environment: + RESTIC_REPOSITORY: "sftp:{{ st_h_box_host }}:srv/{{ ansible_hostname }}-restic" + RESTIC_PASSWORD: "{{ restic_password }}" - name: Restore data folder shell: "/bin/mv /tmp/{{ app_data }} {{ app_data }}" when: data_snapshot is defined -- GitLab From ecb5cf6f0f7f75fa67a2f43f82f599307567e51f Mon Sep 17 00:00:00 2001 From: Julien Gomes Dias Date: Mon, 29 Aug 2022 22:01:46 +0100 Subject: [PATCH 3/3] App_restore --- roles/_app_restore_instance/tasks/main.yml | 96 ++++++++++++++++------ roles/nextcloud_instance/tasks/restore.yml | 6 +- 2 files changed, 76 insertions(+), 26 deletions(-) diff --git a/roles/_app_restore_instance/tasks/main.yml b/roles/_app_restore_instance/tasks/main.yml index 20df8de6..d0ec92ee 100644 --- a/roles/_app_restore_instance/tasks/main.yml +++ b/roles/_app_restore_instance/tasks/main.yml @@ -1,33 +1,81 @@ --- - ## LIST ARCHIVES AND DIRECTORIES CONTAINING INSTANCE BACKUP - - block: + ## LIST SNAPSHOTS + + - name: List backup + block: + - name: List backup + shell: "restic -r \"{{ item.repository }}\" snapshots" + with_items: "{{ restic.backups }}" + register: "list_backups" + environment: + RESTIC_PASSWORD: "{{ restic_password }}" + - name: Print return information from the previous task + debug: + msg: + - "{{ item.stdout_lines }}" + with_items: "{{ list_backups.results }}" + when: restore_action == 'list' + tags: + - list_backups - - name : "listing old versions on host for {{ app_instance_id }}" - shell: "ls {{ backup_version_dir }}/{{ app_instance_id }}" - failed_when: False - register: version_dir_out - - name : "listing archives on host for {{ backup_base_dir }}" - shell: "ls {{ backup_base_dir }}/*.tar.gz" - register: dir_out - - name: "searching for {{ app_instance_id }} in archives" - shell: "tar --list --file {{ archive_name }} | grep {{ backup_prod_dir[1:] }}/{{ app_instance_id }}/ -m 1 | wc -l" - args: - warn: False - loop: "{{ dir_out.stdout_lines }}" - loop_control: - loop_var: archive_name - register: archive_instance - - - name: "see if {{ backup_master_slaves_location }}/{{ app_host }} exists (master backup)" + - name: Restore a snapshot from restic if a snapshot id is provided (only application) + block: + - name: "check {{ app_instance_root }} exists" + stat: + path: "{{ app_instance_root }}" + register: instance_root_dir + - name: "check {{ app_instance_root }} exists" stat: - path: "{{ backup_master_slaves_location }}/{{ app_host }}" - register: slaves_backup - when: app_host is defined + path: "{{ app_data }}" + register: instance_data_dir + - name: create app_folder if app_folder was deleted + file: + path: "{{ app_instance_root }}" + state: directory + when: not(instance_root_dir.stat.exists) + - name: create data_folder if data_folder was deleted + file: + path: "{{ app_data }}" + state: directory + when: not(instance_data_dir.stat.exists) + - name: Restore application + block: + - name: Restore the snapshot in /tmp + command: "/usr/bin/restic restore {{ app_snapshot }} --target /tmp" + environment: + RESTIC_REPOSITORY: "sftp:{{ st_h_box_host }}:srv/{{ ansible_hostname }}-restic" + RESTIC_PASSWORD: "{{ restic_password }}" + - name: Restore the folder from the tmp folder + command: "/bin/mv /tmp/{{ app_instance_root }} {{ app_instance_root }}" + when: app_snapshot is defined + - name: Restore data + block: + - name: Restore the snapshot in /tmp + command: "/usr/bin/restic restore {{ data_snapshot }} --target /tmp" + environment: + RESTIC_REPOSITORY: "sftp:{{ st_h_box_host }}:srv/{{ ansible_hostname }}-restic-{{ app_instance_id }}-data" + RESTIC_PASSWORD: "{{ restic_password }}" + - name: Restore data folder + command: "/bin/mv /tmp/{{ app_data }} {{ app_data }}" + when: data_snapshot is defined + when: restic_restore == "yes" + + ## Restauration de la base de données + + - name: restauration de la base de données + block: + - name: recuperation du snapshot + - name: restauration de la base de données + when: db_snapshot is defined + + ## Restauration du dossier applicatif + + ## Restauration du dossier data + - when: restore_action == 'list' - block: @@ -69,6 +117,8 @@ when: restore_action == 'list' + ## RÉCUPÉRATION DU SNAPSHOT + ## EXTRACT OR COPY FOR RESTORE, TRANSFER OR RECOVER - block: diff --git a/roles/nextcloud_instance/tasks/restore.yml b/roles/nextcloud_instance/tasks/restore.yml index f47206ca..bbd5d0c1 100644 --- a/roles/nextcloud_instance/tasks/restore.yml +++ b/roles/nextcloud_instance/tasks/restore.yml @@ -27,16 +27,16 @@ RESTIC_REPOSITORY: "sftp:{{ st_h_box_host }}:srv/{{ ansible_hostname }}-restic" RESTIC_PASSWORD: "{{ restic_password }}" - name: Restore the folder from the tmp folder - shell: "/bin/mv /tmp/{{ app_instance_root }} {{ app_instance_root }}" + command: "/bin/mv /tmp/{{ app_instance_root }} {{ app_instance_root }}" when: app_snapshot is defined - name: Restore data block: - name: Restore the snapshot in /tmp command: "/usr/bin/restic restore {{ data_snapshot }} --target /tmp" environment: - RESTIC_REPOSITORY: "sftp:{{ st_h_box_host }}:srv/{{ ansible_hostname }}-restic" + RESTIC_REPOSITORY: "sftp:{{ st_h_box_host }}:srv/{{ ansible_hostname }}-restic-{{ app_instance_id }}-data" RESTIC_PASSWORD: "{{ restic_password }}" - name: Restore data folder - shell: "/bin/mv /tmp/{{ app_data }} {{ app_data }}" + command: "/bin/mv /tmp/{{ app_data }} {{ app_data }}" when: data_snapshot is defined when: restic_restore == "yes" \ No newline at end of file -- GitLab