# HG changeset patch # User Franz Glasner # Date 1695367345 -7200 # Node ID bbdb1ab0ea00197fc66a0999e723f9e70d922f05 # Parent 824e886183760cf52d19cb94d3adb0ab8affe7de Implement "-k" option for "fzfs copy-tree" to keep received snapshots diff -r 824e88618376 -r bbdb1ab0ea00 docs/man/man8/fzfs-copy-tree.rst --- a/docs/man/man8/fzfs-copy-tree.rst Thu Sep 21 18:42:41 2023 +0200 +++ b/docs/man/man8/fzfs-copy-tree.rst Fri Sep 22 09:22:25 2023 +0200 @@ -9,7 +9,7 @@ Synopsis -------- -**fzfs copy-tree** [**-A**] [**-M** `mountpoint`] [**-n**] [**-u**] `source-dataset` `dest-dataset` +**fzfs copy-tree** [**-A**] [**-M** `mountpoint`] [**-k**] [**-n**] [**-u**] `source-dataset` `dest-dataset` Description @@ -43,6 +43,12 @@ Set the `mountpoint` property for the root `dest-dataset` to `mountpoint`. All children will be set to inherit it. +.. option:: -k + + When copying from a snapshot source a corresponding snapshot will be + copied to the target dataset. By default this snapshot will be + deleted. With this option this snapshot is kept. + .. option:: -n Dry-run. Do not really create and copy datasets but show what would diff -r 824e88618376 -r bbdb1ab0ea00 sbin/fzfs --- a/sbin/fzfs Thu Sep 21 18:42:41 2023 +0200 +++ b/sbin/fzfs Fri Sep 22 09:22:25 2023 +0200 @@ -256,7 +256,7 @@ #: command_copy_tree() { local _ds_source _ds_target - local _opt_mountpoint _opt_mount_noauto _opt_nomount _opt_dry_run + local _opt_mountpoint _opt_mount_noauto _opt_nomount _opt_keep _opt_dry_run local _ds_source_base _ds_source_snapshot _snapshot_suffix local _ds_tree _ds _ds_relname _ds_canmount @@ -265,9 +265,10 @@ _opt_mountpoint="" _opt_mount_noauto="" _opt_nomount="" + _opt_keep="" _opt_dry_run="" - while getopts "AM:nu" _opt ; do + while getopts "AM:knu" _opt ; do case ${_opt} in A) _opt_mount_noauto="-o canmount=noauto" @@ -275,6 +276,9 @@ M) _opt_mountpoint="${OPTARG}" ;; + k) + _opt_keep="yes" + ;; n) _opt_dry_run="-n" ;; @@ -375,12 +379,14 @@ done # Reset to default IFS=$' \t\n' - # Remove received snapshots + # Remove received snapshots by default if [ -n "${_ds_source_snapshot}" ]; then - if [ -z "${_opt_dry_run}" ]; then - zfs destroy -rv "${_ds_target}${_snapshot_suffix}" - else - echo "Would execute: zfs destroy -rv '${_ds_target}${_snapshot_suffix}'" + if [ -z "${_opt_keep}" ]; then + if [ -z "${_opt_dry_run}" ]; then + zfs destroy -rv "${_ds_target}${_snapshot_suffix}" + else + echo "Would execute: zfs destroy -rv '${_ds_target}${_snapshot_suffix}'" + fi fi fi }