From 1b4d726fd09d30e8d734708576365f2fd4cf317b Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 2 May 2023 17:58:16 +0200 Subject: [PATCH] Finished backup to swappable implementation --- README.md | 2 +- roles/independent_backup-to-swappable/meta/main.yml | 1 + .../templates/backup-to-swappable.service.j2 | 1 + .../README.md | 2 +- .../files/backups-cleanup.py | 9 ++++----- .../handlers/main.yml | 6 ------ .../meta/main.yml | 0 .../tasks/main.yml | 6 ------ .../templates/backups-cleanup.service.j2 | 0 .../vars/main.yml | 0 roles/independent_backups-cleanup-timer/README.md | 3 +++ .../independent_backups-cleanup-timer/handlers/main.yml | 6 ++++++ roles/independent_backups-cleanup-timer/meta/main.yml | 2 ++ roles/independent_backups-cleanup-timer/tasks/main.yml | 5 +++++ .../templates/backups-cleanup.timer.j2 | 0 roles/server_native-backups-consumer/meta/main.yml | 2 +- roles/server_native-backups-provider/meta/main.yml | 2 +- 17 files changed, 26 insertions(+), 21 deletions(-) rename roles/{server_native-backups-cleanup => independent_backups-cleanup-service}/README.md (85%) rename roles/{server_native-backups-cleanup => independent_backups-cleanup-service}/files/backups-cleanup.py (95%) rename roles/{server_native-backups-cleanup => independent_backups-cleanup-service}/handlers/main.yml (50%) rename roles/{server_native-backups-cleanup => independent_backups-cleanup-service}/meta/main.yml (100%) rename roles/{server_native-backups-cleanup => independent_backups-cleanup-service}/tasks/main.yml (76%) rename roles/{server_native-backups-cleanup => independent_backups-cleanup-service}/templates/backups-cleanup.service.j2 (100%) rename roles/{server_native-backups-cleanup => independent_backups-cleanup-service}/vars/main.yml (100%) create mode 100644 roles/independent_backups-cleanup-timer/README.md create mode 100644 roles/independent_backups-cleanup-timer/handlers/main.yml create mode 100644 roles/independent_backups-cleanup-timer/meta/main.yml create mode 100644 roles/independent_backups-cleanup-timer/tasks/main.yml rename roles/{server_native-backups-cleanup => independent_backups-cleanup-timer}/templates/backups-cleanup.timer.j2 (100%) diff --git a/README.md b/README.md index 7405f78d..e8bc132f 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ This software allows to setup the docker following applications: #### Native Applications This software shipts the following tools which are natively setup on the server: -- [Backups Cleanup](./roles/server_native-backups-cleanup/README.md) - Cleans up old backups +- [Backups Cleanup](./roles/independent_backups-cleanup-timer/README.md) - Cleans up old backups - [Btrfs Health Check](./roles/server_native-btrfs-health-check/README.md) - Checks the health of Btrfs file systems - [Docker Health Check](./roles/server_native-docker-health-check/) - Checks the health of docker containers - [Docker Reverse Proxy](./roles/server_native-docker-reverse-proxy/README.md) - Docker Reverse Proxy Solution diff --git a/roles/independent_backup-to-swappable/meta/main.yml b/roles/independent_backup-to-swappable/meta/main.yml index b05984a6..3d3b8bb0 100644 --- a/roles/independent_backup-to-swappable/meta/main.yml +++ b/roles/independent_backup-to-swappable/meta/main.yml @@ -1,3 +1,4 @@ dependencies: - independent_user-administrator - independent_systemd-email +- independent_backups-cleanup-service diff --git a/roles/independent_backup-to-swappable/templates/backup-to-swappable.service.j2 b/roles/independent_backup-to-swappable/templates/backup-to-swappable.service.j2 index 0e66dd3b..ab2e42ed 100644 --- a/roles/independent_backup-to-swappable/templates/backup-to-swappable.service.j2 +++ b/roles/independent_backup-to-swappable/templates/backup-to-swappable.service.j2 @@ -2,6 +2,7 @@ Description=backing up data OnFailure=systemd-email@%n.service ConditionPathExists={{backup_to_swappable_destination_path}} +Wants=backups-cleanup.service [Service] Type=oneshot diff --git a/roles/server_native-backups-cleanup/README.md b/roles/independent_backups-cleanup-service/README.md similarity index 85% rename from roles/server_native-backups-cleanup/README.md rename to roles/independent_backups-cleanup-service/README.md index bd617369..929c3aea 100644 --- a/roles/server_native-backups-cleanup/README.md +++ b/roles/independent_backups-cleanup-service/README.md @@ -1,4 +1,4 @@ -# role server_native-backups-cleanup +# role independent_backups-cleanup-timer Cleans up old backups diff --git a/roles/server_native-backups-cleanup/files/backups-cleanup.py b/roles/independent_backups-cleanup-service/files/backups-cleanup.py similarity index 95% rename from roles/server_native-backups-cleanup/files/backups-cleanup.py rename to roles/independent_backups-cleanup-service/files/backups-cleanup.py index 3a0eb337..a61569dc 100644 --- a/roles/server_native-backups-cleanup/files/backups-cleanup.py +++ b/roles/independent_backups-cleanup-service/files/backups-cleanup.py @@ -17,11 +17,10 @@ def is_directory_used_by_another_process(directory_path): command= "lsof " + directory_path process = subprocess.Popen([command], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) output, error = process.communicate() - if error: - raise Exception(error.strip()) - if output: - return True - return False + # @See https://stackoverflow.com/questions/29841984/non-zero-exit-code-for-lsof + if process.wait() > bool(0): + return False + return True for host_backup_directory_name in os.listdir(args.backups_folder_path): host_backup_directory_path = os.path.join(args.backups_folder_path, host_backup_directory_name) diff --git a/roles/server_native-backups-cleanup/handlers/main.yml b/roles/independent_backups-cleanup-service/handlers/main.yml similarity index 50% rename from roles/server_native-backups-cleanup/handlers/main.yml rename to roles/independent_backups-cleanup-service/handlers/main.yml index ad2bb49b..43cba994 100644 --- a/roles/server_native-backups-cleanup/handlers/main.yml +++ b/roles/independent_backups-cleanup-service/handlers/main.yml @@ -4,9 +4,3 @@ state: reloaded enabled: yes daemon_reload: yes -- name: "restart backups-cleanup.timer" - systemd: - name: backups-cleanup.timer - state: restarted - enabled: yes - daemon_reload: yes diff --git a/roles/server_native-backups-cleanup/meta/main.yml b/roles/independent_backups-cleanup-service/meta/main.yml similarity index 100% rename from roles/server_native-backups-cleanup/meta/main.yml rename to roles/independent_backups-cleanup-service/meta/main.yml diff --git a/roles/server_native-backups-cleanup/tasks/main.yml b/roles/independent_backups-cleanup-service/tasks/main.yml similarity index 76% rename from roles/server_native-backups-cleanup/tasks/main.yml rename to roles/independent_backups-cleanup-service/tasks/main.yml index 37b3c548..00770e50 100644 --- a/roles/server_native-backups-cleanup/tasks/main.yml +++ b/roles/independent_backups-cleanup-service/tasks/main.yml @@ -24,9 +24,3 @@ src: "backups-cleanup.service.j2" dest: "/etc/systemd/system/backups-cleanup.service" notify: reload backups-cleanup.service - -- name: create backups-cleanup.timer - template: - src: "backups-cleanup.timer.j2" - dest: "/etc/systemd/system/backups-cleanup.timer" - notify: restart backups-cleanup.timer diff --git a/roles/server_native-backups-cleanup/templates/backups-cleanup.service.j2 b/roles/independent_backups-cleanup-service/templates/backups-cleanup.service.j2 similarity index 100% rename from roles/server_native-backups-cleanup/templates/backups-cleanup.service.j2 rename to roles/independent_backups-cleanup-service/templates/backups-cleanup.service.j2 diff --git a/roles/server_native-backups-cleanup/vars/main.yml b/roles/independent_backups-cleanup-service/vars/main.yml similarity index 100% rename from roles/server_native-backups-cleanup/vars/main.yml rename to roles/independent_backups-cleanup-service/vars/main.yml diff --git a/roles/independent_backups-cleanup-timer/README.md b/roles/independent_backups-cleanup-timer/README.md new file mode 100644 index 00000000..657baa0f --- /dev/null +++ b/roles/independent_backups-cleanup-timer/README.md @@ -0,0 +1,3 @@ +# role independent_backups-cleanup-timer + +Timer for cleaning up old backups \ No newline at end of file diff --git a/roles/independent_backups-cleanup-timer/handlers/main.yml b/roles/independent_backups-cleanup-timer/handlers/main.yml new file mode 100644 index 00000000..2338bed4 --- /dev/null +++ b/roles/independent_backups-cleanup-timer/handlers/main.yml @@ -0,0 +1,6 @@ +- name: "restart backups-cleanup.timer" + systemd: + name: backups-cleanup.timer + state: restarted + enabled: yes + daemon_reload: yes diff --git a/roles/independent_backups-cleanup-timer/meta/main.yml b/roles/independent_backups-cleanup-timer/meta/main.yml new file mode 100644 index 00000000..a5e6b7a1 --- /dev/null +++ b/roles/independent_backups-cleanup-timer/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - independent_backups-cleanup-service diff --git a/roles/independent_backups-cleanup-timer/tasks/main.yml b/roles/independent_backups-cleanup-timer/tasks/main.yml new file mode 100644 index 00000000..47cae32f --- /dev/null +++ b/roles/independent_backups-cleanup-timer/tasks/main.yml @@ -0,0 +1,5 @@ +- name: create backups-cleanup.timer + template: + src: "backups-cleanup.timer.j2" + dest: "/etc/systemd/system/backups-cleanup.timer" + notify: restart backups-cleanup.timer diff --git a/roles/server_native-backups-cleanup/templates/backups-cleanup.timer.j2 b/roles/independent_backups-cleanup-timer/templates/backups-cleanup.timer.j2 similarity index 100% rename from roles/server_native-backups-cleanup/templates/backups-cleanup.timer.j2 rename to roles/independent_backups-cleanup-timer/templates/backups-cleanup.timer.j2 diff --git a/roles/server_native-backups-consumer/meta/main.yml b/roles/server_native-backups-consumer/meta/main.yml index 3e69c643..621de431 100644 --- a/roles/server_native-backups-consumer/meta/main.yml +++ b/roles/server_native-backups-consumer/meta/main.yml @@ -1,4 +1,4 @@ dependencies: - server_native-git - independent_systemd-email - - server_native-backups-cleanup + - independent_backups-cleanup-timer diff --git a/roles/server_native-backups-provider/meta/main.yml b/roles/server_native-backups-provider/meta/main.yml index 143af587..050d4c94 100644 --- a/roles/server_native-backups-provider/meta/main.yml +++ b/roles/server_native-backups-provider/meta/main.yml @@ -1,3 +1,3 @@ dependencies: - server_native-backups-provider-user -- server_native-backups-cleanup +- independent_backups-cleanup-timer