chg: confirm new datasets before doing anything
This commit is contained in:
+25
-10
@@ -48,6 +48,8 @@ def main():
|
||||
|
||||
|
||||
class Manager:
|
||||
_map_type: dict[Dataset, Dataset | None]
|
||||
|
||||
def __init__(self, local_pool: Pool, external_pool: ExternalPool):
|
||||
self._local_pool = local_pool
|
||||
self._external_pool = external_pool
|
||||
@@ -64,18 +66,30 @@ class Manager:
|
||||
|
||||
def _backup_all_datasets(self):
|
||||
print("Backing up datasets")
|
||||
for local_dataset in self._datasets_to_backup:
|
||||
remote_dataset = self._search_matching_dataset_in_remote_pool(
|
||||
for local_dataset, remote_dataset in self._get_dataset_backup_map().items():
|
||||
if remote_dataset is None:
|
||||
stream = self._send_absolute(local_dataset)
|
||||
else:
|
||||
stream = self._send_incremental(local_dataset, remote_dataset)
|
||||
ZFS.receive(stream, self._external_pool)
|
||||
|
||||
def _get_dataset_backup_map(self) -> _map_type:
|
||||
return self._user_confirm_new_datasets(self._get_raw_dataset_map())
|
||||
|
||||
def _user_confirm_new_datasets(self, dataset_map: _map_type) -> _map_type:
|
||||
return {
|
||||
local_dataset: remote_dataset
|
||||
for local_dataset, remote_dataset in dataset_map.items()
|
||||
if remote_dataset is not None or self._ask_user_confirmation(local_dataset)
|
||||
}
|
||||
|
||||
def _get_raw_dataset_map(self) -> _map_type:
|
||||
return {
|
||||
local_dataset: self._search_matching_dataset_in_remote_pool(
|
||||
local_dataset, self._external_pool
|
||||
)
|
||||
if remote_dataset:
|
||||
stream = self._send_incremental(local_dataset, remote_dataset)
|
||||
else:
|
||||
if self._ask_user_confirmation(local_dataset):
|
||||
stream = self._send_absolute(local_dataset)
|
||||
else:
|
||||
continue
|
||||
ZFS.receive(stream, self._external_pool)
|
||||
for local_dataset in self._datasets_to_backup
|
||||
}
|
||||
|
||||
def _send_incremental(
|
||||
self, local_dataset: Dataset, remote_dataset: Dataset
|
||||
@@ -395,6 +409,7 @@ class ZFS(CommandInterface):
|
||||
|
||||
@classmethod
|
||||
def send_absolute(cls, snapshot: Snapshot) -> Popen:
|
||||
print(f" {snapshot} -> [new]")
|
||||
return cls._open_stream(*cls._Subcommands.Send.absolute, str(snapshot))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user