annotate sbin/fzfs @ 520:7d08fd78775c

fzfs: implement "fzfs clone-tree". Clone a ZFS dataset tree and preserve locally set properties.
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 01 Sep 2024 21:34:27 +0200
parents 7d498093d4c2
children c05ef1c86c9c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1 #!/bin/sh
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2 # -*- indent-tabs-mode: nil; -*-
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
3 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
4 #: A ZFS management helper tool.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
5 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
6 #: :Author: Franz Glasner
438
9c3b1966ba91 Extend copyright to 2024
Franz Glasner <fzglas.hg@dom66.de>
parents: 429
diff changeset
7 #: :Copyright: (c) 2022-2024 Franz Glasner.
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
8 #: All rights reserved.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
9 #: :License: BSD 3-Clause "New" or "Revised" License.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
10 #: See LICENSE for details.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
11 #: If you cannot find LICENSE see
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
12 #: <https://opensource.org/licenses/BSD-3-Clause>
386
84d2735fe7f6 Simplified version tagging a lot: it is also faster now.
Franz Glasner <fzglas.hg@dom66.de>
parents: 380
diff changeset
13 #: :ID: @(#)@@SIMPLEVERSIONTAG@@
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
14 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
15
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
16 set -eu
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
17
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
18 VERSION="@@VERSION@@"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
19
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
20 USAGE='
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
21 USAGE: fzfs [ OPTIONS ] COMMAND [ COMMAND OPTIONS ] [ ARG ... ]
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
22
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
23 OPTIONS:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
24
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
25 -V Print the program name and version number to stdout and exit
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
26
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
27 -h Print this help message to stdout and exit
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
28
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
29 COMMANDS:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
30
520
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
31 clone-tree [-n] SOUECE-DATASET DEST-DATASET
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
32
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
33 copy-tree [-A] [-M MOUNTPOINT] [-n] [-u] SOURCE-DATASET DEST-DATASET
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
34
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
35 create-tree [-A] [-M MOUNTPOINT] [-n] [-p] [-u] SOURCE-DATASET DEST-DATASET
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
36
283
1fc3b04b39fa Build and package manual pages for fzfs, fzfs-mount and fzfs-umount.
Franz Glasner <fzglas.hg@dom66.de>
parents: 276
diff changeset
37 mount [-O] [-N] [-P] [-u] [-n] DATASET [MOUNTPOINT]
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
38
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
39 umount DATASET
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
40
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
41 unmount
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
42
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
43 '
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
44
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
45
442
a2011285f054 Move "_get_local_zfs_properties_for_create()" into common.subr
Franz Glasner <fzglas.hg@dom66.de>
parents: 441
diff changeset
46 _p_datadir="$(dirname "$0")"/../share/local-bsdtools
a2011285f054 Move "_get_local_zfs_properties_for_create()" into common.subr
Franz Glasner <fzglas.hg@dom66.de>
parents: 441
diff changeset
47 . "${_p_datadir}/common.subr"
500
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
48 . "${_p_datadir}/array.sh"
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
49
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
50
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
51 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
52 #: Implementation of the "mount" command.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
53 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
54 #: Mount a dataset and recursively all its children datasets.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
55 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
56 command_mount() {
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
57 local _dsname _mountpoint
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
58 local _opt_dry_run _opt_mount_outside _opt_mount_natural
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
59 local _opt_mount_children_only
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
60
492
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
61 local _name _mp _canmount _mounted _rootds_mountpoint _rootds_mountpoint_prefix _relative_mp _real_mp
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
62
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
63 _opt_dry_run=""
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
64 _opt_mount_outside=""
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
65 _opt_mount_natural=""
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
66 _opt_mount_children_only=""
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
67 while getopts "ONPnu" _opt ; do
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
68 case ${_opt} in
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
69 O)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
70 _opt_mount_outside="yes"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
71 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
72 N)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
73 _opt_mount_natural="yes"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
74 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
75 P)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
76 _opt_mount_children_only="yes"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
77 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
78 n|u)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
79 _opt_dry_run="yes"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
80 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
81 \?|:)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
82 return 2;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
83 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
84 esac
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
85 done
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
86 shift $((OPTIND-1))
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
87 OPTIND=1
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
88
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
89 _dsname="${1-}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
90 _mountpoint="${2-}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
91
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
92 if [ -z "${_dsname}" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
93 echo "ERROR: no dataset given" >&2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
94 return 2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
95 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
96
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
97 _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}")" || \
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
98 { echo "ERROR: root dataset does not exist" >&2; return 1; }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
99
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
100 if [ -z "${_mountpoint}" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
101 if [ "${_opt_mount_natural}" = "yes" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
102 _mountpoint="${_rootds_mountpoint}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
103 else
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
104 echo "ERROR: no mountpoint given" >&2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
105 return 2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
106 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
107 else
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
108 if [ "${_opt_mount_natural}" = "yes" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
109 echo "ERROR: Cannot have a custom mountpoint when \"-O\" is given" >&2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
110 return 2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
111 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
112 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
113
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
114 # Eventually remove a trailing slash
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
115 _mountpoint="${_mountpoint%/}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
116 if [ -z "${_mountpoint}" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
117 echo "ERROR: would mount over the root filesystem" >&2
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
118 return 1
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
119 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
120
492
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
121 if [ "${_rootds_mountpoint}" = "/" ]; then
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
122 _rootds_mountpoint_prefix="/"
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
123 else
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
124 _rootds_mountpoint_prefix="${_rootds_mountpoint}/"
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
125 fi
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
126
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
127 zfs list -H -o name,mountpoint,canmount,mounted -s mountpoint -t filesystem -r "${_dsname}" \
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
128 | {
500
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
129
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
130 #
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
131 # _mounted_datasets is an array of ZFS datasets that have been
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
132 # mounted by this routine and should be unmounted on errors
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
133 # -- if possible.
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
134 #
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
135 array_create _mounted_datasets
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
136
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
137 while IFS=$'\t' read -r _name _mp _canmount _mounted ; do
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
138 # Skip filesystems that are already mounted
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
139 [ "${_mounted}" = "yes" ] && continue
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
140 # Skip filesystems that must not be mounted
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
141 [ "${_canmount}" = "off" ] && continue
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
142 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
143 # Mount only the children and skip the given parent dataset
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
144 # if required
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
145 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
146 [ \( "${_opt_mount_children_only}" = "yes" \) -a \( "${_name}" = "${_dsname}" \) ] && continue
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
147 case "${_mp}" in
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
148 "none"|"legacy")
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
149 # Do nothing for filesystem with unset or legacy mountpoints
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
150 ;;
492
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
151 "${_rootds_mountpoint}"|"${_rootds_mountpoint_prefix}"*)
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
152 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
153 # Handle only mountpoints that have a mountpoint below
492
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
154 # or exactly at the parent datasets mountpoint
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
155 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
156
492
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
157 #
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
158 # Determine the mountpoint relative to the parent
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
159 # mountpoint. Extra effort is needed because the root
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
160 # filesystem mount is just a single slash.
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
161 #
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
162 if [ "${_mp}" = "${_rootds_mountpoint}" ]; then
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
163 if [ "${_name}" != "${_dsname}" ]; then
498
46406503a635 Typo in error message
Franz Glasner <fzglas.hg@dom66.de>
parents: 497
diff changeset
164 echo "ERROR: child dataset mounts over root dataset" >&2
500
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
165 _umount_datasets _mounted_datasets || true
492
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
166 return 1
500
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
167 fi
492
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
168 _relative_mp=""
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
169 _real_mp="${_mountpoint}"
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
170 else
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
171 _relative_mp="${_mp#${_rootds_mountpoint_prefix}}"
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
172 # Eventually remove a trailing slash
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
173 _relative_mp="${_relative_mp%/}"
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
174 if [ -z "${_relative_mp}" ]; then
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
175 echo "ERROR: got an empty relative mountpoint in child" >&2
500
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
176 _umount_datasets _mounted_datasets || true
492
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
177 return 1
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
178 fi
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
179 # The real effective full mountpoint
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
180 _real_mp="${_mountpoint}/${_relative_mp}"
312aebce590c FIX: Handle severe error in "fzfs mount" when the root dataset naturally mounts at root filesystem
Franz Glasner <fzglas.hg@dom66.de>
parents: 442
diff changeset
181 fi
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
182
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
183 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
184 # Consistency and sanity check: computed real mountpoint must
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
185 # be equal to the configured mountpoint when no custom mountpoint
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
186 # is given.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
187 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
188 if [ "${_opt_mount_natural}" = "yes" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
189 if [ "${_real_mp}" != "${_mp}" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
190 echo "ERROR: mountpoint mismatch" >&2
500
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
191 _umount_datasets _mounted_datasets || true
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
192 return 1
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
193 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
194 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
195
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
196 if [ "${_opt_dry_run}" = "yes" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
197 echo "Would mount ${_name} on ${_real_mp}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
198 else
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
199 mkdir -p "${_real_mp}" 1> /dev/null 2> /dev/null || \
500
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
200 { echo "ERROR: cannot create mountpoint ${_real_mp}" >&2; _umount_datasets _mounted_datasets || true; return 1; }
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
201 echo "Mounting ${_name} on ${_real_mp}"
500
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
202 if mount -t zfs "${_name}" "${_real_mp}"; then
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
203 array_append _mounted_datasets "${_name}"
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
204 else
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
205 _umount_datasets _mounted_datasets || true
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
206 return 1
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
207 fi
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
208 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
209 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
210 *)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
211 if [ "${_opt_mount_outside}" = "yes" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
212 if [ "${_opt_dry_run}" = "yes" ]; then
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
213 echo "Would mount ${_name} on configured ZFS dataset mountpoint ${_mp}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
214 else
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
215 echo "Mounting ${_name} on configured ZFS dataset mountpoint ${_mp}"
500
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
216 if zfs mount "${_name}"; then
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
217 array_append _mounted_datasets "${_name}"
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
218 else
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
219 _umount_datasets _mounted_datasets || true
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
220 return 1
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
221 fi
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
222 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
223 else
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
224 echo "Skipping ${_name} because its configured ZFS mountpoint is not relative to given root dataset" 2>&1
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
225 fi
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
226 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
227 esac
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
228 done
500
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
229 array_destroy _mounted_datasets
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
230 return 0
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
231 }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
232 }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
233
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
234
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
235 #:
500
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
236 #: Helper to unmount mounted ZFS filesystems
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
237 #:
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
238 #: Args:
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
239 #: $1 (str): The name of the array that contains the datasets to unmount to
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
240 #:
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
241 #: Returns:
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
242 #: 0 if successfully unmounted all given datasets,
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
243 #: 1 otherwise
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
244 #:
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
245 #: Unmounting is done in the reverse order.
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
246 #:
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
247 _umount_datasets() {
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
248 array_reversed_for_each "$1" _umount_datasets_umount
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
249 }
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
250
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
251
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
252 #:
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
253 #: Array callback to unmount a single ZFS filesystem
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
254 #:
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
255 _umount_datasets_umount() {
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
256 if ! zfs umount "$3" ; then
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
257 warn "Dataset \`${3}' cannot unmounted"
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
258 return 1
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
259 fi
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
260 return 0
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
261 }
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
262
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
263
7d498093d4c2 fzfs: Try to unmount filesystems that have been mounted by this tool when an error occurs
Franz Glasner <fzglas.hg@dom66.de>
parents: 498
diff changeset
264 #:
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
265 #: Implement the "umount" command.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
266 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
267 #: Umount a datasets and recursively all its children datasets.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
268 #:
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
269 command_umount() {
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
270 local _dsname
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
271
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
272 local _name _mp _rest _rootds_mountpoint
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
273
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
274 _dsname="${1-}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
275 [ -z "${_dsname}" ] && { echo "ERROR: no dataset given" 1>&2; return 2; }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
277 # Just determine whether the given dataset name exists
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
278 _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}")" || { echo "ERROR: dataset not found" 1>&2; return 1; }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
279
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
280 mount -t zfs -p \
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
281 | grep -E "^${_dsname}(/|\s)" \
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
282 | sort -n -r \
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
283 | {
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
284 while IFS=' '$'\t' read -r _name _mp _rest ; do
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
285 echo "Umounting ${_name} on ${_mp}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
286 umount "${_mp}" || return 1
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
287 done
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
288 }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
289 return 0
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
290 }
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
291
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
292
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
293 #:
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
294 #: Implementation of "copy-tree"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
295 #:
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
296 command_copy_tree() {
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
297 local _ds_source _ds_target
429
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
298 local _opt_mountpoint _opt_mount_noauto _opt_nomount _opt_keep _opt_dry_run
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
299
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
300 local _ds_source_base _ds_source_snapshot _snapshot_suffix
426
2cd4777821fc More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 424
diff changeset
301 local _ds_tree _ds _ds_relname _ds_canmount
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
302 local _arg_canmount _arg_mp1 _arg_mp2
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
303
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
304 _opt_mountpoint=""
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
305 _opt_mount_noauto=""
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
306 _opt_nomount=""
429
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
307 _opt_keep=""
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
308 _opt_dry_run=""
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
309
429
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
310 while getopts "AM:knu" _opt ; do
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
311 case ${_opt} in
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
312 A)
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
313 _opt_mount_noauto="-o canmount=noauto"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
314 ;;
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
315 M)
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
316 _opt_mountpoint="${OPTARG}"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
317 ;;
429
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
318 k)
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
319 _opt_keep="yes"
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
320 ;;
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
321 n)
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
322 _opt_dry_run="-n"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
323 ;;
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
324 u)
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
325 _opt_nomount="-u"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
326 ;;
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
327 \?)
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
328 return 2;
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
329 ;;
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
330 esac
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
331 done
422
4363929b0a3e FIX: Typo in variable name "OPTID" -> "OPTIND"
Franz Glasner <fzglas.hg@dom66.de>
parents: 421
diff changeset
332 shift $((OPTIND-1))
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
333 OPTIND=1
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
334
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
335 _ds_source="${1-}"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
336 _ds_target="${2-}"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
337
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
338 [ -z "${_ds_source}" ] && { echo "ERROR: no source given" 1>&2; return 2; }
423
1d6ee78f06ef FIX: Another typo in variable name (COPY-PASTE)
Franz Glasner <fzglas.hg@dom66.de>
parents: 422
diff changeset
339 [ -z "${_ds_target}" ] && { echo "ERROR: no target name given" 1>&2; return 2; }
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
340
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
341 if ! zfs get -H name "${_ds_source}" >/dev/null 2>&1; then
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
342 echo "ERROR: source dataset does not exist: ${_ds_source}" 1>&2;
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
343 return 1;
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
344 fi
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
345 if zfs get -H name "${_ds_target}" >/dev/null 2>&1; then
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
346 echo "ERROR: target dataset already exists: ${_ds_target}" 1>&2;
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
347 return 1;
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
348 fi
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
349
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
350 _ds_source_base="${_ds_source%@*}"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
351 _ds_source_snapshot="${_ds_source##*@}"
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
352 _snapshot_suffix="@${_ds_source_snapshot}"
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
353
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
354 if [ "${_ds_source_snapshot}" = "${_ds_source_base}" ]; then
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
355 # No snapshot given
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
356 [ "${_ds_source_base}" = "${_ds_source}" ] || { echo "ERROR:" 1>&2; return 1; }
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
357 _ds_source_snapshot=""
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
358 _snapshot_suffix=""
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
359 fi
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
360
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
361 _ds_tree=""
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
362
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
363 while IFS=$'\n' read -r _ds; do
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
364 if [ -z "${_ds_tree}" ]; then
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
365 _ds_tree="${_ds}"
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
366 else
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
367 _ds_tree="${_ds_tree}"$'\n'"${_ds}"
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
368 fi
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
369 done <<EOF20ee7ea0781414fab8c305d3875d15e
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
370 $(zfs list -H -r -t filesystem -o name -s name "${_ds_source_base}")
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
371 EOF20ee7ea0781414fab8c305d3875d15e
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
372 # Check the existence of all intermediate datasets and their shapshots
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
373 IFS=$'\n'
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
374 for _ds in ${_ds_tree}; do
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
375 if ! zfs get -H name "${_ds}${_snapshot_suffix}" >/dev/null 2>&1; then
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
376 echo "ERROR: child dataset does not exist: ${_ds}${_snapshot_suffix}" 1>&2
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
377 return 1
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
378 fi
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
379 done
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
380 IFS=$'\n'
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
381 for _ds in ${_ds_tree}; do
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
382 # Reset IFS
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
383 IFS=$' \t\n'
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
384
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
385 # Determine the relative name of the dataset
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
386 _ds_relname="${_ds#${_ds_source_base}}"
426
2cd4777821fc More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 424
diff changeset
387
2cd4777821fc More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 424
diff changeset
388 _ds_canmount=$(zfs get -H -o value canmount "${_ds}")
2cd4777821fc More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 424
diff changeset
389
2cd4777821fc More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 424
diff changeset
390 if [ "${_ds_canmount}" = "off" ]; then
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
391 _arg_canmount="-o canmount=off"
426
2cd4777821fc More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 424
diff changeset
392 else
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
393 _arg_canmount="${_opt_mount_noauto}"
426
2cd4777821fc More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 424
diff changeset
394 fi
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
395
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
396 if [ -z "${_ds_relname}" ]; then
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
397 #
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
398 # Source root to target root
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
399 #
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
400 if [ -z "${_opt_mountpoint}" ]; then
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
401 _arg_mp1=-x
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
402 _arg_mp2=mountpoint
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
403 else
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
404 _arg_mp1=-o
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
405 _arg_mp2="mountpoint=${_opt_mountpoint}"
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
406 fi
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
407 else
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
408 _arg_mp1=-x
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
409 _arg_mp2=mountpoint
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
410 fi
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
411 if [ -z "${_opt_dry_run}" ]; then
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
412 zfs send -Lec -p -v "${_ds}${_snapshot_suffix}" | zfs receive -v ${_opt_nomount} ${_arg_canmount} ${_arg_mp1} "${_arg_mp2}" "${_ds_target}${_ds_relname}"
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
413 else
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
414 echo "Would execute: zfs send -Lec -p -v '${_ds}${_snapshot_suffix}' | zfs receive -v ${_opt_nomount} ${_arg_canmount} ${_arg_mp1} '${_arg_mp2}' '${_ds_target}${_ds_relname}'"
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
415 fi
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
416 # for the loop
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
417 IFS=$'\n'
424
a200c18603c9 Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents: 423
diff changeset
418 done
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
419 # Reset to default
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
420 IFS=$' \t\n'
429
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
421 # Remove received snapshots by default
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
422 if [ -n "${_ds_source_snapshot}" ]; then
429
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
423 if [ -z "${_opt_keep}" ]; then
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
424 if [ -z "${_opt_dry_run}" ]; then
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
425 zfs destroy -rv "${_ds_target}${_snapshot_suffix}"
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
426 else
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
427 echo "Would execute: zfs destroy -rv '${_ds_target}${_snapshot_suffix}'"
bbdb1ab0ea00 Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents: 428
diff changeset
428 fi
428
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
429 fi
824e88618376 The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents: 427
diff changeset
430 fi
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
431 }
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
432
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
433
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
434 #:
520
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
435 #: Implementation of "clone-tree"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
436 #:
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
437 command_clone_tree() {
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
438 local _ds_source _ds_dest
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
439 local _opt_dry_run
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
440
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
441 local _ds snapshot_name _ds_source_base _ds_relname
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
442 local _ds_canmount _ds_mountpoint
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
443 local _clone_props _arg_canmount _arg_other_clone_props
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
444 local _opt _idx _idx_lp _prop _propval
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
445
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
446 _opt_dry_run=""
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
447
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
448 while getopts "n" _opt ; do
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
449 case ${_opt} in
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
450 n)
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
451 _opt_dry_run="yes"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
452 ;;
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
453 \?|:)
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
454 return 2;
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
455 ;;
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
456 esac
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
457 done
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
458 shift $((OPTIND-1))
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
459 OPTIND=1
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
460
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
461 _ds_source="${1-}"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
462 _ds_dest="${2-}"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
463
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
464 [ -z "${_ds_source}" ] && { err "no source dataset/snapshot given"; return 2; }
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
465 [ -z "${_ds_dest}" ] && { err "no destination name given"; return 2; }
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
466
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
467 if ! zfs get -H name "${_ds_source}" >/dev/null 2>&1; then
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
468 err "source dataset does not exist: ${_ds_source}"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
469 return 1
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
470 fi
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
471 if zfs get -H name "${_ds_dest}" >/dev/null 2>&1; then
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
472 err "destination dataset already exists: ${_ds_dest}"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
473 return 1
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
474 fi
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
475
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
476 _ds_source_base="${_ds_source%@*}"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
477 _snapshot_name="${_ds_source##*@}"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
478
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
479 if [ "${_ds_source_base}" = "${_snapshot_name}" ]; then
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
480 err "no snapshot given"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
481 return 1
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
482 fi
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
483
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
484 array_create _ds_tree
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
485
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
486 while IFS=$'\n' read -r _ds; do
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
487 array_append _ds_tree "${_ds}"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
488 done <<EOF_9ef07253679011efa78174d435fd3892
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
489 $(zfs list -H -r -t filesystem -o name -s name "${_ds_source_base}")
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
490 EOF_9ef07253679011efa78174d435fd3892
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
491
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
492 # Check the existence of all intermediate datasets and their shapshots
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
493 _idx=1
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
494 while array_tryget _ds _ds_tree ${_idx}; do
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
495 if ! zfs get -H name "${_ds}@${_snapshot_name}" >/dev/null 2>&1; then
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
496 err "child dataset does not exist: ${_ds}@${_snapshot_name}" 1>&2
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
497 array_destroy _ds_tree
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
498 return 1
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
499 fi
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
500 _idx=$((${_idx} + 1))
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
501 done
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
502
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
503 array_create _cloned_datasets
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
504 alist_create _local_props
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
505
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
506 #
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
507 # 1. Clone with "safe" canmount settings
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
508 #
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
509
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
510 _idx=1
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
511 while array_tryget _ds _ds_tree ${_idx}; do
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
512 # Determine the relative name of the dataset
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
513 _ds_relname="${_ds#${_ds_source_base}}"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
514
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
515 # Need to determine in *every* case (local, default, received, ...)
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
516 _ds_canmount="$(zfs get -H -o value canmount "${_ds}")"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
517
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
518 alist_clear _local_props
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
519 while IFS=$'\t' read -r _prop _propval ; do
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
520 alist_set _local_props "${_prop}" "${_propval}"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
521 done <<EOF_ce8c76187f33471f8e8c1607ed09c42e
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
522 $(zfs get -H -o property,value -s local,received all "${_ds}")
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
523 EOF_ce8c76187f33471f8e8c1607ed09c42e
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
524
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
525 #
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
526 # - "zfs clone" does NOT copy/clone properties.
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
527 #
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
528 # Clones inherit their properties from the target filesystem
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
529 # context or are set back to their ZFS default.
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
530 #
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
531 if [ "${_ds_canmount}" = "off" ]; then
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
532 _arg_canmount="-o canmount=off"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
533 else
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
534 _arg_canmount="-o canmount=noauto"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
535 fi
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
536
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
537 # Copy all local props with the exception of canmount and mountpoint
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
538 _arg_other_clone_props=""
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
539 _idx_lp=1
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
540 while alist_tryget_key_at_index _prop _local_props ${_idx_lp}; do
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
541 if [ "${_prop}" = "mountpoint" ]; then
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
542 _idx_lp=$((${_idx_lp} + 1))
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
543 continue
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
544 fi
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
545 if [ "${_prop}" = "canmount" ]; then
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
546 _idx_lp=$((${_idx_lp} + 1))
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
547 continue
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
548 fi
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
549 alist_tryget_value_at_index _propvalue _local_props ${_idx_lp}
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
550 _arg_other_clone_props="${_arg_other_clone_props} -o ${_prop}=${_propvalue}"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
551 _idx_lp=$((${_idx_lp} + 1))
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
552 done
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
553
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
554 if ! checkyes _opt_dry_run; then
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
555 echo "Cloning ${_ds}@${_snapshot_name} into ${_ds_dest}${_ds_relname} with ${_arg_canmount} ${_arg_other_clone_props}"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
556 if zfs clone ${_arg_canmount} ${_arg_other_clone_props} "${_ds}@${_snapshot_name}" "${_ds_dest}${_ds_relname}"; then
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
557 array_append _cloned_datasets "${_ds_dest}${_ds_relname}"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
558 else
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
559 _destroy_datasets _cloned_datasets || true
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
560 return 1
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
561 fi
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
562 else
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
563 echo "Would execute: zfs clone ${_arg_canmount} ${_arg_other_clone_props} '${_ds}@${_snapshot_name}' '${_ds_dest}${_ds_relname}'"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
564 fi
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
565 _idx=$((${_idx} + 1))
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
566 done
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
567
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
568 #
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
569 # 2. Copy property mountpoint for root and inherit for all children;
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
570 # also handle canmount.
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
571 #
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
572 _idx=1
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
573 while array_tryget _ds _ds_tree ${_idx}; do
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
574 # Determine the relative name of the dataset
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
575 _ds_relname="${_ds#${_ds_source_base}}"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
576
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
577 # Need to determine in *every* case (default, local, received, ...)
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
578 _ds_canmount="$(zfs get -H -o value canmount "${_ds}")"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
579 # Local mountpoint
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
580 _ds_mountpoint="$(zfs get -H -o value -s local,received mountpoint "${_ds}")"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
581
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
582 if [ \( "${_ds_canmount}" = "off" \) -o \( "${_ds_canmount}" = "noauto" \) ]; then
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
583 #
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
584 # Already handled above because "nomount" is the default if not
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
585 # already set to "off".
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
586 #
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
587 _arg_canmount=""
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
588 else
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
589 _arg_canmount="-o canmount=${_ds_canmount}"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
590 fi
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
591
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
592 if [ \( -n "${_arg_canmount}" \) -o \( -n "${_ds_mountpoint}" \) ]; then
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
593 if ! checkyes _opt_dry_run; then
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
594 # If a local or received mountpoint is given set it here
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
595 if [ -n "${_ds_mountpoint}" ]; then
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
596 echo "Correcting properties for ${_ds_dest}${_ds_relname}: ${_arg_canmount} mountpoint=\"${_ds_mountpoint}\""
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
597 zfs set -u ${_arg_canmount} mountpoint="${_ds_mountpoint}" "${_ds_dest}${_ds_relname}" || true
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
598 else
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
599 echo "Correcting properties for ${_ds_dest}${_ds_relname}: ${_arg_canmount}"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
600 zfs set -u ${_arg_canmount} "${_ds_dest}${_ds_relname}" || true
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
601 fi
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
602 else
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
603 # If a local or received mountpoint is given set it here
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
604 if [ -n "${_ds_mountpoint}" ]; then
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
605 echo "Would execute: zfs set -u ${_arg_canmount} mountpoint='${_ds_mountpoint}' '${_ds_dest}${_ds_relname}'"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
606 else
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
607 echo "Would execute: zfs set -u ${_arg_canmount} '${_ds_dest}${_ds_relname}'"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
608 fi
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
609 fi
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
610 fi
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
611 _idx=$((${_idx} + 1))
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
612 done
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
613
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
614 return 0
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
615 }
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
616
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
617
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
618 #:
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
619 #: Implement the "create-tree" command
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
620 #:
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
621 #: Create a ZFS dataset tree from a source tree tree including important properties
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
622 #:
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
623 command_create_tree() {
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
624 local _source_ds _target_ds
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
625 local _opt_dry_run _opt_mountpoint _opt_noauto _opt_nomount _opt_canmount_parent_only
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
626
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
627 local _opt _source_name _snapshot_name _current_name _current_type _relative_name _zfs_opts _zfs_canmount _zfs_mountpoint
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
628
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
629 _opt_noauto=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
630 _opt_dry_run=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
631 _opt_mountpoint=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
632 _opt_nomount=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
633 _opt_canmount_parent_only=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
634
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
635 while getopts "AM:npu" _opt ; do
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
636 case ${_opt} in
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
637 A)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
638 _opt_noauto="-o canmount=noauto"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
639 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
640 M)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
641 _opt_mountpoint="${OPTARG}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
642 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
643 n)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
644 _opt_dry_run="yes"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
645 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
646 p)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
647 _opt_canmount_parent_only="yes"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
648 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
649 u)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
650 _opt_nomount="-u"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
651 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
652 \?|:)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
653 return 2;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
654 ;;
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
655 esac
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
656 done
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
657 shift $((OPTIND-1))
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
658 OPTIND=1
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
659
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
660 _source_ds="${1-}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
661 _target_ds="${2-}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
662
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
663 [ -z "${_source_ds}" ] && { echo "ERROR: no source dataset given" 1>&2; return 2; }
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
664 [ -z "${_target_ds}" ] && { echo "ERROR: no destination dataset given" 1>&2; return 2; }
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
665
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
666 _source_name="${_source_ds%@*}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
667 if [ "${_source_name}" != "${_source_ds}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
668 _snapshot_name="${_source_ds##*@}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
669 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
670 _snapshot_name=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
671 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
672
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
673 [ -n "${_snapshot_name}" ] && { echo "ERROR: No snapshot sources are supported yet" 1>&2; return 2; }
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
674
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
675 zfs list -H -r -t filesystem -o name,type "${_source_ds}" \
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
676 | {
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
677 while IFS=$'\t' read -r _current_name _current_type ; do
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
678 # Determine the relative name of the dataset
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
679 _relative_name="${_current_name#${_source_name}}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
680 _relative_name="${_relative_name%@*}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
681 if [ "${_current_type}" != "filesystem" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
682 echo "ERROR: Got a snapshot but expected a filesystem" 1>&2
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
683 return 1
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
684 fi
441
f06998866c01 Renamed local helper function
Franz Glasner <fzglas.hg@dom66.de>
parents: 438
diff changeset
685 _zfs_opts="$(_get_local_zfs_properties_for_create "${_current_name}" atime exec setuid compression primarycache sync readonly)"
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
686 if [ -z "${_relative_name}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
687 #
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
688 # Root
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
689 #
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
690 if [ -z "${_opt_noauto}" ]; then
441
f06998866c01 Renamed local helper function
Franz Glasner <fzglas.hg@dom66.de>
parents: 438
diff changeset
691 _zfs_canmount="$(_get_local_zfs_properties_for_create "${_current_name}" canmount)"
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
692 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
693 _zfs_canmount="${_opt_noauto}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
694 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
695 if [ -n "${_opt_mountpoint}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
696 _zfs_mountpoint="${_opt_mountpoint}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
697 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
698 _zfs_mountpoint=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
699 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
700
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
701 if [ "${_opt_dry_run}" = "yes" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
702 if [ -z "${_zfs_mountpoint}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
703 echo "Would call: zfs create ${_opt_nomount} ${_zfs_opts} ${_zfs_canmount} ${_target_ds}${_relative_name}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
704 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
705 echo "Would call: zfs create ${_opt_nomount} ${_zfs_opts} ${_zfs_canmount} -o mountpoint=${_zfs_mountpoint} ${_target_ds}${_relative_name}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
706 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
707 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
708 if [ -z "${_zfs_mountpoint}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
709 zfs create -v ${_opt_nomount} ${_zfs_opts} ${_zfs_canmount} "${_target_ds}${_relative_name}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
710 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
711 zfs create -v ${_opt_nomount} ${_zfs_opts} ${_zfs_canmount} -o "mountpoint=${_zfs_mountpoint}" "${_target_ds}${_relative_name}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
712 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
713 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
714 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
715 #
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
716 # Children
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
717 #
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
718 if [ -z "${_opt_noauto}" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
719 if [ "${_opt_canmount_parent_only}" = "yes" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
720 _zfs_canmount=""
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
721 else
441
f06998866c01 Renamed local helper function
Franz Glasner <fzglas.hg@dom66.de>
parents: 438
diff changeset
722 _zfs_canmount="$(_get_local_zfs_properties_for_create "${_current_name}" canmount)"
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
723 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
724 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
725 _zfs_canmount="${_opt_noauto}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
726 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
727 if [ "${_opt_dry_run}" = "yes" ]; then
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
728 echo "Would call: zfs create ${_opt_nomount} ${_zfs_opts} ${_zfs_canmount} ${_target_ds}${_relative_name}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
729 else
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
730 zfs create -v ${_opt_nomount} ${_zfs_opts} ${_zfs_canmount} "${_target_ds}${_relative_name}"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
731 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
732 fi
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
733 done
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
734 }
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
735 return 0
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
736 }
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
737
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
738
520
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
739 #:
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
740 #: Helper to destroy some created ZFS filesystems
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
741 #:
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
742 #: Args:
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
743 #: $1 (str): The name of the array that contains the datasets to destroy to
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
744 #:
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
745 #: Returns:
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
746 #: 0 if successfully destroyed all given datasets,
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
747 #: 1 otherwise
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
748 #:
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
749 #: Destruction is done in the reverse order.
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
750 #:
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
751 _destroy_datasets() {
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
752 array_reversed_for_each "$1" _destroy_datasets_destroy
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
753 }
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
754
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
755
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
756 #:
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
757 #: Array callback to destroy a single ZFS filesystem
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
758 #:
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
759 _destroy_datasets_destroy() {
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
760 if ! zfs destroy -v "$3" ; then
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
761 warn "Dataset \`${3}' cannot unmounted"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
762 return 1
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
763 fi
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
764 return 0
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
765 }
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
766
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
767
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
768 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
769 # Global option handling
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
770 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
771 while getopts "Vh" _opt ; do
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
772 case ${_opt} in
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
773 V)
408
bb0a0384b5da FIX: Program name in fzfs's version string
Franz Glasner <f.glasner@feldmann-mg.com>
parents: 386
diff changeset
774 printf 'fzfs %s\n' '@@SIMPLEVERSIONSTR@@'
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
775 exit 0
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
776 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
777 h)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
778 echo "${USAGE}"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
779 exit 0
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
780 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
781 \?)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
782 exit 2;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
783 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
784 *)
497
eb42828c0cbf Use the new output routinges for errors in fzfs' global error handling
Franz Glasner <fzglas.hg@dom66.de>
parents: 492
diff changeset
785 fatal 2 "option handling failed" 1>&2
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
786 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
787 esac
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
788 done
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
789 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
790 # Reset the Shell's option handling system to prepare for handling
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
791 # command-local options.
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
792 #
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
793 shift $((OPTIND-1))
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
794 OPTIND=1
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
795
497
eb42828c0cbf Use the new output routinges for errors in fzfs' global error handling
Franz Glasner <fzglas.hg@dom66.de>
parents: 492
diff changeset
796 test $# -gt 0 || fatal 2 "no command given"
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
797
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
798 command="$1"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
799 shift
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
800
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
801 case "${command}" in
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
802 mount)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
803 command_mount "$@"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
804 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
805 umount|unmount)
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
806 command_umount "$@"
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
807 ;;
520
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
808 clone-tree)
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
809 command_clone_tree "$@"
7d08fd78775c fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents: 500
diff changeset
810 ;;
421
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
811 copy-tree)
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
812 command_copy_tree "$@"
a571a30bcf8a Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents: 408
diff changeset
813 ;;
380
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
814 create-tree)
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
815 command_create_tree "$@"
6be930eb7490 Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents: 283
diff changeset
816 ;;
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
817 *)
497
eb42828c0cbf Use the new output routinges for errors in fzfs' global error handling
Franz Glasner <fzglas.hg@dom66.de>
parents: 492
diff changeset
818 fatal 2 "unknown command \`${command}'" 1>&2
276
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
819 ;;
3c24b07240f2 Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
820 esac