Allow multiple --pre/post-snapshot-cmd options. Add a usage example.

This commit is contained in:
Phil Krylov
2021-06-16 23:19:29 +03:00
parent ec9459c1d2
commit 55ff14f1d8
3 changed files with 31 additions and 11 deletions

View File

@ -45,10 +45,10 @@ class ZfsAutobackup:
help='Target ZFS filesystem (optional: if not specified, zfs-autobackup will only operate '
'as snapshot-tool on source)')
parser.add_argument('--pre-snapshot-cmd', metavar="COMMAND", type=str,
help='Run COMMAND before snapshotting.')
parser.add_argument('--post-snapshot-cmd', metavar="COMMAND", type=str,
help='Run COMMAND after snapshotting.')
parser.add_argument('--pre-snapshot-cmd', metavar="COMMAND", default=[], action='append',
help='Run COMMAND before snapshotting (can be used multiple times.')
parser.add_argument('--post-snapshot-cmd', metavar="COMMAND", default=[], action='append',
help='Run COMMAND after snapshotting (can be used multiple times.')
parser.add_argument('--other-snapshots', action='store_true',
help='Send over other snapshots as well, not just the ones created by this tool.')
parser.add_argument('--no-snapshot', action='store_true',

View File

@ -192,9 +192,9 @@ class ZfsNode(ExecuteNode):
self.verbose("No changes anywhere: not creating snapshots.")
return
if pre_snapshot_cmd:
self.verbose("Running pre-snapshot-cmd:\n\t{}".format(pre_snapshot_cmd))
self.run(cmd=shlex.split(pre_snapshot_cmd), readonly=False)
for cmd in pre_snapshot_cmd:
self.verbose("Running pre-snapshot-cmd")
self.run(cmd=shlex.split(cmd), readonly=False)
# create consistent snapshot per pool
for (pool_name, snapshots) in pools.items():
@ -205,9 +205,9 @@ class ZfsNode(ExecuteNode):
self.verbose("Creating snapshots {} in pool {}".format(snapshot_name, pool_name))
self.run(cmd, readonly=False)
if post_snapshot_cmd:
self.verbose("Running post-snapshot-cmd:\n\t{}".format(post_snapshot_cmd))
self.run(cmd=shlex.split(post_snapshot_cmd), readonly=False)
for cmd in post_snapshot_cmd:
self.verbose("Running post-snapshot-cmd")
self.run(cmd=shlex.split(cmd), readonly=False)
def selected_datasets(self, exclude_received, exclude_paths):
"""determine filesystems that should be backupped by looking at the special autobackup-property, systemwide