From d243b6a32be560612dc45864ad74c9dd2e29ac40 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Mon, 29 May 2023 01:12:35 +0200 Subject: [PATCH] Optimized local backup code --- .../files/backup-to-usb.python | 14 ++++++++------ .../templates/backup-to-usb.service.j2 | 4 +--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/roles/independent_backup-to-usb/files/backup-to-usb.python b/roles/independent_backup-to-usb/files/backup-to-usb.python index 8a5c179a..0ace95ba 100644 --- a/roles/independent_backup-to-usb/files/backup-to-usb.python +++ b/roles/independent_backup-to-usb/files/backup-to-usb.python @@ -46,15 +46,17 @@ def main(): ] rsync_output = subprocess.check_output(rsync_command, stderr=subprocess.STDOUT, text=True) - if "rsync warning: some files vanished before they could be transferred" in rsync_output: + print(rsync_output) + print("Synchronization finished") + sys.exit(0) + except subprocess.CalledProcessError as e: + print(e.output) + if "rsync warning: some files vanished before they could be transferred" in e.output: print("Synchronization finished with rsync warning") sys.exit(0) else: - print("Synchronization finished") - sys.exit(0) - except subprocess.CalledProcessError as e: - print("Synchronization failed:", e.output) - sys.exit(1) + print("Synchronization failed") + sys.exit(1) if __name__ == "__main__": main() \ No newline at end of file diff --git a/roles/independent_backup-to-usb/templates/backup-to-usb.service.j2 b/roles/independent_backup-to-usb/templates/backup-to-usb.service.j2 index ad82599c..d5398db3 100644 --- a/roles/independent_backup-to-usb/templates/backup-to-usb.service.j2 +++ b/roles/independent_backup-to-usb/templates/backup-to-usb.service.j2 @@ -1,13 +1,11 @@ [Unit] Description=Backup to USB when mounted to {{ backup_to_usb_mount }} Wants={{systemctl_mount_service_name}} -After={{systemctl_mount_service_name}} OnFailure=systemd-notifier@%n.service -Requires=backups-cleanup.service -After=backups-cleanup.service [Service] ExecStart=/bin/python {{ backup_to_usb_script_path }} {{backup_to_usb_source}} {{backup_to_usb_destination}} +ExecStartPost=/bin/systemctl start backups-cleanup.service [Install] WantedBy=multi-user.target \ No newline at end of file