Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
annotate sbin/fzfs @ 625:69d557d67842
fzfs: FIX: no numeric sort for fstab
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Tue, 24 Sep 2024 14:38:46 +0200 |
| parents | 721737ce1ea0 |
| children | 17209ce80536 |
| 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 |
|
550
847ae246f3cc
Make the port really DATADIR and EXAMPLESDIR safe because the user may redefine DATADIR and EXAMPLESDIR.
Franz Glasner <fzglas.hg@dom66.de>
parents:
546
diff
changeset
|
18 VERSION='@@VERSION@@' |
|
276
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 |
|
538
9f8f3e9b3d84
fzfs: FIX: typo in help msg
Franz Glasner <fzglas.hg@dom66.de>
parents:
537
diff
changeset
|
31 clone-tree [-k] [-n] SOURCE-DATASET DEST-DATASET |
|
520
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 |
|
521
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
37 mount [-O] [-N] [-P] [-k] [-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 |
|
528
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
39 umount [-k] DATASET |
|
276
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 |
|
550
847ae246f3cc
Make the port really DATADIR and EXAMPLESDIR safe because the user may redefine DATADIR and EXAMPLESDIR.
Franz Glasner <fzglas.hg@dom66.de>
parents:
546
diff
changeset
|
46 _p_datadir='@@DATADIR@@' |
|
847ae246f3cc
Make the port really DATADIR and EXAMPLESDIR safe because the user may redefine DATADIR and EXAMPLESDIR.
Franz Glasner <fzglas.hg@dom66.de>
parents:
546
diff
changeset
|
47 [ "${_p_datadir#@@DATADIR}" = '@@' ] && _p_datadir="$(dirname "$0")"/../share/local-bsdtools |
|
442
a2011285f054
Move "_get_local_zfs_properties_for_create()" into common.subr
Franz Glasner <fzglas.hg@dom66.de>
parents:
441
diff
changeset
|
48 . "${_p_datadir}/common.subr" |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
49 . "${_p_datadir}/farray.sh" |
|
380
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
50 |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
51 |
|
276
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
52 # |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
53 #: 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
|
54 #: |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
55 #: 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
|
56 #: |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
57 command_mount() { |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
58 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
|
59 local _opt_dry_run _opt_mount_outside _opt_mount_natural |
|
521
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
60 local _opt_mount_children_only _opt_keep |
|
276
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
61 |
|
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
|
62 local _name _mp _canmount _mounted _rootds_mountpoint _rootds_mountpoint_prefix _relative_mp _real_mp |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
63 local _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
|
64 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
65 _opt_dry_run="" |
|
521
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
66 _opt_keep="" |
|
276
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
67 _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
|
68 _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
|
69 _opt_mount_children_only="" |
|
521
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
70 while getopts "ONPknu" _opt ; do |
|
276
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
71 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
|
72 O) |
|
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_outside="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 N) |
|
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_natural="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 P) |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
79 _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
|
80 ;; |
|
521
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
81 k) |
|
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
82 _opt_keep="yes" |
|
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
83 ;; |
|
276
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
84 n|u) |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
85 _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
|
86 ;; |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
87 \?|:) |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
88 return 2; |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
89 ;; |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
90 esac |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
91 done |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
92 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
|
93 OPTIND=1 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
94 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
95 _dsname="${1-}" |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
96 _mountpoint="${2-}" |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
97 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
98 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
|
99 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
|
100 return 2 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
101 fi |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
102 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
103 _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
|
104 { 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
|
105 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
106 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
|
107 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
|
108 _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
|
109 else |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
110 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
|
111 return 2 |
|
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 else |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
114 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
|
115 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
|
116 return 2 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
117 fi |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
118 fi |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
119 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
120 # 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
|
121 _mountpoint="${_mountpoint%/}" |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
122 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
|
123 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
|
124 return 1 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
125 fi |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
126 |
|
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
|
127 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
|
128 _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
|
129 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
|
130 _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
|
131 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
|
132 |
|
276
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
133 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
|
134 | { |
|
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
|
135 |
|
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 # |
|
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
|
137 # _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
|
138 # 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
|
139 # -- 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
|
140 # |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
141 farray_create _mounted_datasets |
|
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
|
142 |
|
276
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
143 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
|
144 # 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
|
145 [ "${_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
|
146 # 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
|
147 [ "${_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
|
148 # |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
149 # 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
|
150 # if required |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
151 # |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
152 [ \( "${_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
|
153 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
|
154 "none"|"legacy") |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
155 # 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
|
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 "${_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
|
158 # |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
159 # 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
|
160 # 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
|
161 # |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
162 |
|
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
|
163 # |
|
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
|
164 # 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
|
165 # 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
|
166 # 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
|
167 # |
|
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 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
|
169 if [ "${_name}" != "${_dsname}" ]; then |
| 498 | 170 echo "ERROR: child dataset mounts over root dataset" >&2 |
|
521
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
171 if ! checkyes _opt_keep; then |
|
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
172 _umount_datasets _mounted_datasets || true |
|
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
173 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
|
174 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
|
175 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
|
176 _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
|
177 _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
|
178 else |
|
561
d173161a3a0f
FIX: SC2295: expansions inside ${..} need to be quoted separately, otherwise they will match as a pattern.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
179 _relative_mp="${_mp#"${_rootds_mountpoint_prefix}"}" |
|
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
|
180 # 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
|
181 _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
|
182 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
|
183 echo "ERROR: got an empty relative mountpoint in child" >&2 |
|
521
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
184 if ! checkyes _opt_keep; then |
|
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
185 _umount_datasets _mounted_datasets || true |
|
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 # 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
|
190 _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
|
191 fi |
|
276
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
192 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
193 # |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
194 # 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
|
195 # 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
|
196 # is given. |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
197 # |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
198 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
|
199 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
|
200 echo "ERROR: mountpoint mismatch" >&2 |
|
521
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
201 if ! checkyes _opt_keep; then |
|
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
202 _umount_datasets _mounted_datasets || true |
|
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
203 fi |
|
276
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
204 return 1 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
205 fi |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
206 fi |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
207 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
208 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
|
209 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
|
210 else |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
211 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
|
212 { 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
|
213 echo "Mounting ${_name} on ${_real_mp}" |
|
527
b7d60802b25f
Use absolute paths for "mount" (all occurrences) and grep (some)
Franz Glasner <fzglas.hg@dom66.de>
parents:
521
diff
changeset
|
214 if /sbin/mount -t zfs "${_name}" "${_real_mp}"; then |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
215 farray_append _mounted_datasets "${_name}" |
|
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 else |
|
521
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
217 if ! checkyes _opt_keep; then |
|
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
218 _umount_datasets _mounted_datasets || true |
|
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
219 fi |
|
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
|
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 ;; |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
224 *) |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
225 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
|
226 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
|
227 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
|
228 else |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
229 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
|
230 if zfs mount "${_name}"; then |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
231 farray_append _mounted_datasets "${_name}" |
|
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
|
232 else |
|
521
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
233 if ! checkyes _opt_keep; then |
|
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
234 _umount_datasets _mounted_datasets || true |
|
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
235 fi |
|
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 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
|
237 fi |
|
276
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
238 fi |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
239 else |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
240 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
|
241 fi |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
242 ;; |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
243 esac |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
244 done |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
245 farray_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
|
246 return 0 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
247 } |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
248 } |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
249 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
250 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
251 #: |
|
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
|
252 #: 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
|
253 #: |
|
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 #: 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
|
255 #: $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
|
256 #: |
|
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 #: 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
|
258 #: 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
|
259 #: 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
|
260 #: |
|
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 #: 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
|
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 _umount_datasets() { |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
264 farray_reversed_for_each "$1" _umount_datasets_umount |
|
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
|
265 } |
|
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
|
266 |
|
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
|
267 |
|
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
|
268 #: |
|
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
|
269 #: 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
|
270 #: |
|
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
|
271 _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
|
272 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
|
273 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
|
274 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
|
275 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
|
276 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
|
277 } |
|
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
|
278 |
|
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
|
279 |
|
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
|
280 #: |
|
276
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
281 #: 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
|
282 #: |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
283 #: 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
|
284 #: |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
285 command_umount() { |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
286 local _dsname |
|
528
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
287 local _opt_dry_run |
|
276
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
288 |
|
528
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
289 local _opt _name _mp _rest _rootds_mountpoint |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
290 |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
291 _opt_dry_run="" |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
292 |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
293 while getopts "k" _opt ; do |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
294 case ${_opt} in |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
295 k) |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
296 _opt_dry_run="yes" |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
297 ;; |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
298 \?) |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
299 return 2; |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
300 ;; |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
301 esac |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
302 done |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
303 shift $((OPTIND-1)) |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
304 OPTIND=1 |
|
276
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
305 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
306 _dsname="${1-}" |
|
529
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
307 [ -z "${_dsname}" ] && { err "no dataset given"; return 2; } |
|
276
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
308 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
309 # Just determine whether the given dataset name exists |
|
529
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
310 _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}" 1>/dev/null 2>/dev/null)" || { err "dataset not found"; 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
|
311 |
|
529
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
312 if [ -x "${JQ}" ]; then |
|
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
313 /sbin/mount -t zfs -p --libxo=json,no-locale \ |
|
546
d28733400b18
Using jq: the '.a.b.c.["d"]' syntax in chains is 1.7+: use the old syntax '.a.b.c["d"]' instead.
Franz Glasner <fzglas.hg@dom66.de>
parents:
545
diff
changeset
|
314 | LC_ALL=C "${JQ}" -r $'.mount.fstab[] | [.device, .mntpoint, .fstype, .opts, .dump, .pass] | @tsv ' \ |
|
529
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
315 | LC_ALL=C /usr/bin/awk -F $'\\t+' -v OFS=$'\t' -v ds1="${_dsname}" -v ds2="${_dsname}/" $'{ if (($1 == ds1) || (index($1, ds2) == 1)) { print $1, $2; } }' \ |
|
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
316 | LC_ALL=C /usr/bin/sort -t $'\t' -k 1 -r \ |
|
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
317 | while IFS=$'\t' read -r _name _mp ; do |
|
528
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
318 if checkyes _opt_dry_run ; then |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
319 echo "Would umount ${_name} from ${_mp}" |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
320 else |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
321 echo "Umounting ${_name} on ${_mp}" |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
322 /sbin/umount "${_mp}" || return 1 |
|
93b98803219b
fzfs umount: implemented option "-k" (dry-run)
Franz Glasner <fzglas.hg@dom66.de>
parents:
527
diff
changeset
|
323 fi |
|
529
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
324 done |
|
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
325 else |
|
545
566ecdd9e73b
When analyzing the output of "mount -p" check for proper parsing capability: no improper mixing of tabs and spaces.
Franz Glasner <fzglas.hg@dom66.de>
parents:
539
diff
changeset
|
326 # Check for unexpected spaces |
|
566ecdd9e73b
When analyzing the output of "mount -p" check for proper parsing capability: no improper mixing of tabs and spaces.
Franz Glasner <fzglas.hg@dom66.de>
parents:
539
diff
changeset
|
327 if ! check_for_proper_fstab; then |
|
566ecdd9e73b
When analyzing the output of "mount -p" check for proper parsing capability: no improper mixing of tabs and spaces.
Franz Glasner <fzglas.hg@dom66.de>
parents:
539
diff
changeset
|
328 fatal 1 "Unexpected spaces in fstab. Please install \`${JQ}'." |
|
566ecdd9e73b
When analyzing the output of "mount -p" check for proper parsing capability: no improper mixing of tabs and spaces.
Franz Glasner <fzglas.hg@dom66.de>
parents:
539
diff
changeset
|
329 fi |
|
529
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
330 /sbin/mount -t zfs -p \ |
|
537
62cd970aea9c
Replace the use of "deprecated" egrep calls with "grep -E"
Franz Glasner <fzglas.hg@dom66.de>
parents:
533
diff
changeset
|
331 | LC_ALL=C /usr/bin/grep -E "^${_dsname}(/|\s)" \ |
|
625
69d557d67842
fzfs: FIX: no numeric sort for fstab
Franz Glasner <fzglas.hg@dom66.de>
parents:
578
diff
changeset
|
332 | LC_ALL=C /usr/bin/sort -r \ |
|
529
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
333 | while IFS=' '$'\t' read -r _name _mp _rest ; do |
|
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
334 if checkyes _opt_dry_run ; then |
|
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
335 echo "Would umount ${_name} from ${_mp}" |
|
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
336 else |
|
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
337 echo "Umounting ${_name} on ${_mp}" |
|
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
338 /sbin/umount "${_mp}" || return 1 |
|
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
339 fi |
|
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
340 done |
|
703e9f357339
fzfs umount: umounting now also works for datasets and/or mountpoints that have spaces in their values.
Franz Glasner <fzglas.hg@dom66.de>
parents:
528
diff
changeset
|
341 fi |
|
276
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
342 return 0 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
343 } |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
344 |
|
380
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
345 |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
346 #: |
|
421
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
347 #: Implementation of "copy-tree" |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
348 #: |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
349 command_copy_tree() { |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
350 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
|
351 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
|
352 |
|
424
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
353 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
|
354 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
|
355 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
|
356 |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
357 _opt_mountpoint="" |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
358 _opt_mount_noauto="" |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
359 _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
|
360 _opt_keep="" |
|
424
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
361 _opt_dry_run="" |
|
421
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
362 |
|
429
bbdb1ab0ea00
Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents:
428
diff
changeset
|
363 while getopts "AM:knu" _opt ; do |
|
421
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
364 case ${_opt} in |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
365 A) |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
366 _opt_mount_noauto="-o canmount=noauto" |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
367 ;; |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
368 M) |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
369 _opt_mountpoint="${OPTARG}" |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
370 ;; |
|
429
bbdb1ab0ea00
Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents:
428
diff
changeset
|
371 k) |
|
bbdb1ab0ea00
Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents:
428
diff
changeset
|
372 _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
|
373 ;; |
|
421
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
374 n) |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
375 _opt_dry_run="-n" |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
376 ;; |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
377 u) |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
378 _opt_nomount="-u" |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
379 ;; |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
380 \?) |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
381 return 2; |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
382 ;; |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
383 esac |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
384 done |
|
422
4363929b0a3e
FIX: Typo in variable name "OPTID" -> "OPTIND"
Franz Glasner <fzglas.hg@dom66.de>
parents:
421
diff
changeset
|
385 shift $((OPTIND-1)) |
|
421
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
386 OPTIND=1 |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
387 |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
388 _ds_source="${1-}" |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
389 _ds_target="${2-}" |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
390 |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
391 [ -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
|
392 [ -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
|
393 |
|
424
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
394 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
|
395 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
|
396 return 1; |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
397 fi |
|
428
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
398 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
|
399 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
|
400 return 1; |
|
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
401 fi |
|
424
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
402 |
|
421
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
403 _ds_source_base="${_ds_source%@*}" |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
404 _ds_source_snapshot="${_ds_source##*@}" |
|
424
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
405 _snapshot_suffix="@${_ds_source_snapshot}" |
|
421
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
406 |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
407 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
|
408 # No snapshot given |
|
424
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
409 [ "${_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
|
410 _ds_source_snapshot="" |
|
424
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
411 _snapshot_suffix="" |
|
421
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
412 fi |
|
424
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
413 |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
414 _ds_tree="" |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
415 |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
416 while IFS=$'\n' read -r _ds; do |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
417 if [ -z "${_ds_tree}" ]; then |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
418 _ds_tree="${_ds}" |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
419 else |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
420 _ds_tree="${_ds_tree}"$'\n'"${_ds}" |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
421 fi |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
422 done <<EOF20ee7ea0781414fab8c305d3875d15e |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
423 $(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
|
424 EOF20ee7ea0781414fab8c305d3875d15e |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
425 # 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
|
426 IFS=$'\n' |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
427 for _ds in ${_ds_tree}; do |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
428 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
|
429 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
|
430 return 1 |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
431 fi |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
432 done |
|
428
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
433 IFS=$'\n' |
|
424
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
434 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
|
435 # Reset IFS |
|
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
436 IFS=$' \t\n' |
|
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
437 |
|
424
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
438 # Determine the relative name of the dataset |
|
561
d173161a3a0f
FIX: SC2295: expansions inside ${..} need to be quoted separately, otherwise they will match as a pattern.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
439 _ds_relname="${_ds#"${_ds_source_base}"}" |
|
426
2cd4777821fc
More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
424
diff
changeset
|
440 |
|
2cd4777821fc
More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
424
diff
changeset
|
441 _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
|
442 |
|
2cd4777821fc
More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
424
diff
changeset
|
443 if [ "${_ds_canmount}" = "off" ]; then |
|
428
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
444 _arg_canmount="-o canmount=off" |
|
426
2cd4777821fc
More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
424
diff
changeset
|
445 else |
|
428
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
446 _arg_canmount="${_opt_mount_noauto}" |
|
426
2cd4777821fc
More work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
424
diff
changeset
|
447 fi |
|
424
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
448 |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
449 if [ -z "${_ds_relname}" ]; then |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
450 # |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
451 # Source root to target root |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
452 # |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
453 if [ -z "${_opt_mountpoint}" ]; then |
|
428
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
454 _arg_mp1=-x |
|
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
455 _arg_mp2=mountpoint |
|
424
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
456 else |
|
428
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
457 _arg_mp1=-o |
|
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
458 _arg_mp2="mountpoint=${_opt_mountpoint}" |
|
424
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
459 fi |
|
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
460 else |
|
428
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
461 _arg_mp1=-x |
|
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
462 _arg_mp2=mountpoint |
|
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
463 fi |
|
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
464 if [ -z "${_opt_dry_run}" ]; then |
|
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
465 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
|
466 else |
|
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
467 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
|
468 fi |
|
428
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
469 # for the loop |
|
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
470 IFS=$'\n' |
|
424
a200c18603c9
Further work on "fzfs copy-tree"
Franz Glasner <fzglas.hg@dom66.de>
parents:
423
diff
changeset
|
471 done |
|
428
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
472 # Reset to default |
|
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
473 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
|
474 # Remove received snapshots by default |
|
428
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
475 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
|
476 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
|
477 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
|
478 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
|
479 else |
|
bbdb1ab0ea00
Implement "-k" option for "fzfs copy-tree" to keep received snapshots
Franz Glasner <fzglas.hg@dom66.de>
parents:
428
diff
changeset
|
480 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
|
481 fi |
|
428
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
482 fi |
|
824e88618376
The first version of "fzfs copy-tree" completed
Franz Glasner <hg@dom66.de>
parents:
427
diff
changeset
|
483 fi |
|
421
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
484 } |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
485 |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
486 |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
487 #: |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
488 #: Implementation of "clone-tree" |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
489 #: |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
490 command_clone_tree() { |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
491 local _ds_source _ds_dest |
|
521
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
492 local _opt_keep _opt_dry_run |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
493 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
494 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
|
495 local _ds_canmount _ds_mountpoint |
|
578
721737ce1ea0
fzfs: make other "normal" properties an array and use eval with proper escaping.
Franz Glasner <fzglas.hg@dom66.de>
parents:
577
diff
changeset
|
496 local _clone_props _arg_canmount _args_other_clone_props |
|
576
5eed2968e671
fzfs: Variable name confusion: use _propvalue everywhere -- as intended
Franz Glasner <fzglas.hg@dom66.de>
parents:
561
diff
changeset
|
497 local _opt _idx _idx_lp _prop _propvalue |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
498 local _ds_tree _cloned_datasets _local_props |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
499 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
500 _opt_dry_run="" |
|
521
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
501 _opt_keep="" |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
502 |
|
521
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
503 while getopts "kn" _opt ; do |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
504 case ${_opt} in |
|
521
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
505 k) |
|
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
506 _opt_keep="yes" |
|
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
507 ;; |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
508 n) |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
509 _opt_dry_run="yes" |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
510 ;; |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
511 \?|:) |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
512 return 2; |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
513 ;; |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
514 esac |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
515 done |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
516 shift $((OPTIND-1)) |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
517 OPTIND=1 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
518 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
519 _ds_source="${1-}" |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
520 _ds_dest="${2-}" |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
521 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
522 [ -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
|
523 [ -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
|
524 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
525 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
|
526 err "source dataset does not exist: ${_ds_source}" |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
527 return 1 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
528 fi |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
529 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
|
530 err "destination dataset already exists: ${_ds_dest}" |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
531 return 1 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
532 fi |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
533 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
534 _ds_source_base="${_ds_source%@*}" |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
535 _snapshot_name="${_ds_source##*@}" |
|
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 if [ "${_ds_source_base}" = "${_snapshot_name}" ]; then |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
538 err "no snapshot given" |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
539 return 1 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
540 fi |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
541 |
|
577
8655fadf4b77
fzfs: Init local array and alist variables as recommented
Franz Glasner <fzglas.hg@dom66.de>
parents:
576
diff
changeset
|
542 _ds_tree="" |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
543 farray_create _ds_tree |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
544 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
545 while IFS=$'\n' read -r _ds; do |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
546 farray_append _ds_tree "${_ds}" |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
547 done <<EOF_9ef07253679011efa78174d435fd3892 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
548 $(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
|
549 EOF_9ef07253679011efa78174d435fd3892 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
550 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
551 # 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
|
552 _idx=1 |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
553 while farray_tryget _ds _ds_tree ${_idx}; do |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
554 if ! zfs get -H name "${_ds}@${_snapshot_name}" >/dev/null 2>&1; then |
|
521
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
555 err "child dataset (snapshot) does not exist: ${_ds}@${_snapshot_name}" 1>&2 |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
556 return 1 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
557 fi |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
558 _idx=$((${_idx} + 1)) |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
559 done |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
560 |
|
577
8655fadf4b77
fzfs: Init local array and alist variables as recommented
Franz Glasner <fzglas.hg@dom66.de>
parents:
576
diff
changeset
|
561 _cloned_datasets="" |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
562 farray_create _cloned_datasets |
|
577
8655fadf4b77
fzfs: Init local array and alist variables as recommented
Franz Glasner <fzglas.hg@dom66.de>
parents:
576
diff
changeset
|
563 _local_props="" |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
564 falist_create _local_props |
|
578
721737ce1ea0
fzfs: make other "normal" properties an array and use eval with proper escaping.
Franz Glasner <fzglas.hg@dom66.de>
parents:
577
diff
changeset
|
565 _args_other_clone_props="" |
|
721737ce1ea0
fzfs: make other "normal" properties an array and use eval with proper escaping.
Franz Glasner <fzglas.hg@dom66.de>
parents:
577
diff
changeset
|
566 farray_create _args_other_clone_props |
|
520
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 # 1. Clone with "safe" canmount settings |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
570 # |
|
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 |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
573 while farray_tryget _ds _ds_tree ${_idx}; do |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
574 # Determine the relative name of the dataset |
|
561
d173161a3a0f
FIX: SC2295: expansions inside ${..} need to be quoted separately, otherwise they will match as a pattern.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
575 _ds_relname="${_ds#"${_ds_source_base}"}" |
|
520
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 (local, default, 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 |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
580 falist_clear _local_props |
|
576
5eed2968e671
fzfs: Variable name confusion: use _propvalue everywhere -- as intended
Franz Glasner <fzglas.hg@dom66.de>
parents:
561
diff
changeset
|
581 while IFS=$'\t' read -r _prop _propvalue ; do |
|
5eed2968e671
fzfs: Variable name confusion: use _propvalue everywhere -- as intended
Franz Glasner <fzglas.hg@dom66.de>
parents:
561
diff
changeset
|
582 falist_set _local_props "${_prop}" "${_propvalue}" |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
583 done <<EOF_ce8c76187f33471f8e8c1607ed09c42e |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
584 $(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
|
585 EOF_ce8c76187f33471f8e8c1607ed09c42e |
|
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 # |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
588 # - "zfs clone" does NOT copy/clone properties. |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
589 # |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
590 # Clones inherit their properties from the target filesystem |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
591 # 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
|
592 # |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
593 if [ "${_ds_canmount}" = "off" ]; then |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
594 _arg_canmount="-o canmount=off" |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
595 else |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
596 _arg_canmount="-o canmount=noauto" |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
597 fi |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
598 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
599 # 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
|
600 _idx_lp=1 |
|
578
721737ce1ea0
fzfs: make other "normal" properties an array and use eval with proper escaping.
Franz Glasner <fzglas.hg@dom66.de>
parents:
577
diff
changeset
|
601 while falist_tryget_item_at_index _prop _propvalue _local_props ${_idx_lp}; do |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
602 if [ "${_prop}" = "mountpoint" ]; then |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
603 _idx_lp=$((${_idx_lp} + 1)) |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
604 continue |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
605 fi |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
606 if [ "${_prop}" = "canmount" ]; then |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
607 _idx_lp=$((${_idx_lp} + 1)) |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
608 continue |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
609 fi |
|
578
721737ce1ea0
fzfs: make other "normal" properties an array and use eval with proper escaping.
Franz Glasner <fzglas.hg@dom66.de>
parents:
577
diff
changeset
|
610 farray_append _args_other_clone_props "-o" "${_prop}"="${_propvalue}" |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
611 _idx_lp=$((${_idx_lp} + 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 if ! checkyes _opt_dry_run; then |
|
578
721737ce1ea0
fzfs: make other "normal" properties an array and use eval with proper escaping.
Franz Glasner <fzglas.hg@dom66.de>
parents:
577
diff
changeset
|
615 echo "Cloning ${_ds}@${_snapshot_name} into ${_ds_dest}${_ds_relname} with ${_arg_canmount} $(farray_print_join_for_eval _args_other_clone_props)" |
|
721737ce1ea0
fzfs: make other "normal" properties an array and use eval with proper escaping.
Franz Glasner <fzglas.hg@dom66.de>
parents:
577
diff
changeset
|
616 if eval "zfs clone \${_arg_canmount} $(farray_print_join_for_eval _args_other_clone_props) \"\${_ds}@\${_snapshot_name}\" \"\${_ds_dest}\${_ds_relname}\""; then |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
617 farray_append _cloned_datasets "${_ds_dest}${_ds_relname}" |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
618 else |
|
521
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
619 if ! checkyes _opt_keep; then |
|
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
620 _destroy_datasets _cloned_datasets || true |
|
c05ef1c86c9c
fzfs: Implement option "-k" for clone-tree and mount to keep cloned datasets or keep datasets mounted on errors
Franz Glasner <fzglas.hg@dom66.de>
parents:
520
diff
changeset
|
621 fi |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
622 return 1 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
623 fi |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
624 else |
|
578
721737ce1ea0
fzfs: make other "normal" properties an array and use eval with proper escaping.
Franz Glasner <fzglas.hg@dom66.de>
parents:
577
diff
changeset
|
625 echo "Would execute: zfs clone ${_arg_canmount} $(farray_print_join_for_eval _args_other_clone_props) '${_ds}@${_snapshot_name}' '${_ds_dest}${_ds_relname}'" |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
626 fi |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
627 _idx=$((${_idx} + 1)) |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
628 done |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
629 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
630 # |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
631 # 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
|
632 # also handle canmount. |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
633 # |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
634 _idx=1 |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
635 while farray_tryget _ds _ds_tree ${_idx}; do |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
636 # Determine the relative name of the dataset |
|
561
d173161a3a0f
FIX: SC2295: expansions inside ${..} need to be quoted separately, otherwise they will match as a pattern.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
637 _ds_relname="${_ds#"${_ds_source_base}"}" |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
638 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
639 # 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
|
640 _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
|
641 # Local mountpoint |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
642 _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
|
643 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
644 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
|
645 # |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
646 # 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
|
647 # already set to "off". |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
648 # |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
649 _arg_canmount="" |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
650 else |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
651 _arg_canmount="-o canmount=${_ds_canmount}" |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
652 fi |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
653 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
654 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
|
655 if ! checkyes _opt_dry_run; then |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
656 # 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
|
657 if [ -n "${_ds_mountpoint}" ]; then |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
658 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
|
659 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
|
660 else |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
661 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
|
662 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
|
663 fi |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
664 else |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
665 # 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
|
666 if [ -n "${_ds_mountpoint}" ]; then |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
667 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
|
668 else |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
669 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
|
670 fi |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
671 fi |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
672 fi |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
673 _idx=$((${_idx} + 1)) |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
674 done |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
675 farray_destroy _cloned_datasets |
|
578
721737ce1ea0
fzfs: make other "normal" properties an array and use eval with proper escaping.
Franz Glasner <fzglas.hg@dom66.de>
parents:
577
diff
changeset
|
676 farray_destroy _args_other_clone_props |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
677 return 0 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
678 } |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
679 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
680 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
681 #: |
|
380
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
682 #: Implement the "create-tree" command |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
683 #: |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
684 #: 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
|
685 #: |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
686 command_create_tree() { |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
687 local _source_ds _target_ds |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
688 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
|
689 |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
690 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
|
691 |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
692 _opt_noauto="" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
693 _opt_dry_run="" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
694 _opt_mountpoint="" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
695 _opt_nomount="" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
696 _opt_canmount_parent_only="" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
697 |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
698 while getopts "AM:npu" _opt ; do |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
699 case ${_opt} in |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
700 A) |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
701 _opt_noauto="-o canmount=noauto" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
702 ;; |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
703 M) |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
704 _opt_mountpoint="${OPTARG}" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
705 ;; |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
706 n) |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
707 _opt_dry_run="yes" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
708 ;; |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
709 p) |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
710 _opt_canmount_parent_only="yes" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
711 ;; |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
712 u) |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
713 _opt_nomount="-u" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
714 ;; |
|
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 return 2; |
|
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 esac |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
719 done |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
720 shift $((OPTIND-1)) |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
721 OPTIND=1 |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
722 |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
723 _source_ds="${1-}" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
724 _target_ds="${2-}" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
725 |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
726 [ -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
|
727 [ -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
|
728 |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
729 _source_name="${_source_ds%@*}" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
730 if [ "${_source_name}" != "${_source_ds}" ]; then |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
731 _snapshot_name="${_source_ds##*@}" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
732 else |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
733 _snapshot_name="" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
734 fi |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
735 |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
736 [ -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
|
737 |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
738 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
|
739 | { |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
740 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
|
741 # Determine the relative name of the dataset |
|
561
d173161a3a0f
FIX: SC2295: expansions inside ${..} need to be quoted separately, otherwise they will match as a pattern.
Franz Glasner <fzglas.hg@dom66.de>
parents:
550
diff
changeset
|
742 _relative_name="${_current_name#"${_source_name}"}" |
|
380
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
743 _relative_name="${_relative_name%@*}" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
744 if [ "${_current_type}" != "filesystem" ]; then |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
745 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
|
746 return 1 |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
747 fi |
|
441
f06998866c01
Renamed local helper function
Franz Glasner <fzglas.hg@dom66.de>
parents:
438
diff
changeset
|
748 _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
|
749 if [ -z "${_relative_name}" ]; then |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
750 # |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
751 # Root |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
752 # |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
753 if [ -z "${_opt_noauto}" ]; then |
|
441
f06998866c01
Renamed local helper function
Franz Glasner <fzglas.hg@dom66.de>
parents:
438
diff
changeset
|
754 _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
|
755 else |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
756 _zfs_canmount="${_opt_noauto}" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
757 fi |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
758 if [ -n "${_opt_mountpoint}" ]; then |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
759 _zfs_mountpoint="${_opt_mountpoint}" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
760 else |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
761 _zfs_mountpoint="" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
762 fi |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
763 |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
764 if [ "${_opt_dry_run}" = "yes" ]; then |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
765 if [ -z "${_zfs_mountpoint}" ]; then |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
766 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
|
767 else |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
768 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
|
769 fi |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
770 else |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
771 if [ -z "${_zfs_mountpoint}" ]; then |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
772 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
|
773 else |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
774 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
|
775 fi |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
776 fi |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
777 else |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
778 # |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
779 # Children |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
780 # |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
781 if [ -z "${_opt_noauto}" ]; then |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
782 if [ "${_opt_canmount_parent_only}" = "yes" ]; then |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
783 _zfs_canmount="" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
784 else |
|
441
f06998866c01
Renamed local helper function
Franz Glasner <fzglas.hg@dom66.de>
parents:
438
diff
changeset
|
785 _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
|
786 fi |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
787 else |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
788 _zfs_canmount="${_opt_noauto}" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
789 fi |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
790 if [ "${_opt_dry_run}" = "yes" ]; then |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
791 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
|
792 else |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
793 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
|
794 fi |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
795 fi |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
796 done |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
797 } |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
798 return 0 |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
799 } |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
800 |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
801 |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
802 #: |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
803 #: Helper to destroy some created ZFS filesystems |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
804 #: |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
805 #: Args: |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
806 #: $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
|
807 #: |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
808 #: Returns: |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
809 #: 0 if successfully destroyed all given datasets, |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
810 #: 1 otherwise |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
811 #: |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
812 #: Destruction is done in the reverse order. |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
813 #: |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
814 _destroy_datasets() { |
|
539
f6dc405ddd58
fzfs: switch to farray.sh
Franz Glasner <fzglas.hg@dom66.de>
parents:
538
diff
changeset
|
815 farray_reversed_for_each "$1" _destroy_datasets_destroy |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
816 } |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
817 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
818 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
819 #: |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
820 #: Array callback to destroy a single ZFS filesystem |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
821 #: |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
822 _destroy_datasets_destroy() { |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
823 if ! zfs destroy -v "$3" ; then |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
824 warn "Dataset \`${3}' cannot unmounted" |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
825 return 1 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
826 fi |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
827 return 0 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
828 } |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
829 |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
830 |
|
276
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
831 # |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
832 # 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
|
833 # |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
834 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
|
835 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
|
836 V) |
|
408
bb0a0384b5da
FIX: Program name in fzfs's version string
Franz Glasner <f.glasner@feldmann-mg.com>
parents:
386
diff
changeset
|
837 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
|
838 exit 0 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
839 ;; |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
840 h) |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
841 echo "${USAGE}" |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
842 exit 0 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
843 ;; |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
844 \?) |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
845 exit 2; |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
846 ;; |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
847 *) |
|
497
eb42828c0cbf
Use the new output routinges for errors in fzfs' global error handling
Franz Glasner <fzglas.hg@dom66.de>
parents:
492
diff
changeset
|
848 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
|
849 ;; |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
850 esac |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
851 done |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
852 # |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
853 # 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
|
854 # 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
|
855 # |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
856 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
|
857 OPTIND=1 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
858 |
|
497
eb42828c0cbf
Use the new output routinges for errors in fzfs' global error handling
Franz Glasner <fzglas.hg@dom66.de>
parents:
492
diff
changeset
|
859 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
|
860 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
861 command="$1" |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
862 shift |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
863 |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
864 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
|
865 mount) |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
866 command_mount "$@" |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
867 ;; |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
868 umount|unmount) |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
869 command_umount "$@" |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
870 ;; |
|
520
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
871 clone-tree) |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
872 command_clone_tree "$@" |
|
7d08fd78775c
fzfs: implement "fzfs clone-tree".
Franz Glasner <fzglas.hg@dom66.de>
parents:
500
diff
changeset
|
873 ;; |
|
421
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
874 copy-tree) |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
875 command_copy_tree "$@" |
|
a571a30bcf8a
Begin the implementation of "fzfs copy-tree"
Franz Glasner <hg@dom66.de>
parents:
408
diff
changeset
|
876 ;; |
|
380
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
877 create-tree) |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
878 command_create_tree "$@" |
|
6be930eb7490
Implement the "fzfs create-tree" command
Franz Glasner <fzglas.hg@dom66.de>
parents:
283
diff
changeset
|
879 ;; |
|
276
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
880 *) |
|
497
eb42828c0cbf
Use the new output routinges for errors in fzfs' global error handling
Franz Glasner <fzglas.hg@dom66.de>
parents:
492
diff
changeset
|
881 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
|
882 ;; |
|
3c24b07240f2
Move the implementation of "mount" and "umount" into the new tool fzfs.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff
changeset
|
883 esac |
