add: class Dataset

This commit is contained in:
timeshifter
2021-11-25 15:42:59 +01:00
parent 63d1d3e2fc
commit 7a46f0d810
+15 -5
View File
@@ -1,6 +1,8 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import annotations
import os import os
from subprocess import Popen, PIPE, check_output from subprocess import Popen, PIPE, check_output
import config import config
@@ -35,7 +37,15 @@ def find_backup_pool():
raise IOError("Konnte keine Backup-Platte finden!") raise IOError("Konnte keine Backup-Platte finden!")
def get_datasets_to_backup(): class Dataset:
def __init__(self, name: str):
self.name = name
def __repr__(self):
return self.name
@classmethod
def from_local_pool(cls) -> list[Dataset]:
datasets_str = ( datasets_str = (
Command([config.ZFS, "list", "-H", "-d", "1", "-o", "name", config.local_pool]) Command([config.ZFS, "list", "-H", "-d", "1", "-o", "name", config.local_pool])
.stdout.strip() .stdout.strip()
@@ -43,10 +53,10 @@ def get_datasets_to_backup():
) )
# we omit the first return value, which is the pool, not the dataset # we omit the first return value, which is the pool, not the dataset
datasets_list = datasets_str.split("\n")[1:] datasets_list = datasets_str.split("\n")[1:]
to_backup = [d for d in datasets_list if d not in config.do_not_backup] 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:") print("Folgende Datasets und alle darunter befindlichen Kinder werden gesichert:")
for tb in to_backup: for item in to_backup:
print(" " + tb) print(" " + str(item))
return to_backup return to_backup
@@ -199,7 +209,7 @@ def zfs_destroy(full_name, recursive=False):
def main(): def main():
verify_running_as_root() verify_running_as_root()
datasets = get_datasets_to_backup() datasets = Dataset.from_local_pool()
backup_pool = find_backup_pool() backup_pool = find_backup_pool()
import_pool(backup_pool) import_pool(backup_pool)
try: try: