wip
This commit is contained in:
118
zfs_autobackup
118
zfs_autobackup
@ -10,68 +10,46 @@ import pprint
|
|||||||
# import cStringIO
|
# import cStringIO
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
class Log:
|
||||||
|
def __init__(self):
|
||||||
|
self.titles=[]
|
||||||
|
pass
|
||||||
|
|
||||||
def error(txt):
|
def titled_str(self, txt, titles):
|
||||||
print(txt, file=sys.stderr)
|
"""magic to make our log messages ident and more clear"""
|
||||||
|
str=""
|
||||||
|
count=0
|
||||||
|
for title in titles:
|
||||||
|
if len(self.titles)>count and self.titles[count]==title:
|
||||||
|
str=str+ ( " " * len(title))
|
||||||
|
else:
|
||||||
|
str=str+title
|
||||||
|
str=str+": "
|
||||||
|
count=count+1
|
||||||
|
|
||||||
def verbose(txt):
|
str=str+txt
|
||||||
if args.verbose:
|
self.titles=titles
|
||||||
print(txt)
|
return(str)
|
||||||
|
|
||||||
def debug(txt):
|
def error(self, txt, titles=[]):
|
||||||
if args.debug:
|
print(txt, file=sys.stderr)
|
||||||
print(txt)
|
|
||||||
|
def verbose(self, txt, titles=[]):
|
||||||
|
if args.verbose:
|
||||||
|
print(self.titled_str(txt, titles))
|
||||||
|
|
||||||
|
def debug(self, txt, titles=[]):
|
||||||
|
if args.debug:
|
||||||
|
print(txt)
|
||||||
|
|
||||||
|
|
||||||
|
log=Log()
|
||||||
|
|
||||||
#fatal abort execution, exit code 255
|
#fatal abort execution, exit code 255
|
||||||
def abort(txt):
|
def abort(txt):
|
||||||
error(txt)
|
log.error(txt)
|
||||||
sys.exit(255)
|
sys.exit(255)
|
||||||
|
|
||||||
# class TreeNode():
|
|
||||||
# """generic tree implementation, with parent/child and prev/next relations"""
|
|
||||||
# def __init__(self, name, parent=None, next=None, prev=None, *args, **kwargs):
|
|
||||||
# self.childs={}
|
|
||||||
#
|
|
||||||
# self.name=name
|
|
||||||
# self.parent=parent
|
|
||||||
# if parent:
|
|
||||||
# if name in parent.childs:
|
|
||||||
# raise(Exception("parent {} already has child {}").format(parent.name, name))
|
|
||||||
# parent.childs[name]=self
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# self.next=next
|
|
||||||
# if next:
|
|
||||||
# if next.prev:
|
|
||||||
# raise(Exception("{} already has a previous item").format(next.name))
|
|
||||||
# next.prev=self
|
|
||||||
#
|
|
||||||
# self.prev=prev
|
|
||||||
# if prev:
|
|
||||||
# if prev.next:
|
|
||||||
# raise(Exception("{} already has a next item").format(prev.name))
|
|
||||||
# prev.next=self
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# def remove(self):
|
|
||||||
# """remove the item from other referenced TreeNodes. call before you actually delete a treeobject"""
|
|
||||||
#
|
|
||||||
# if self.parent:
|
|
||||||
# self.parent.childs.remove(self.name)
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# # let previous and next objects point to eachother
|
|
||||||
# if self.next:
|
|
||||||
# self.next.prev=self.prev
|
|
||||||
#
|
|
||||||
# if self.prev:
|
|
||||||
# self.prev.next=self.next
|
|
||||||
#
|
|
||||||
# self.parent=None
|
|
||||||
# self.next=None
|
|
||||||
# self.prev=None
|
|
||||||
#
|
|
||||||
#
|
|
||||||
|
|
||||||
class cached_property(object):
|
class cached_property(object):
|
||||||
""" A property that is only computed once per instance and then replaces
|
""" A property that is only computed once per instance and then replaces
|
||||||
@ -144,12 +122,12 @@ class ExecuteNode:
|
|||||||
debug_txt="# "+" ".join(encoded_cmd)
|
debug_txt="# "+" ".join(encoded_cmd)
|
||||||
|
|
||||||
if self.readonly and not readonly:
|
if self.readonly and not readonly:
|
||||||
debug("[NOT EXECUTING (readonly mode)] "+debug_txt)
|
log.debug("[NOT EXECUTING (readonly mode)] "+debug_txt)
|
||||||
else:
|
else:
|
||||||
debug(debug_txt)
|
log.debug(debug_txt)
|
||||||
|
|
||||||
if input:
|
if input:
|
||||||
debug("INPUT:\n"+input.rstrip())
|
log.debug("INPUT:\n"+input.rstrip())
|
||||||
stdin=subprocess.PIPE
|
stdin=subprocess.PIPE
|
||||||
else:
|
else:
|
||||||
stdin=None
|
stdin=None
|
||||||
@ -192,10 +170,10 @@ class ZfsDataset():
|
|||||||
return(self.name)
|
return(self.name)
|
||||||
|
|
||||||
def verbose(self,txt):
|
def verbose(self,txt):
|
||||||
self.zfs_node.verbose("{}: {}".format(self.name, txt))
|
self.zfs_node.verbose(txt,[self.name])
|
||||||
|
|
||||||
def debug(self,txt):
|
def debug(self,txt):
|
||||||
self.zfs_node.debug("{}: {}".format(self.name, txt))
|
self.zfs_node.debug(txt,[self.name])
|
||||||
|
|
||||||
|
|
||||||
def invalidate(self):
|
def invalidate(self):
|
||||||
@ -307,11 +285,13 @@ class ZfsNode(ExecuteNode):
|
|||||||
|
|
||||||
ExecuteNode.__init__(self, ssh_to=ssh_to, readonly=readonly)
|
ExecuteNode.__init__(self, ssh_to=ssh_to, readonly=readonly)
|
||||||
|
|
||||||
def verbose(self,txt):
|
def verbose(self,txt,titles=[]):
|
||||||
verbose("{}: {}".format(self.description, txt))
|
titles.insert(0,self.description)
|
||||||
|
log.verbose(txt, titles)
|
||||||
|
|
||||||
def debug(self,txt):
|
def debug(self,txt, titles=[]):
|
||||||
debug("{}: {}".format(self.description, txt))
|
titles.insert(0,self.description)
|
||||||
|
log.debug(txt, titles)
|
||||||
|
|
||||||
def new_snapshotname(self):
|
def new_snapshotname(self):
|
||||||
"""determine uniq new snapshotname"""
|
"""determine uniq new snapshotname"""
|
||||||
@ -370,17 +350,17 @@ class ZfsNode(ExecuteNode):
|
|||||||
direct_filesystems.append(name)
|
direct_filesystems.append(name)
|
||||||
|
|
||||||
if source=="local" and value=="true":
|
if source=="local" and value=="true":
|
||||||
selected_filesystems.append(ZfsDataset(self, name))
|
selected_filesystems.append(dataset)
|
||||||
verbose("* Selected: {0} (direct selection)".format(name))
|
dataset.verbose("Selected (direct selection)")
|
||||||
elif source.find("inherited from ")==0 and (value=="true" or value=="child"):
|
elif source.find("inherited from ")==0 and (value=="true" or value=="child"):
|
||||||
inherited_from=re.sub("^inherited from ", "", source)
|
inherited_from=re.sub("^inherited from ", "", source)
|
||||||
if inherited_from in direct_filesystems:
|
if inherited_from in direct_filesystems:
|
||||||
selected_filesystems.append(ZfsDataset(self, name))
|
selected_filesystems.append(dataset)
|
||||||
verbose("* Selected: {0} (inherited selection)".format(name))
|
dataset.verbose("Selected (inherited selection)")
|
||||||
else:
|
else:
|
||||||
verbose("* Ignored : {0} (already a backup)".format(name))
|
dataset.verbose("Ignored (already a backup)")
|
||||||
else:
|
else:
|
||||||
verbose("* Ignored : {0} (only childs)".format(name))
|
dataset.verbose("Ignored (only childs)")
|
||||||
|
|
||||||
return(selected_filesystems)
|
return(selected_filesystems)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user