Implemented cleanup procedure for failed backups

This commit is contained in:
Kevin Veen-Birkenbach 2023-11-04 14:36:55 +01:00
parent ebcd93f837
commit dfc0dbbffa
12 changed files with 44 additions and 6 deletions

View File

@ -1,12 +1,11 @@
- name: "reload pull-remote-backups service" - name: "reload pull-remote-backups service"
systemd: systemd:
name: pull-remote-backups.service name: pull-remote-backups.service
state: reloaded
enabled: yes enabled: yes
daemon_reload: yes daemon_reload: yes
- name: "restart pull-remote-backups timer" - name: "restart pull-remote-backups timer"
systemd: systemd:
name: pull-remote-backups.timer name: pull-remote-backups.timer
state: restarted state: started
enabled: yes enabled: yes
daemon_reload: yes daemon_reload: yes

View File

@ -2,3 +2,4 @@ dependencies:
- git - git
- systemd_notifier - systemd_notifier
- backups-cleanup-timer - backups-cleanup-timer
- docker-volume-backup-cleanup

View File

@ -1,6 +1,6 @@
[Unit] [Unit]
Description=pull remote backups Description=pull remote backups
OnFailure=systemd-notifier@%n.service OnFailure=systemd-notifier@%n.service docker-volume-backup-cleanup.service
[Service] [Service]
Type=oneshot Type=oneshot

View File

@ -0,0 +1,3 @@
# Docker Volume Backup Cleanup
This script cleans up failed docker backups.
It uses https://github.com/kevinveenbirkenbach/docker-volume-backup-cleanup as base.

View File

@ -0,0 +1,5 @@
- name: "reload docker-volume-backup-cleanup.service daemon"
systemd:
name: docker-volume-backup-cleanup.service
enabled: yes
daemon_reload: yes

View File

@ -0,0 +1,3 @@
dependencies:
- git
- systemd_notifier

View File

@ -0,0 +1,18 @@
- name: pull docker-volume-backup-cleanup.git
git:
repo: "https://github.com/kevinveenbirkenbach/docker-volume-backup-cleanup.git"
dest: "{{docker_volume_backup_cleanup_folder}}"
update: yes
register: git_result
ignore_errors: true
- name: Warn if repo is not reachable
debug:
msg: "Warning: Repository is not reachable."
when: git_result.failed
- name: configure docker-volume-backup-cleanup.service
template:
src: docker-volume-backup-cleanup.service.j2
dest: /etc/systemd/system/docker-volume-backup-cleanup.service
notify: reload docker-volume-backup-cleanup.service daemon

View File

@ -0,0 +1,7 @@
[Unit]
Description=Cleans up failed docker volume backups
OnFailure=systemd-notifier@%n.service
[Service]
Type=oneshot
ExecStart=/bin/sh -c '/usr/bin/yes | /usr/bin/bash {{docker_volume_backup_cleanup_folder}}cleanup.sh {{docker_volume_backup_cleanup_machine_id}} {{docker_volume_backup_cleanup_trigger_directory}}'

View File

@ -0,0 +1 @@
docker_volume_backup_cleanup_folder: "{{path_administrator_scripts}}docker-volume-backup-cleanup/"

View File

@ -1,12 +1,12 @@
- name: "reload docker-volume-backup.service" - name: "reload docker-volume-backup.service"
systemd: systemd:
name: docker-volume-backup.service name: docker-volume-backup.service
state: reloaded
enabled: yes enabled: yes
daemon_reload: yes daemon_reload: yes
- name: "restart docker-volume-backup.timer" - name: "restart docker-volume-backup.timer"
systemd: systemd:
name: docker-volume-backup.timer name: docker-volume-backup.timer
state: restarted state: started
enabled: yes enabled: yes
daemon_reload: yes daemon_reload: yes

View File

@ -2,3 +2,4 @@ dependencies:
- git - git
- backups-provider - backups-provider
- systemd_notifier - systemd_notifier
- docker-volume-backup-cleanup

View File

@ -1,6 +1,6 @@
[Unit] [Unit]
Description=docker volume backup Description=docker volume backup
OnFailure=systemd-notifier@%n.service OnFailure=systemd-notifier@%n.service docker-volume-backup-cleanup.service
[Service] [Service]
Type=oneshot Type=oneshot