Browse Source

tar container data before backing up

Blaine Story 1 year ago
parent
commit
46fe39478e

+ 8 - 0
roles/cloud-backups/tasks/main.yml

@@ -29,6 +29,14 @@
     group: root
     mode: '0750'
 
+- name: Create /opt/backups directory
+  file:
+    path: /opt/backups
+    state: directory
+    owner: root
+    group: root
+    mode: '0750'
+
 - name: Copy Backup and Restore scripts
   template:
     src: "{{ item }}.j2"

+ 10 - 7
roles/cloud-backups/templates/backup-to-b2.sh.j2

@@ -13,13 +13,9 @@ echo "Stopping '{{ container.name }}' service..." | ts >> "$LOG_FILE"
 systemctl stop {{ container.name }}
 echo "Service '{{ container.name }}' stopped." | ts >> "$LOG_FILE"
 echo "Starting backup of '{{ container.name }}:{{ volume | regex_replace(':.*') }}'." | ts >> "$LOG_FILE"
-/usr/bin/rclone copy {{ volume | regex_replace(':.*') }}/ b2-container-data:current/{{ ansible_hostname }}/{{ container.name }}/{{ volume | regex_replace(':.*') | basename }} \
-      --backup-dir=b2-container-data:old/{{ ansible_hostname }}/{{ container.name }}/{{ volume | regex_replace(':.*') | basename }} \
-      --suffix=-$(date +%Y-%m-%d) \
-      --fast-list \
-      --suffix-keep-extension \
-      --exclude "*log" \
-      --log-file="$LOG_FILE" -v
+
+tar -czf /opt/backups/$(date +%Y-%m-%d)_{{ ansible_hostname }}_{{ container.name}}_{{ volume | regex_replace(':.*') | basename }}.tar.gz {{ volume | regex_replace(':.*') }}/
+
 if [[ $? > 0 ]]; then
   curl \
     -H "Title: rclone backup error" \
@@ -37,6 +33,13 @@ echo "Service '{{ container.name }}' started." | ts >> "$LOG_FILE"
 {% endfor %}
 {% endif %}
 {% endfor %}
+
+echo "Backing up tarballs to B2..." | ts >> "$LOG_FILE"
+/usr/bin/rclone copy /opt/backups/ b2-container-data:current/{{ ansible_hostname }} \
+    --fast-list \
+    --log-file="$LOG_FILE" -v
+echo "Finished backing up tarballs to B2." | ts >> "$LOG_FILE"
+
 {% endif %} 
 {% endif %}