changeset 421:a571a30bcf8a

Begin the implementation of "fzfs copy-tree"
author Franz Glasner <hg@dom66.de>
date Tue, 19 Sep 2023 19:35:29 +0200
parents bf0d63c8e682
children 4363929b0a3e
files docs/man/man8/fzfs-copy-tree.rst sbin/fzfs
diffstat 2 files changed, 58 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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.
--- 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 "$@"
         ;;