Эх сурвалжийг харах

stop container services while backing them up

Blaine Story 1 жил өмнө
parent
commit
4e4f42fc82

+ 6 - 0
roles/cloud-backups/templates/backup-to-b2.sh.j2

@@ -9,6 +9,9 @@ LOG_FILE="/var/log/rclone/rclone-$(date +%Y-%m-%d).log"
 {% if container.volumes is defined %}
 {% for volume in container.volumes %}
 {% if volume|regex_replace(':.*') not in backups_ignore %}
+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 }} \
@@ -26,6 +29,9 @@ if [[ $? > 0 ]]; then
     https://ntfy.warchildstory.com/{{ ntfy_server_notifications }}
 fi
 echo "Finished backup of '{{ container.name }}:{{ volume | regex_replace(':.*') }}'." | ts >> "$LOG_FILE"
+echo "Starting '{{ container.name }}' service..." | ts >> "$LOG_FILE"
+systemctl start {{ container.name }}
+echo "Service '{{ container.name }}' started." | ts >> "$LOG_FILE"
 
 {% endif %}
 {% endfor %}