WIP
This commit is contained in:
@ -23,13 +23,19 @@ def debug(txt):
|
||||
print(txt)
|
||||
|
||||
|
||||
class Node(Object):
|
||||
"""an endpoint that contains zfs filesystems. can be local or remote"""
|
||||
class ZfsNode:
|
||||
"""an endpoint that contains zfs filesystems.
|
||||
|
||||
def __init__(self, ssh_to='local'):
|
||||
self.backup_name=backup_name
|
||||
contains lowlevel zfs wrappers for actual zfs commands on remote nodes via ssh (or local)
|
||||
|
||||
methods only accept and return simple dataset names, just like the real commands
|
||||
"""
|
||||
|
||||
def __init__(self, ssh_to):
|
||||
"""ssh_to: server you want to ssh to. specify 'local' to just use local commands without ssh"""
|
||||
self.ssh_to=ssh_to
|
||||
|
||||
|
||||
def run(cmd, input=None, tab_split=False, valid_exitcodes=[ 0 ], test=False):
|
||||
"""run a command on the node"""
|
||||
|
||||
@ -87,7 +93,10 @@ class Node(Object):
|
||||
|
||||
|
||||
def zfs_get_selected_filesystems():
|
||||
"""determine filesystems that should be backupped by looking at the special autobackup-property"""
|
||||
"""determine filesystems that should be backupped by looking at the special autobackup-property
|
||||
|
||||
return: list with dataset names
|
||||
"""
|
||||
|
||||
#get all source filesystems that have the backup property
|
||||
source_filesystems=self.run(tab_split=True, cmd=[
|
||||
@ -171,20 +180,18 @@ class Node(Object):
|
||||
|
||||
#in testmode we dont actually make changes, so keep them in a list to simulate
|
||||
if args.test:
|
||||
if not ssh_to in test_snapshots:
|
||||
test_snapshots[ssh_to]={}
|
||||
if not filesystem in test_snapshots[ssh_to]:
|
||||
test_snapshots[ssh_to][filesystem]=[]
|
||||
test_snapshots[ssh_to][filesystem].append(snapshot)
|
||||
if not filesystem in test_snapshots:
|
||||
test_snapshots[filesystem]=[]
|
||||
test_snapshots[filesystem].append(snapshot)
|
||||
|
||||
run(ssh_to=ssh_to, tab_split=False, cmd=cmd, test=args.test)
|
||||
|
||||
|
||||
def zfs_get_snapshots(filesystems):
|
||||
"""get names of all snapshots for specified filesystems belonging to backup_name
|
||||
|
||||
return[filesystem_name]=[ "snashot1", "snapshot2", ... ]
|
||||
"""
|
||||
def zfs_get_snapshots(ssh_to, filesystems, backup_name):
|
||||
|
||||
ret={}
|
||||
|
||||
@ -392,6 +399,53 @@ def lstrip_path(path, count):
|
||||
return("/".join(path.split("/")[count:]))
|
||||
|
||||
|
||||
class ZfsDataset:
|
||||
"""a generic zfs dataset"""
|
||||
|
||||
def __init__(name, parent, backup=false, created=false):
|
||||
""" backup: should be backupped by zfs_autobackup
|
||||
created: is created by zfs_autobackup (and may be destroyed by it as well)
|
||||
parent: parent dataset this belongs to (none is "root")
|
||||
|
||||
"""
|
||||
self.name=name
|
||||
self.parent=parent
|
||||
self.created=created
|
||||
self.backup=backup
|
||||
|
||||
self.childs={}
|
||||
|
||||
|
||||
class ZfsSnapshot(Dataset):
|
||||
"""A zfs snapshot"""
|
||||
def __init__(previous_snapshot=false, next_snapshot=fase, keep_time=false, timestamp=false, **kwargs, *args):
|
||||
super.__init__(**kargs, *args)
|
||||
self.timestamp
|
||||
self.keep_time
|
||||
self.previous_snapshot
|
||||
self.next_snapshot
|
||||
|
||||
|
||||
class ZfsBackupSource():
|
||||
"""backup source.
|
||||
|
||||
contains high level backup source functions.
|
||||
|
||||
these work with ZfsDataset and ZfsSnapshot objects.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.node=ZfsNode(ssh_to=args.ssh_to)
|
||||
self.datasets={}
|
||||
self.snapshots={}
|
||||
|
||||
|
||||
def refresh():
|
||||
"""refresh all data by calling various zfs commands"""
|
||||
selected_filesystems=self.node.zfs_get_selected_filesystems()
|
||||
|
||||
|
||||
|
||||
def zfs_autobackup():
|
||||
|
||||
|
||||
Reference in New Issue
Block a user