Skip to content

Commit

Permalink
refine --{include,exclude}-snapshot-regex semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
whoschek committed Jul 23, 2024
1 parent 6a9c221 commit 3bede35
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions wbackup_zfs/wbackup_zfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ def argument_parser() -> argparse.ArgumentParser:
f"is `{exclude_dataset_regexes_default}`"))
parser.add_argument(
'--include-snapshot-regex', action=FileOrLiteralAction, nargs='+', default=[], metavar='REGEX',
help=("During replication, include any ZFS snapshot that has a name (i.e. the part after the '@') that matches "
"at least one of the given include regular expressions but none of the exclude regular expressions. "
help=("During replication, include any source ZFS snapshot that has a name (i.e. the part after the '@') "
"that matches at least one of the given include regular expressions but none of the exclude regular "
"expressions. "
"This option can be specified multiple times. "
"A leading `!` character indicates logical negation, i.e. the regex matches if the regex with the "
"leading `!` character removed does not match. "
Expand All @@ -205,8 +206,8 @@ def argument_parser() -> argparse.ArgumentParser:
parser.add_argument(
'--force', action='store_true',
help=("Before replication, delete destination ZFS snapshots that are more recent than the most recent common "
"snapshot found on the source ('conflicting snapshots') and rollback the destination dataset "
"correspondingly before starting replication. Also, if no common snapshot is found then delete all "
"snapshot included on the source ('conflicting snapshots') and rollback the destination dataset "
"correspondingly before starting replication. Also, if no common snapshot is included then delete all "
"destination snapshots before starting replication. Without the --force flag, the destination dataset is "
"treated as append-only, hence no destination snapshot that already exists is deleted, and instead the "
"operation is aborted with an error when encountering a conflicting snapshot."))
Expand Down Expand Up @@ -692,7 +693,6 @@ def run_main_action(self):
dst_snapshots_with_guids = self.filter_snapshots(dst_snapshots_with_guids.splitlines())
cmd = p.split_args(f"{p.zfs_program} list -t snapshot -d 1 -s name -Hp -o guid,name", src_dataset)
src_snapshots_with_guids = self.run_ssh_command('src', self.trace, cmd=cmd).splitlines()
src_snapshots_with_guids = self.filter_snapshots(src_snapshots_with_guids)

missing_snapshot_guids = set(cut(field=1, lines=dst_snapshots_with_guids)).difference(
set(cut(1, lines=src_snapshots_with_guids)))
Expand Down Expand Up @@ -810,8 +810,7 @@ def replicate_flat_dataset(self, src_dataset: str, dst_dataset: str):
snapshot = snapshot.replace('#', '@', 1)
if bookmarks.get(snapshot) is None: # not yet seen?
bookmarks[snapshot] = bookmark
tab = '\t'
src_snapshots_with_guids.append(f"{guid}{tab}{snapshot}")
src_snapshots_with_guids.append(f"{guid}\t{snapshot}")
src_snapshots_and_bookmarks = None
has_snapshot = None
if not latest_src_snapshot and params.recursive:
Expand All @@ -826,10 +825,8 @@ def replicate_flat_dataset(self, src_dataset: str, dst_dataset: str):
latest_dst_snapshot = ""
latest_common_src_snapshot = ""
latest_common_dst_snapshot = ""
origin_dst_snapshots_with_guids = dst_snapshots_with_guids

if self.dst_dataset_exists[dst_dataset]:
dst_snapshots_with_guids = self.filter_snapshots(dst_snapshots_with_guids)
dst_snapshots = [line[line.index('\t') + 1:] for line in dst_snapshots_with_guids] # cut -f2-
latest_dst_snapshot = dst_snapshots[-1] if len(dst_snapshots) > 0 else ""
if latest_dst_snapshot != "" and params.force:
Expand Down Expand Up @@ -891,7 +888,7 @@ def replicate_flat_dataset(self, src_dataset: str, dst_dataset: str):
if self.is_solaris_zfs('dst'):
# solaris-11.4.0 has no wildcard syntax to delete all snapshots in a single CLI invocation
self.delete_snapshots(
dst_dataset, snapshot_tags=cut(2, separator='@', lines=origin_dst_snapshots_with_guids))
dst_dataset, snapshot_tags=cut(2, separator='@', lines=dst_snapshots_with_guids))
else:
cmd = p.split_args(
f"{p.dst_sudo} {p.zfs_program} destroy {p.force_hard} {p.verbose_destroy} {p.dry_run_destroy}",
Expand Down

0 comments on commit 3bede35

Please sign in to comment.