mirror of
https://github.com/psy0rz/zfs_autobackup.git
synced 2025-04-29 23:21:28 +03:00
move more ulgy stuff to parse_args
This commit is contained in:
parent
033fcf68f7
commit
d2b183bb27
@ -15,12 +15,15 @@ class ZfsAuto(object):
|
|||||||
|
|
||||||
def __init__(self, argv, print_arguments=True):
|
def __init__(self, argv, print_arguments=True):
|
||||||
|
|
||||||
|
self.hold_name = None
|
||||||
|
self.snapshot_time_format = None
|
||||||
|
self.property_name = None
|
||||||
|
self.exclude_paths = None
|
||||||
|
|
||||||
# helps with investigating failed regression tests:
|
# helps with investigating failed regression tests:
|
||||||
if print_arguments:
|
if print_arguments:
|
||||||
print("ARGUMENTS: " + " ".join(argv))
|
print("ARGUMENTS: " + " ".join(argv))
|
||||||
|
|
||||||
|
|
||||||
self.exclude_paths = []
|
|
||||||
self.args = self.parse_args(argv)
|
self.args = self.parse_args(argv)
|
||||||
|
|
||||||
def parse_args(self, argv):
|
def parse_args(self, argv):
|
||||||
@ -66,16 +69,31 @@ class ZfsAuto(object):
|
|||||||
# may still need to be used to explicitly exclude a backup with the 'received' source property to avoid accidental
|
# may still need to be used to explicitly exclude a backup with the 'received' source property to avoid accidental
|
||||||
# recursive replication of a zvol that is currently being received in another session (as it will have changes).
|
# recursive replication of a zvol that is currently being received in another session (as it will have changes).
|
||||||
|
|
||||||
args.exclude_paths = [] # not an actual arg, but depending on args so whatever :)
|
self.exclude_paths = []
|
||||||
if args.ssh_source == args.ssh_target:
|
if args.ssh_source == args.ssh_target:
|
||||||
if args.target_path:
|
if args.target_path:
|
||||||
# target and source are the same, make sure to exclude target_path
|
# target and source are the same, make sure to exclude target_path
|
||||||
self.verbose("NOTE: Source and target are on the same host, excluding target-path from selection.")
|
self.verbose("NOTE: Source and target are on the same host, excluding target-path from selection.")
|
||||||
args.exclude_paths.append(args.target_path)
|
self.exclude_paths.append(args.target_path)
|
||||||
else:
|
else:
|
||||||
self.verbose("NOTE: Source and target are on the same host, excluding received datasets from selection.")
|
self.verbose("NOTE: Source and target are on the same host, excluding received datasets from selection.")
|
||||||
args.exclude_received = True
|
args.exclude_received = True
|
||||||
|
|
||||||
|
if args.test:
|
||||||
|
self.warning("TEST MODE - SIMULATING WITHOUT MAKING ANY CHANGES")
|
||||||
|
|
||||||
|
#format all the names
|
||||||
|
self.property_name = args.property_format.format(args.backup_name)
|
||||||
|
self.snapshot_time_format = args.snapshot_format.format(args.backup_name)
|
||||||
|
self.hold_name = args.hold_format.format(args.backup_name)
|
||||||
|
|
||||||
|
self.verbose("")
|
||||||
|
self.verbose("Selecting dataset property : {}".format(self.property_name))
|
||||||
|
self.verbose("Snapshot format : {}".format(self.snapshot_time_format))
|
||||||
|
|
||||||
|
if not args.no_holds:
|
||||||
|
self.verbose("Hold name : {}".format(self.hold_name))
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
def get_parser(self):
|
def get_parser(self):
|
||||||
@ -116,6 +134,15 @@ class ZfsAuto(object):
|
|||||||
help='Target host to push backup to.')
|
help='Target host to push backup to.')
|
||||||
|
|
||||||
|
|
||||||
|
group=parser.add_argument_group("String formatting options")
|
||||||
|
group.add_argument('--property-format', metavar='FORMAT', default="autobackup:{}",
|
||||||
|
help='Dataset selection string format. Default: %(default)s')
|
||||||
|
group.add_argument('--snapshot-format', metavar='FORMAT', default="{}-%Y%m%d%H%M%S",
|
||||||
|
help='ZFS Snapshot string format. Default: %(default)s')
|
||||||
|
group.add_argument('--hold-format', metavar='FORMAT', default="zfs_autobackup:{}",
|
||||||
|
help='ZFS hold string format. Default: %(default)s')
|
||||||
|
|
||||||
|
|
||||||
group=parser.add_argument_group("Selection options")
|
group=parser.add_argument_group("Selection options")
|
||||||
group.add_argument('--ignore-replicated', action='store_true', help=argparse.SUPPRESS)
|
group.add_argument('--ignore-replicated', action='store_true', help=argparse.SUPPRESS)
|
||||||
group.add_argument('--exclude-unchanged', action='store_true',
|
group.add_argument('--exclude-unchanged', action='store_true',
|
||||||
@ -123,8 +150,6 @@ class ZfsAuto(object):
|
|||||||
group.add_argument('--exclude-received', action='store_true',
|
group.add_argument('--exclude-received', action='store_true',
|
||||||
help='Exclude datasets that have the origin of their autobackup: property as "received". '
|
help='Exclude datasets that have the origin of their autobackup: property as "received". '
|
||||||
'This can avoid recursive replication between two backup partners.')
|
'This can avoid recursive replication between two backup partners.')
|
||||||
group.add_argument('--property-format', metavar='FORMAT', default="autobackup:{}",
|
|
||||||
help='Dataset selection string format. Default: %(default)s')
|
|
||||||
|
|
||||||
return (parser)
|
return (parser)
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ from .ThinnerRule import ThinnerRule
|
|||||||
class ZfsAutobackup(ZfsAuto):
|
class ZfsAutobackup(ZfsAuto):
|
||||||
"""The main zfs-autobackup class. Start here, at run() :)"""
|
"""The main zfs-autobackup class. Start here, at run() :)"""
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, argv, print_arguments=True):
|
def __init__(self, argv, print_arguments=True):
|
||||||
|
|
||||||
# NOTE: common options and parameters are in ZfsAuto
|
# NOTE: common options and parameters are in ZfsAuto
|
||||||
@ -65,8 +64,6 @@ class ZfsAutobackup(ZfsAuto):
|
|||||||
help='If nothing has changed, still create empty snapshots. (Faster. Same as --min-change=0)')
|
help='If nothing has changed, still create empty snapshots. (Faster. Same as --min-change=0)')
|
||||||
group.add_argument('--other-snapshots', action='store_true',
|
group.add_argument('--other-snapshots', action='store_true',
|
||||||
help='Send over other snapshots as well, not just the ones created by this tool.')
|
help='Send over other snapshots as well, not just the ones created by this tool.')
|
||||||
group.add_argument('--snapshot-format', metavar='FORMAT', default="{}-%Y%m%d%H%M%S",
|
|
||||||
help='ZFS Snapshot string format. Default: %(default)s')
|
|
||||||
|
|
||||||
group = parser.add_argument_group("Transfer options")
|
group = parser.add_argument_group("Transfer options")
|
||||||
group.add_argument('--no-send', action='store_true',
|
group.add_argument('--no-send', action='store_true',
|
||||||
@ -104,10 +101,6 @@ class ZfsAutobackup(ZfsAuto):
|
|||||||
|
|
||||||
group.add_argument('--zfs-compressed', action='store_true',
|
group.add_argument('--zfs-compressed', action='store_true',
|
||||||
help='Transfer blocks that already have zfs-compression as-is.')
|
help='Transfer blocks that already have zfs-compression as-is.')
|
||||||
group.add_argument('--hold-format', metavar='FORMAT', default="zfs_autobackup:{}",
|
|
||||||
help='ZFS hold string format. Default: %(default)s')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
group = parser.add_argument_group("ZFS send/recv pipes")
|
group = parser.add_argument_group("ZFS send/recv pipes")
|
||||||
group.add_argument('--compress', metavar='TYPE', default=None, nargs='?', const='zstd-fast',
|
group.add_argument('--compress', metavar='TYPE', default=None, nargs='?', const='zstd-fast',
|
||||||
@ -123,7 +116,6 @@ class ZfsAutobackup(ZfsAuto):
|
|||||||
group.add_argument('--recv-pipe', metavar="COMMAND", default=[], action='append',
|
group.add_argument('--recv-pipe', metavar="COMMAND", default=[], action='append',
|
||||||
help='pipe zfs recv input through COMMAND (can be used multiple times)')
|
help='pipe zfs recv input through COMMAND (can be used multiple times)')
|
||||||
|
|
||||||
|
|
||||||
group = parser.add_argument_group("Thinner options")
|
group = parser.add_argument_group("Thinner options")
|
||||||
group.add_argument('--no-thinning', action='store_true', help="Do not destroy any snapshots.")
|
group.add_argument('--no-thinning', action='store_true', help="Do not destroy any snapshots.")
|
||||||
group.add_argument('--keep-source', metavar='SCHEDULE', type=str, default="10,1d1w,1w1m,1m1y",
|
group.add_argument('--keep-source', metavar='SCHEDULE', type=str, default="10,1d1w,1w1m,1m1y",
|
||||||
@ -134,15 +126,11 @@ class ZfsAutobackup(ZfsAuto):
|
|||||||
help='Destroy datasets on target that are missing on the source. Specify the time since '
|
help='Destroy datasets on target that are missing on the source. Specify the time since '
|
||||||
'the last snapshot, e.g: --destroy-missing 30d')
|
'the last snapshot, e.g: --destroy-missing 30d')
|
||||||
|
|
||||||
|
|
||||||
# obsolete
|
# obsolete
|
||||||
parser.add_argument('--resume', action='store_true', help=argparse.SUPPRESS)
|
parser.add_argument('--resume', action='store_true', help=argparse.SUPPRESS)
|
||||||
parser.add_argument('--raw', action='store_true', help=argparse.SUPPRESS)
|
parser.add_argument('--raw', action='store_true', help=argparse.SUPPRESS)
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
return (parser)
|
|
||||||
|
|
||||||
def progress(self, txt):
|
def progress(self, txt):
|
||||||
self.log.progress(txt)
|
self.log.progress(txt)
|
||||||
@ -397,22 +385,6 @@ class ZfsAutobackup(ZfsAuto):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
if self.args.test:
|
|
||||||
self.warning("TEST MODE - SIMULATING WITHOUT MAKING ANY CHANGES")
|
|
||||||
|
|
||||||
#format all the names
|
|
||||||
property_name = self.args.property_format.format(self.args.backup_name)
|
|
||||||
snapshot_time_format = self.args.snapshot_format.format(self.args.backup_name)
|
|
||||||
hold_name = self.args.hold_format.format(self.args.backup_name)
|
|
||||||
|
|
||||||
self.verbose("")
|
|
||||||
self.verbose("Selecting dataset property : {}".format(property_name))
|
|
||||||
self.verbose("Snapshot format : {}".format(snapshot_time_format))
|
|
||||||
|
|
||||||
if not self.args.no_holds:
|
|
||||||
self.verbose("Hold name : {}".format(hold_name))
|
|
||||||
|
|
||||||
|
|
||||||
################ create source zfsNode
|
################ create source zfsNode
|
||||||
self.set_title("Source settings")
|
self.set_title("Source settings")
|
||||||
|
|
||||||
@ -421,15 +393,16 @@ class ZfsAutobackup(ZfsAuto):
|
|||||||
source_thinner = None
|
source_thinner = None
|
||||||
else:
|
else:
|
||||||
source_thinner = Thinner(self.args.keep_source)
|
source_thinner = Thinner(self.args.keep_source)
|
||||||
source_node = ZfsNode(snapshot_time_format=snapshot_time_format, hold_name=hold_name, logger=self, ssh_config=self.args.ssh_config,
|
source_node = ZfsNode(snapshot_time_format=self.snapshot_time_format, hold_name=self.hold_name, logger=self,
|
||||||
|
ssh_config=self.args.ssh_config,
|
||||||
ssh_to=self.args.ssh_source, readonly=self.args.test,
|
ssh_to=self.args.ssh_source, readonly=self.args.test,
|
||||||
debug_output=self.args.debug_output, description=description, thinner=source_thinner)
|
debug_output=self.args.debug_output, description=description, thinner=source_thinner)
|
||||||
|
|
||||||
|
|
||||||
################# select source datasets
|
################# select source datasets
|
||||||
self.set_title("Selecting")
|
self.set_title("Selecting")
|
||||||
source_datasets = source_node.selected_datasets(property_name=property_name,exclude_received=self.args.exclude_received,
|
source_datasets = source_node.selected_datasets(property_name=self.property_name,
|
||||||
exclude_paths=self.args.exclude_paths,
|
exclude_received=self.args.exclude_received,
|
||||||
|
exclude_paths=self.exclude_paths,
|
||||||
exclude_unchanged=self.args.exclude_unchanged,
|
exclude_unchanged=self.args.exclude_unchanged,
|
||||||
min_change=self.args.min_change)
|
min_change=self.args.min_change)
|
||||||
if not source_datasets:
|
if not source_datasets:
|
||||||
@ -442,7 +415,7 @@ class ZfsAutobackup(ZfsAuto):
|
|||||||
################# snapshotting
|
################# snapshotting
|
||||||
if not self.args.no_snapshot:
|
if not self.args.no_snapshot:
|
||||||
self.set_title("Snapshotting")
|
self.set_title("Snapshotting")
|
||||||
snapshot_name=time.strftime(snapshot_time_format)
|
snapshot_name = time.strftime(self.snapshot_time_format)
|
||||||
source_node.consistent_snapshot(source_datasets, snapshot_name,
|
source_node.consistent_snapshot(source_datasets, snapshot_name,
|
||||||
min_changed_bytes=self.args.min_change,
|
min_changed_bytes=self.args.min_change,
|
||||||
pre_snapshot_cmds=self.args.pre_snapshot_cmd,
|
pre_snapshot_cmds=self.args.pre_snapshot_cmd,
|
||||||
@ -458,7 +431,8 @@ class ZfsAutobackup(ZfsAuto):
|
|||||||
target_thinner = None
|
target_thinner = None
|
||||||
else:
|
else:
|
||||||
target_thinner = Thinner(self.args.keep_target)
|
target_thinner = Thinner(self.args.keep_target)
|
||||||
target_node = ZfsNode(snapshot_time_format=snapshot_time_format, hold_name=hold_name, logger=self, ssh_config=self.args.ssh_config,
|
target_node = ZfsNode(snapshot_time_format=self.snapshot_time_format, hold_name=self.hold_name,
|
||||||
|
logger=self, ssh_config=self.args.ssh_config,
|
||||||
ssh_to=self.args.ssh_target,
|
ssh_to=self.args.ssh_target,
|
||||||
readonly=self.args.test, debug_output=self.args.debug_output,
|
readonly=self.args.test, debug_output=self.args.debug_output,
|
||||||
description="[Target]",
|
description="[Target]",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user