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 https://opensource.org/licenses/CDDL-1.0. 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# 47function cleanup 48{ 49 for dset in $rst_snap $rst_fs $orig_snap; do 50 datasetexists $dset && destroy_dataset $dset -fr 51 done 52 53 for file in $fbackup $mnt_file $tmp_out; do 54 if [[ -f $file ]]; then 55 log_must rm -f $file 56 fi 57 done 58 59 if datasetexists $TESTPOOL/$TESTFS; then 60 destroy_dataset $TESTPOOL/$TESTFS -Rf 61 log_must zfs create $TESTPOOL/$TESTFS 62 log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS 63 fi 64} 65 66verify_runnable "both" 67log_assert "Verifying 'zfs receive -vn [<filesystem|snapshot>] " \ 68 "and zfs receive -vn -d <filesystem>'" 69 70log_onexit cleanup 71 72typeset datasets="$TESTPOOL/$TESTFS $TESTPOOL" 73typeset rst_fs=$TESTPOOL/$TESTFS/$TESTFS 74typeset fbackup=$TEST_BASE_DIR/fbackup.$$ 75typeset tmp_out=$TEST_BASE_DIR/tmpout.$$ 76 77for orig_fs in $datasets ; do 78 typeset rst_snap=$rst_fs@snap 79 typeset orig_snap=$orig_fs@snap 80 typeset verb_msg="receiving full stream of ${orig_snap} into ${rst_snap}" 81 typeset dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}" 82 83 if ! datasetexists $orig_fs; then 84 log_must zfs create $orig_fs 85 fi 86 87 typeset mntpnt 88 mntpnt=$(get_prop mountpoint $orig_fs) 89 90 typeset mnt_file=$mntpnt/file1 91 92 log_must mkfile 100m $mnt_file 93 log_must zfs snapshot $orig_snap 94 log_must eval "zfs send $orig_snap > $fbackup" 95 96 for opt in "-v" "-vn"; do 97 datasetexists $rst_fs && destroy_dataset $rst_fs -fr 98 log_note "Check ZFS receive $opt [<filesystem|snapshot>]" 99 log_must eval "zfs receive $opt $rst_fs < $fbackup > $tmp_out 2>&1" 100 if [[ $opt == "-v" ]]; then 101 log_must eval "grep \"$verb_msg\" $tmp_out >/dev/null 2>&1" 102 if ! datasetexists $rst_snap; then 103 log_fail "dataset was not received, even though the"\ 104 " -v flag was used." 105 fi 106 else 107 log_must eval "grep \"$dryrun_msg\" $tmp_out >/dev/null 2>&1" 108 if datasetexists $rst_snap; then 109 log_fail "dataset was received, even though the -nv"\ 110 " flag was used." 111 fi 112 fi 113 done 114 115 log_note "Check ZFS receive -vn -d <filesystem>" 116 if ! datasetexists $rst_fs; then 117 log_must zfs create $rst_fs 118 fi 119 log_must eval "zfs receive -vn -d -F $rst_fs <$fbackup >$tmp_out 2>&1" 120 typeset relative_path="" 121 if [[ ${orig_fs} == *"/"* ]]; then 122 relative_path=${orig_fs#*/} 123 fi 124 125 typeset leaf_fs=${rst_fs}/${relative_path} 126 leaf_fs=${leaf_fs%/} 127 rst_snap=${leaf_fs}@snap 128 dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}" 129 130 log_must eval "grep \"$dryrun_msg\" $tmp_out > /dev/null 2>&1" 131 132 if datasetexists $rst_snap; then 133 log_fail "dataset $rst_snap should not existed." 134 fi 135 log_must zfs destroy -Rf $rst_fs 136 137 cleanup 138done 139 140log_pass "zfs receive -vn [<filesystem|snapshot>] and " \ 141 "zfs receive -vn -d <filesystem>' succeed." 142