Browse Source

add restore-from-b2.sh to cloud backups role

Blaine Story 2 years ago
parent
commit
cdbba2f4e3

+ 6 - 3
roles/cloud-backups/tasks/main.yml

@@ -29,13 +29,16 @@
     group: root
     group: root
     mode: '0750'
     mode: '0750'
 
 
-- name: Copy Backup scripts
+- name: Copy Backup and Restore scripts
   template:
   template:
-    src: backup-to-b2.sh.j2
-    dest: /usr/local/bin/backup-to-b2.sh
+    src: "{{ item }}.j2"
+    dest: /usr/local/bin/{{ item }}
     owner: root
     owner: root
     group: root
     group: root
     mode: '0755'
     mode: '0755'
+  loop:
+    - backup-to-b2.sh
+    - restore-from-b2.sh
 
 
 - name: Create cronjob to backup data to b2
 - name: Create cronjob to backup data to b2
   cron:
   cron:

+ 25 - 0
roles/cloud-backups/templates/restore-from-b2.sh.j2

@@ -0,0 +1,25 @@
+#!/bin/bash
+# {{ ansible_managed }}
+
+{% if backups is defined and 'containers' in backups %}
+{% if containers is defined %}
+{% for container in containers %}
+{% if container.volumes is defined %}
+{% for volume in container.volumes %}
+{% if backups_ignore not in volume|regex_replace(':.*') %}
+
+BACKUP_DIR='/opt/restores{{ volume | regex_replace(':.*') }}'
+
+echo "Starting restore of '{{ container.name }}:{{ volume | regex_replace(':.*') }} to $BACKUP_DIR'..."
+/usr/bin/rclone copy b2-container-data:current/{{ ansible_hostname }}/{{ container.name }}/{{ volume | regex_replace(':.*') | basename }} "$BACKUP_DIR" \
+	--fast-list \
+	--progress
+echo
+echo
+
+{% endif %}
+{% endfor %}
+{% endif %}
+{% endfor %}
+{% endif %}
+{% endif %}