diff sbin/fzfs @ 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 bb0a0384b5da
children 4363929b0a3e
line wrap: on
line diff
--- 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 "$@"
         ;;