From f58a36ea34902893dc56f5e526f945b83626a15d Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 27 Dec 2023 22:12:19 +0100 Subject: [PATCH] implemented backup of everything before docker update --- group_vars/all | 1 + roles/backup-docker-to-local/handlers/main.yml | 5 +++++ roles/backup-docker-to-local/tasks/main.yml | 7 +++++++ .../templates/backup-docker-to-local.service.j2 | 2 +- .../backup-every-docker-volume-to-local.service.j2 | 8 ++++++++ roles/update-docker/tasks/main.yml | 4 ++-- 6 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 roles/backup-docker-to-local/templates/backup-every-docker-volume-to-local.service.j2 diff --git a/group_vars/all b/group_vars/all index c22cf989..3ce11f52 100644 --- a/group_vars/all +++ b/group_vars/all @@ -70,6 +70,7 @@ system_maintenance_backup_services: - "backup-docker-to-local" - "backup-remote-to-local" - "backup-data-to-usb" + - "backup-docker-to-local-everything" ### Defined Services for System Cleanup system_maintenance_cleanup_services: diff --git a/roles/backup-docker-to-local/handlers/main.yml b/roles/backup-docker-to-local/handlers/main.yml index 845922f0..687aacda 100644 --- a/roles/backup-docker-to-local/handlers/main.yml +++ b/roles/backup-docker-to-local/handlers/main.yml @@ -3,6 +3,11 @@ name: backup-docker-to-local.service daemon_reload: yes +- name: "reload backup-docker-to-local-everything.service" + systemd: + name: backup-docker-to-local-everything.service + daemon_reload: yes + - name: "restart backup-docker-to-local.timer" systemd: name: backup-docker-to-local.timer diff --git a/roles/backup-docker-to-local/tasks/main.yml b/roles/backup-docker-to-local/tasks/main.yml index e67b8ca0..60929150 100644 --- a/roles/backup-docker-to-local/tasks/main.yml +++ b/roles/backup-docker-to-local/tasks/main.yml @@ -20,6 +20,13 @@ msg: "Warning: Repository is not reachable." when: git_result is defined and git_result.failed is defined and run_once_cleanup_failed_docker_backups is not defined +- name: configure backup-docker-to-local-everything.service + template: + src: backup-docker-to-local-everything.service.j2 + dest: /etc/systemd/system/backup-docker-to-local-everything.service + notify: reload backup-docker-to-local-everything.service + when: run_once_backup_docker_to_local is not defined + - name: configure backup-docker-to-local.service template: src: backup-docker-to-local.service.j2 diff --git a/roles/backup-docker-to-local/templates/backup-docker-to-local.service.j2 b/roles/backup-docker-to-local/templates/backup-docker-to-local.service.j2 index ec4caa59..c64641f6 100644 --- a/roles/backup-docker-to-local/templates/backup-docker-to-local.service.j2 +++ b/roles/backup-docker-to-local/templates/backup-docker-to-local.service.j2 @@ -4,5 +4,5 @@ OnFailure=systemd-notifier@%n.service cleanup-failed-docker-backups.service [Service] Type=oneshot -ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{system_maintenance_backup_services| join(' ') }} --timeout "{{sytem_maintenance_lock_timeoutbackup_services}}"' +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{ system_maintenance_backup_services | reject('equalto', 'backup-docker-to-local-everything') | join(' ') }} --timeout "{{sytem_maintenance_lock_timeoutbackup_services}}"' ExecStart=/bin/sh -c '/usr/bin/python {{backup_docker_to_local_folder}}backup-docker-to-local.py' \ No newline at end of file diff --git a/roles/backup-docker-to-local/templates/backup-every-docker-volume-to-local.service.j2 b/roles/backup-docker-to-local/templates/backup-every-docker-volume-to-local.service.j2 new file mode 100644 index 00000000..bdb2b638 --- /dev/null +++ b/roles/backup-docker-to-local/templates/backup-every-docker-volume-to-local.service.j2 @@ -0,0 +1,8 @@ +[Unit] +Description=backup docker volumes to local folder +OnFailure=systemd-notifier@%n.service cleanup-failed-docker-backups.service + +[Service] +Type=oneshot +ExecStartPre=/bin/sh -c '/usr/bin/python {{ path_system_lock_script }} {{ system_maintenance_services | join(' ') }} --ignore {{ system_maintenance_backup_services | reject('equalto', 'backup-docker-to-local') | join(' ') }} --timeout "{{sytem_maintenance_lock_timeoutbackup_services}}"' +ExecStart=/bin/sh -c '/usr/bin/python {{backup_docker_to_local_folder}}backup-docker-to-local.py --everything' \ No newline at end of file diff --git a/roles/update-docker/tasks/main.yml b/roles/update-docker/tasks/main.yml index 1c346513..c0576bf5 100644 --- a/roles/update-docker/tasks/main.yml +++ b/roles/update-docker/tasks/main.yml @@ -1,6 +1,6 @@ -- name: "start backup-docker-to-local.service" +- name: "start backup-docker-to-local-everything.service" systemd: - name: backup-docker-to-local.service + name: backup-docker-to-local-everything.service state: started when: force_backup_before_update | bool