Dataset.from_local_pool --> Pool.datasets
This commit is contained in:
+24
-19
@@ -20,11 +20,12 @@ Erstes Backup muss für alle notwendigen Datasets durchgeführt werden mit
|
||||
|
||||
def main():
|
||||
verify_running_as_root()
|
||||
datasets = Dataset.from_local_pool()
|
||||
backup_pool = Pool.from_dict(config.backup_pool)
|
||||
local_pool = Pool(config.local_pool_to_backup)
|
||||
datasets_to_backup = local_pool.get_datasets_not_in_list(config.do_not_backup)
|
||||
backup_pool = Pool.find_from_dict(config.backup_pool)
|
||||
import_pool(backup_pool)
|
||||
try:
|
||||
send_datasets_to_backup_pool(backup_pool, datasets)
|
||||
send_datasets_to_backup_pool(backup_pool, datasets_to_backup)
|
||||
finally:
|
||||
export_pool(backup_pool)
|
||||
|
||||
@@ -34,9 +35,22 @@ class Pool:
|
||||
self.name = name
|
||||
|
||||
@cache
|
||||
@property
|
||||
def datasets(self) -> list[Dataset]:
|
||||
datasets_str = get_output_of_command(
|
||||
[config.ZFS, "list", "-H", "-d", "1", "-o", "name", self.name]
|
||||
)
|
||||
# we omit the first return value, which is the pool, not the dataset
|
||||
datasets_list = datasets_str.split("\n")[1:]
|
||||
to_backup = [Dataset(d) for d in datasets_list]
|
||||
return to_backup
|
||||
|
||||
@cache
|
||||
def get_datasets_not_in_list(self, do_not_backup) -> list[Dataset]:
|
||||
return [d for d in self.datasets if d.name not in do_not_backup]
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, backup_pools: dict[str, str]) -> Pool:
|
||||
def find_from_dict(cls, backup_pools: dict[str, str]) -> Pool:
|
||||
print("Suche nach externer Festplatte für Backups")
|
||||
present_uuids = get_output_of_command(["ls", "/dev/disk/by-uuid"])
|
||||
for pool, uuid in backup_pools.items():
|
||||
@@ -54,21 +68,6 @@ class Dataset:
|
||||
def __repr__(self):
|
||||
return self.name
|
||||
|
||||
@classmethod
|
||||
def from_local_pool(cls) -> list[Dataset]:
|
||||
datasets_str = get_output_of_command(
|
||||
[config.ZFS, "list", "-H", "-d", "1", "-o", "name", config.local_pool_to_backup]
|
||||
)
|
||||
# we omit the first return value, which is the pool, not the dataset
|
||||
datasets_list = datasets_str.split("\n")[1:]
|
||||
to_backup = [Dataset(d) for d in datasets_list if d not in config.do_not_backup]
|
||||
print(
|
||||
"Folgende Datasets und alle darunter befindlichen Kinder werden gesichert:"
|
||||
)
|
||||
for item in to_backup:
|
||||
print(" " + str(item))
|
||||
return to_backup
|
||||
|
||||
|
||||
def get_snapshots(pool):
|
||||
return get_output_of_command(
|
||||
@@ -256,5 +255,11 @@ def verify_running_as_root():
|
||||
exit(1)
|
||||
|
||||
|
||||
def show_actions_to_execute(datasets: list[Dataset]):
|
||||
print("Folgende Datasets und alle darunter befindlichen Kinder werden gesichert:")
|
||||
for ds in datasets:
|
||||
print(" " + str(ds))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user