From 63d1d3e2fc935c14dab60b77edd2596de5dea9f1 Mon Sep 17 00:00:00 2001 From: timeshifter Date: Thu, 25 Nov 2021 15:42:39 +0100 Subject: [PATCH] refactor: send_datasets_to_backup_pool --- zfs-backup.py | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/zfs-backup.py b/zfs-backup.py index 31b616c..0503f7f 100755 --- a/zfs-backup.py +++ b/zfs-backup.py @@ -203,33 +203,37 @@ def main(): backup_pool = find_backup_pool() import_pool(backup_pool) try: - last_local_snapshot = last_snapshot(config.local_pool) - if not last_local_snapshot: - print("Es scheint keine Snapshots im Speicherpool zu geben") - print("Breche ab.") - export_pool(backup_pool) - exit() - last_remote_snapshot = last_snapshot(backup_pool) - if not last_remote_snapshot: - print("Es scheint keine Snapshots auf der Backup-Festplatte zu geben") - print("Breche ab.") - export_pool(backup_pool) - exit() - if not present_locally(last_remote_snapshot): - print( - """ - Kann keine inkrementelle Sicherung durchführen, da es im Backup und auf dem Server - keinen gemeinsamen Snapshot gibt. Vermutlich wurde diese externe Festplatte vor - zu langer Zeit das letzte mal als Backup verwendet""" - ) - return - for dataset in datasets: - do_backup(dataset, last_local_snapshot, last_remote_snapshot, backup_pool) - clean_old_snapshots(dataset, backup_pool) + send_datasets_to_backup_pool(backup_pool, datasets) finally: export_pool(backup_pool) +def send_datasets_to_backup_pool(backup_pool, datasets): + last_local_snapshot = last_snapshot(config.local_pool) + if not last_local_snapshot: + print("Es scheint keine Snapshots im Speicherpool zu geben") + print("Breche ab.") + export_pool(backup_pool) + exit() + last_remote_snapshot = last_snapshot(backup_pool) + if not last_remote_snapshot: + print("Es scheint keine Snapshots auf der Backup-Festplatte zu geben") + print("Breche ab.") + export_pool(backup_pool) + exit() + if not present_locally(last_remote_snapshot): + print( + """ +Kann keine inkrementelle Sicherung durchführen, da es im Backup und auf dem Server +keinen gemeinsamen Snapshot gibt. Vermutlich wurde diese externe Festplatte vor +zu langer Zeit das letzte mal als Backup verwendet""" + ) + return + for dataset in datasets: + do_backup(dataset, last_local_snapshot, last_remote_snapshot, backup_pool) + clean_old_snapshots(dataset, backup_pool) + + def verify_running_as_root(): if os.getuid() > 0: print("Muss als root ausgeführt werden.")