add: class Dataset
This commit is contained in:
+24
-14
@@ -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,19 +37,27 @@ 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:
|
||||||
datasets_str = (
|
def __init__(self, name: str):
|
||||||
Command([config.ZFS, "list", "-H", "-d", "1", "-o", "name", config.local_pool])
|
self.name = name
|
||||||
.stdout.strip()
|
|
||||||
.decode()
|
def __repr__(self):
|
||||||
)
|
return self.name
|
||||||
# we omit the first return value, which is the pool, not the dataset
|
|
||||||
datasets_list = datasets_str.split("\n")[1:]
|
@classmethod
|
||||||
to_backup = [d for d in datasets_list if d not in config.do_not_backup]
|
def from_local_pool(cls) -> list[Dataset]:
|
||||||
print("Folgende Datasets und alle darunter befindlichen Kinder werden gesichert:")
|
datasets_str = (
|
||||||
for tb in to_backup:
|
Command([config.ZFS, "list", "-H", "-d", "1", "-o", "name", config.local_pool])
|
||||||
print(" " + tb)
|
.stdout.strip()
|
||||||
return to_backup
|
.decode()
|
||||||
|
)
|
||||||
|
# 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):
|
def get_snapshots(pool):
|
||||||
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user