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.
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.
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]
24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2016 by Delphix. All rights reserved.
32 . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
36 # Verifying 'zfs receive -vn [<filesystem|snapshot>]
37 # and zfs receive -vn -d <filesystem>'
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
49 for dset in $rst_snap $rst_fs $orig_snap; do
50 if datasetexists $dset; then
51 log_must zfs destroy -fr $dset
55 for file in $fbackup $mnt_file $tmp_out; do
56 if [[ -f $file ]]; then
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
68 verify_runnable "both"
69 log_assert "Verifying 'zfs receive -vn [<filesystem|snapshot>] " \
70 "and zfs receive -vn -d <filesystem>'"
74 typeset datasets="$TESTPOOL/$TESTFS $TESTPOOL"
75 typeset rst_fs=$TESTPOOL/$TESTFS/$TESTFS
76 typeset fbackup=$TEST_BASE_DIR/fbackup.$$
77 typeset tmp_out=$TEST_BASE_DIR/tmpout.$$
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}"
85 if ! datasetexists $orig_fs; then
86 log_must zfs create $orig_fs
90 mntpnt=$(get_prop mountpoint $orig_fs)
91 if [[ $? -ne 0 ]] ; then
92 log_fail "get_prop mountpoint $orig_fs failed"
95 typeset mnt_file=$mntpnt/file1
97 log_must mkfile 100m $mnt_file
98 log_must zfs snapshot $orig_snap
99 log_must eval "zfs send $orig_snap > $fbackup"
101 for opt in "-v" "-vn"; do
102 if datasetexists $rst_fs; then
103 log_must zfs destroy -fr $rst_fs
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"\
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"\
122 log_note "Check ZFS receive -vn -d <filesystem>"
123 if ! datasetexists $rst_fs; then
124 log_must zfs create $rst_fs
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#*/}
132 typeset leaf_fs=${rst_fs}/${relative_path}
134 rst_snap=${leaf_fs}@snap
135 dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}"
137 log_must eval "grep \"$dryrun_msg\" $tmp_out > /dev/null 2>&1"
139 if datasetexists $rst_snap; then
140 log_fail "dataset $rst_snap should not existed."
142 log_must zfs destroy -Rf $rst_fs
147 log_pass "zfs receive -vn [<filesystem|snapshot>] and " \
148 "zfs receive -vn -d <filesystem>' succeed."