From 5fd53479a0a9981c0aaae4e569e41bc36e4a4393 Mon Sep 17 00:00:00 2001 From: timeshifter Date: Sat, 4 Dec 2021 21:04:53 +0100 Subject: [PATCH] add: first backup feature --- zfs-backup.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/zfs-backup.py b/zfs-backup.py index e183b15..f6d068c 100755 --- a/zfs-backup.py +++ b/zfs-backup.py @@ -47,7 +47,6 @@ def main(): # TODO tests # TODO docstrings -# TODO first backup # TODO --skip-import # TODO --skip-post-backup-scrub # TODO print time estimation while scrub is in progress @@ -78,8 +77,10 @@ class Manager: if remote_dataset: stream = self._send_incremental(local_dataset, remote_dataset) else: - # TODO ask for confirmation before sending - stream = self._send_absolute(local_dataset) + if self._ask_user_confirmation(local_dataset): + stream = self._send_absolute(local_dataset) + else: + continue ZFS.receive(stream, self._external_pool) def _send_incremental( @@ -139,6 +140,19 @@ class Manager: common_snapshots.sort() return common_snapshots[-1] + @staticmethod + def _ask_user_confirmation(dataset: Dataset) -> bool: + msg = f"Dataset {dataset.qualified_name} does not exist in backup pool. Backup? [y/n] " + reply = "" + while not reply: + reply = input(msg).lower() + if reply == "y": + return True + elif reply == "n": + return False + else: + reply = "" + def _get_regex_matching_snapshots_with_tags(tags: list[str]): return "@" + ".*".join(tags)