# HG changeset patch # User Franz Glasner # Date 1695144929 -7200 # Node ID a571a30bcf8aebc3a6e5168f2666f2af272a9ad9 # Parent bf0d63c8e682e8c245932afe28f0504f5c3faba9 Begin the implementation of "fzfs copy-tree" diff -r bf0d63c8e682 -r a571a30bcf8a docs/man/man8/fzfs-copy-tree.rst --- a/docs/man/man8/fzfs-copy-tree.rst Mon Sep 18 09:43:12 2023 +0200 +++ b/docs/man/man8/fzfs-copy-tree.rst Tue Sep 19 19:35:29 2023 +0200 @@ -9,20 +9,21 @@ Synopsis -------- -**fzfs copy-tree** [**-A**] [**-M** `mountpoint`] [**-n**] [**-p**] [**-u**] `source-dataset` `dest-dataset` +**fzfs copy-tree** [**-A**] [**-M** `mountpoint`] [**-n**] [**-u**] `source-dataset` `dest-dataset` + Description ----------- -Copy the ZFS filesystem structure and contents that is rooted at -`source-dataset` to the destination rooted at `dest-dataset`. +Copy the ZFS filesystem or snapshot that is rooted at `source-dataset` +and all descendent datasets to the destination rooted at `dest-dataset`. -The content of the filesystems is copied also. +The structure and content of the filesystems is copied. `dest-dataset` must not exist already. By default `canmount` is also copied. But this can be modified with -options :option:`-A` and :option:`-p`. +option :option:`-A`. Options @@ -44,12 +45,6 @@ Dry-run. Do not really create and copy datasets but show what would be done. -.. option:: -p - - Copy the `canmount` property only from the source to the root - destination dataset This will be overwritten by the option - :option:`-A`. - .. option:: -u Do not mount the copied datasets. diff -r bf0d63c8e682 -r a571a30bcf8a sbin/fzfs --- a/sbin/fzfs Mon Sep 18 09:43:12 2023 +0200 +++ b/sbin/fzfs Tue Sep 19 19:35:29 2023 +0200 @@ -28,6 +28,8 @@ COMMANDS: + copy-tree [-A] [-M MOUNTPOINT] [-n] [-u] SOURCE-DATASET DEST-DATASET + create-tree [-A] [-M MOUNTPOINT] [-n] [-p] [-u] SOURCE-DATASET DEST-DATASET mount [-O] [-N] [-P] [-u] [-n] DATASET [MOUNTPOINT] @@ -250,6 +252,53 @@ #: +#: Implementation of "copy-tree" +#: +command_copy_tree() { + local _ds_source _ds_target + local _opt_mountpoint _opt_mount_noauto _opt_nomount _opt_dry_run + + local _ds_source_base _ds_source_snapshot + + while getopts "AM:nu" _opt ; do + case ${_opt} in + A) + _opt_mount_noauto="-o canmount=noauto" + ;; + M) + _opt_mountpoint="${OPTARG}" + ;; + n) + _opt_dry_run="-n" + ;; + u) + _opt_nomount="-u" + ;; + \?) + return 2; + ;; + esac + done + shift $((OPTID-1)) + OPTIND=1 + + _ds_source="${1-}" + _ds_target="${2-}" + + [ -z "${_ds_source}" ] && { echo "ERROR: no source given" 1>&2; return 2; } + [ -z "${_snapshot_name}" ] && { echo "ERROR: no snapshot name given" 1>&2; return 2; } + + _ds_source_base="${_ds_source%@*}" + _ds_source_snapshot="${_ds_source##*@}" + + if [ "${_ds_source_snapshot}" = "${_ds_source_base}" ]; then + # No snapshot given + _ds_source_snapshot="" + fi +} + + +#: #: Implement the "create-tree" command #: #: Create a ZFS dataset tree from a source tree tree including important properties @@ -411,6 +460,9 @@ umount|unmount) command_umount "$@" ;; + copy-tree) + command_copy_tree "$@" + ;; create-tree) command_create_tree "$@" ;;