Skip to content

Commit

Permalink
Added -F (--force) to allow 1:1 replication.
Browse files Browse the repository at this point in the history
  • Loading branch information
psy0rz committed Feb 23, 2022
1 parent cab2f98 commit e4356cb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
6 changes: 4 additions & 2 deletions zfs_autobackup/ZfsAutobackup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class ZfsAutobackup:
"""main class"""

VERSION = "3.1.2-rc1"
VERSION = "3.1.2-rc2"
HEADER = "zfs-autobackup v{} - (c)2021 E.H.Eefting (edwin@datux.nl)".format(VERSION)

def __init__(self, argv, print_arguments=True):
Expand Down Expand Up @@ -87,6 +87,8 @@ def __init__(self, argv, print_arguments=True):
parser.add_argument('--rollback', action='store_true',
help='Rollback changes to the latest target snapshot before starting. (normally you can '
'prevent changes by setting the readonly property on the target_path to on)')
parser.add_argument('--force', '-F', action='store_true',
help='Use zfs -F option to force overwrite/rollback. (Usefull with --strip-path=1, but use with care)')
parser.add_argument('--destroy-incompatible', action='store_true',
help='Destroy incompatible snapshots on target. Use with care! (implies --rollback)')
parser.add_argument('--destroy-missing', metavar="SCHEDULE", type=str, default=None,
Expand Down Expand Up @@ -438,7 +440,7 @@ def sync_datasets(self, source_node, source_datasets, target_node):
destroy_incompatible=self.args.destroy_incompatible,
send_pipes=send_pipes, recv_pipes=recv_pipes,
decrypt=self.args.decrypt, encrypt=self.args.encrypt,
zfs_compressed=self.args.zfs_compressed)
zfs_compressed=self.args.zfs_compressed, force=self.args.force)
except Exception as e:
fail_count = fail_count + 1
source_dataset.error("FAILED: " + str(e))
Expand Down
15 changes: 10 additions & 5 deletions zfs_autobackup/ZfsDataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ def send_pipe(self, features, prev_snapshot, resume_token, show_progress, raw, s

return output_pipe

def recv_pipe(self, pipe, features, recv_pipes, filter_properties=None, set_properties=None, ignore_exit_code=False):
def recv_pipe(self, pipe, features, recv_pipes, filter_properties=None, set_properties=None, ignore_exit_code=False, force=False):
"""starts a zfs recv for this snapshot and uses pipe as input
note: you can it both on a snapshot or filesystem object. The
Expand Down Expand Up @@ -626,6 +626,9 @@ def recv_pipe(self, pipe, features, recv_pipes, filter_properties=None, set_prop
# verbose output
cmd.append("-v")

if force:
cmd.append("-F")

if 'extensible_dataset' in features and "-s" in self.zfs_node.supported_recv_options:
# support resuming
self.debug("Enabled resume support")
Expand Down Expand Up @@ -656,7 +659,7 @@ def recv_pipe(self, pipe, features, recv_pipes, filter_properties=None, set_prop

def transfer_snapshot(self, target_snapshot, features, prev_snapshot, show_progress,
filter_properties, set_properties, ignore_recv_exit_code, resume_token,
raw, send_properties, write_embedded, send_pipes, recv_pipes, zfs_compressed):
raw, send_properties, write_embedded, send_pipes, recv_pipes, zfs_compressed, force):
"""transfer this snapshot to target_snapshot. specify prev_snapshot for
incremental transfer
Expand Down Expand Up @@ -697,7 +700,7 @@ def transfer_snapshot(self, target_snapshot, features, prev_snapshot, show_progr
pipe = self.send_pipe(features=features, show_progress=show_progress, prev_snapshot=prev_snapshot,
resume_token=resume_token, raw=raw, send_properties=send_properties, write_embedded=write_embedded, send_pipes=send_pipes, zfs_compressed=zfs_compressed)
target_snapshot.recv_pipe(pipe, features=features, filter_properties=filter_properties,
set_properties=set_properties, ignore_exit_code=ignore_recv_exit_code, recv_pipes=recv_pipes)
set_properties=set_properties, ignore_exit_code=ignore_recv_exit_code, recv_pipes=recv_pipes, force=force)

def abort_resume(self):
"""abort current resume state"""
Expand Down Expand Up @@ -994,7 +997,7 @@ def handle_incompatible_snapshots(self, incompatible_target_snapshots, destroy_i

def sync_snapshots(self, target_dataset, features, show_progress, filter_properties, set_properties,
ignore_recv_exit_code, holds, rollback, decrypt, encrypt, also_other_snapshots,
no_send, destroy_incompatible, send_pipes, recv_pipes, zfs_compressed):
no_send, destroy_incompatible, send_pipes, recv_pipes, zfs_compressed, force):
"""sync this dataset's snapshots to target_dataset, while also thinning
out old snapshots along the way.
Expand Down Expand Up @@ -1079,7 +1082,9 @@ def sync_snapshots(self, target_dataset, features, show_progress, filter_propert
filter_properties=active_filter_properties,
set_properties=active_set_properties,
ignore_recv_exit_code=ignore_recv_exit_code,
resume_token=resume_token, write_embedded=write_embedded, raw=raw, send_properties=send_properties, send_pipes=send_pipes, recv_pipes=recv_pipes, zfs_compressed=zfs_compressed)
resume_token=resume_token, write_embedded=write_embedded, raw=raw,
send_properties=send_properties, send_pipes=send_pipes,
recv_pipes=recv_pipes, zfs_compressed=zfs_compressed, force=force)

resume_token = None

Expand Down

0 comments on commit e4356cb

Please sign in to comment.