Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --snapshot-property argument to pass to zfs snapshot #146

Merged
merged 3 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion zfs_autobackup/ZfsAutobackup.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def get_parser(self):
help='If nothing has changed, still create empty snapshots. (Faster. Same as --min-change=0)')
group.add_argument('--other-snapshots', action='store_true',
help='Send over other snapshots as well, not just the ones created by this tool.')
group.add_argument('--set-snapshot-properties', metavar='PROPERTY=VALUE,...', type=str,
help='List of properties to set on the snapshot.')


group = parser.add_argument_group("Transfer options")
group.add_argument('--no-send', action='store_true',
Expand Down Expand Up @@ -382,6 +385,15 @@ def set_properties_list(self):

return set_properties

def set_snapshot_properties_list(self):

if self.args.set_snapshot_properties:
set_snapshot_properties = self.args.set_snapshot_properties.split(",")
else:
set_snapshot_properties = []

return set_snapshot_properties

def run(self):

try:
Expand Down Expand Up @@ -417,7 +429,8 @@ def run(self):
source_node.consistent_snapshot(source_datasets, snapshot_name,
min_changed_bytes=self.args.min_change,
pre_snapshot_cmds=self.args.pre_snapshot_cmd,
post_snapshot_cmds=self.args.post_snapshot_cmd)
post_snapshot_cmds=self.args.post_snapshot_cmd,
set_snapshot_properties=self.set_snapshot_properties_list())

################# sync
# if target is specified, we sync the datasets, otherwise we just thin the source. (e.g. snapshot mode)
Expand Down
4 changes: 3 additions & 1 deletion zfs_autobackup/ZfsNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def debug(self, txt):
self.logger.debug("{} {}".format(self.description, txt))

def consistent_snapshot(self, datasets, snapshot_name, min_changed_bytes, pre_snapshot_cmds=[],
post_snapshot_cmds=[]):
post_snapshot_cmds=[], set_snapshot_properties=[]):
"""create a consistent (atomic) snapshot of specified datasets, per pool.
"""

Expand Down Expand Up @@ -212,6 +212,8 @@ def consistent_snapshot(self, datasets, snapshot_name, min_changed_bytes, pre_sn
# create consistent snapshot per pool
for (pool_name, snapshots) in pools.items():
cmd = ["zfs", "snapshot"]
for snapshot_property in set_snapshot_properties:
cmd += ['-o', snapshot_property]

cmd.extend(map(lambda snapshot_: str(snapshot_), snapshots))

Expand Down