]>
Commit | Line | Data |
---|---|---|
cae5b340 AX |
1 | #!/bin/ksh -p |
2 | # | |
3 | # CDDL HEADER START | |
4 | # | |
5 | # The contents of this file are subject to the terms of the | |
6 | # Common Development and Distribution License (the "License"). | |
7 | # You may not use this file except in compliance with the License. | |
8 | # | |
9 | # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
10 | # or http://www.opensolaris.org/os/licensing. | |
11 | # See the License for the specific language governing permissions | |
12 | # and limitations under the License. | |
13 | # | |
14 | # When distributing Covered Code, include this CDDL HEADER in each | |
15 | # file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
16 | # If applicable, add the following below this CDDL HEADER, with the | |
17 | # fields enclosed by brackets "[]" replaced with your own identifying | |
18 | # information: Portions Copyright [yyyy] [name of copyright owner] | |
19 | # | |
20 | # CDDL HEADER END | |
21 | # | |
22 | ||
23 | # | |
24 | # Copyright 2008 Sun Microsystems, Inc. All rights reserved. | |
25 | # Use is subject to license terms. | |
26 | # | |
27 | ||
28 | # | |
29 | # Copyright (c) 2016 by Delphix. All rights reserved. | |
30 | # | |
31 | ||
32 | . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib | |
33 | ||
34 | # | |
35 | # DESCRIPTION: | |
36 | # Verifying 'zfs receive -vn [<filesystem|snapshot>] | |
37 | # and zfs receive -vn -d <filesystem>' | |
38 | # | |
39 | # STRATEGY: | |
40 | # 1. Fill in fs with some data | |
41 | # 2. Create full and incremental send stream | |
42 | # 3. run zfs receive with -v option | |
43 | # 3. Dryrun zfs receive with -vn option | |
44 | # 3. Dryrun zfs receive with -vn -d option | |
45 | # 4. Verify receive output and result | |
46 | # | |
47 | function cleanup | |
48 | { | |
49 | for dset in $rst_snap $rst_fs $orig_snap; do | |
50 | if datasetexists $dset; then | |
51 | log_must zfs destroy -fr $dset | |
52 | fi | |
53 | done | |
54 | ||
55 | for file in $fbackup $mnt_file $tmp_out; do | |
56 | if [[ -f $file ]]; then | |
57 | log_must rm -f $file | |
58 | fi | |
59 | done | |
60 | ||
61 | if datasetexists $TESTPOOL/$TESTFS; then | |
62 | log_must zfs destroy -Rf $TESTPOOL/$TESTFS | |
63 | log_must zfs create $TESTPOOL/$TESTFS | |
64 | log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS | |
65 | fi | |
66 | } | |
67 | ||
68 | verify_runnable "both" | |
69 | log_assert "Verifying 'zfs receive -vn [<filesystem|snapshot>] " \ | |
70 | "and zfs receive -vn -d <filesystem>'" | |
71 | ||
72 | log_onexit cleanup | |
73 | ||
74 | typeset datasets="$TESTPOOL/$TESTFS $TESTPOOL" | |
75 | typeset rst_fs=$TESTPOOL/$TESTFS/$TESTFS | |
76 | typeset fbackup=/var/tmp/fbackup.$$ | |
77 | typeset tmp_out=/var/tmp/tmpout.$$ | |
78 | ||
79 | for orig_fs in $datasets ; do | |
80 | typeset rst_snap=$rst_fs@snap | |
81 | typeset orig_snap=$orig_fs@snap | |
82 | typeset verb_msg="receiving full stream of ${orig_snap} into ${rst_snap}" | |
83 | typeset dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}" | |
84 | ||
85 | if ! datasetexists $orig_fs; then | |
86 | log_must zfs create $orig_fs | |
87 | fi | |
88 | ||
89 | typeset mntpnt | |
90 | mntpnt=$(get_prop mountpoint $orig_fs) | |
91 | if [[ $? -ne 0 ]] ; then | |
92 | log_fail "get_prop mountpoint $orig_fs failed" | |
93 | fi | |
94 | ||
95 | typeset mnt_file=$mntpnt/file1 | |
96 | ||
97 | log_must mkfile 100m $mnt_file | |
98 | log_must zfs snapshot $orig_snap | |
99 | log_must eval "zfs send $orig_snap > $fbackup" | |
100 | ||
101 | for opt in "-v" "-vn"; do | |
102 | if datasetexists $rst_fs; then | |
103 | log_must zfs destroy -fr $rst_fs | |
104 | fi | |
105 | log_note "Check ZFS receive $opt [<filesystem|snapshot>]" | |
106 | log_must eval "zfs receive $opt $rst_fs < $fbackup > $tmp_out 2>&1" | |
107 | if [[ $opt == "-v" ]]; then | |
108 | log_must eval "grep \"$verb_msg\" $tmp_out >/dev/null 2>&1" | |
109 | if ! datasetexists $rst_snap; then | |
110 | log_fail "dataset was not received, even though the"\ | |
111 | " -v flag was used." | |
112 | fi | |
113 | else | |
114 | log_must eval "grep \"$dryrun_msg\" $tmp_out >/dev/null 2>&1" | |
115 | if datasetexists $rst_snap; then | |
116 | log_fail "dataset was received, even though the -nv"\ | |
117 | " flag was used." | |
118 | fi | |
119 | fi | |
120 | done | |
121 | ||
122 | log_note "Check ZFS receive -vn -d <filesystem>" | |
123 | if ! datasetexists $rst_fs; then | |
124 | log_must zfs create $rst_fs | |
125 | fi | |
126 | log_must eval "zfs receive -vn -d -F $rst_fs <$fbackup >$tmp_out 2>&1" | |
127 | typeset relative_path="" | |
128 | if [[ ${orig_fs} == *"/"* ]]; then | |
129 | relative_path=${orig_fs#*/} | |
130 | fi | |
131 | ||
132 | typeset leaf_fs=${rst_fs}/${relative_path} | |
133 | leaf_fs=${leaf_fs%/} | |
134 | rst_snap=${leaf_fs}@snap | |
135 | dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}" | |
136 | ||
137 | log_must eval "grep \"$dryrun_msg\" $tmp_out > /dev/null 2>&1" | |
138 | ||
139 | if datasetexists $rst_snap; then | |
140 | log_fail "dataset $rst_snap should not existed." | |
141 | fi | |
142 | log_must zfs destroy -Rf $rst_fs | |
143 | ||
144 | cleanup | |
145 | done | |
146 | ||
147 | log_pass "zfs receive -vn [<filesystem|snapshot>] and " \ | |
148 | "zfs receive -vn -d <filesystem>' succeed." |