12fae26bdSAlan Somers#!/usr/local/bin/ksh93 -p 22fae26bdSAlan Somers# 32fae26bdSAlan Somers# CDDL HEADER START 42fae26bdSAlan Somers# 52fae26bdSAlan Somers# The contents of this file are subject to the terms of the 62fae26bdSAlan Somers# Common Development and Distribution License (the "License"). 72fae26bdSAlan Somers# You may not use this file except in compliance with the License. 82fae26bdSAlan Somers# 92fae26bdSAlan Somers# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 102fae26bdSAlan Somers# or http://www.opensolaris.org/os/licensing. 112fae26bdSAlan Somers# See the License for the specific language governing permissions 122fae26bdSAlan Somers# and limitations under the License. 132fae26bdSAlan Somers# 142fae26bdSAlan Somers# When distributing Covered Code, include this CDDL HEADER in each 152fae26bdSAlan Somers# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 162fae26bdSAlan Somers# If applicable, add the following below this CDDL HEADER, with the 172fae26bdSAlan Somers# fields enclosed by brackets "[]" replaced with your own identifying 182fae26bdSAlan Somers# information: Portions Copyright [yyyy] [name of copyright owner] 192fae26bdSAlan Somers# 202fae26bdSAlan Somers# CDDL HEADER END 212fae26bdSAlan Somers# 222fae26bdSAlan Somers 232fae26bdSAlan Somers# 242fae26bdSAlan Somers# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 252fae26bdSAlan Somers# Use is subject to license terms. 262fae26bdSAlan Somers 272fae26bdSAlan Somers. $STF_SUITE/tests/cli_root/cli_common.kshlib 282fae26bdSAlan Somers 292fae26bdSAlan Somers################################################################################# 302fae26bdSAlan Somers# 312fae26bdSAlan Somers# __stc_assertion_start 322fae26bdSAlan Somers# 332fae26bdSAlan Somers# ID: zfs_receive_008_pos 342fae26bdSAlan Somers# 352fae26bdSAlan Somers# DESCRIPTION: 362fae26bdSAlan Somers# Verifying 'zfs receive -vn [<filesystem|snapshot>] 372fae26bdSAlan Somers# and zfs receive -vn -d <filesystem>' 382fae26bdSAlan Somers# 392fae26bdSAlan Somers# STRATEGY: 402fae26bdSAlan Somers# 1. Fill in fs with some data 412fae26bdSAlan Somers# 2. Create full and incremental send stream 422fae26bdSAlan Somers# 3. run zfs receive with -v option 432fae26bdSAlan Somers# 3. Dryrun zfs receive with -vn option 442fae26bdSAlan Somers# 3. Dryrun zfs receive with -vn -d option 452fae26bdSAlan Somers# 4. Verify receive output and result 462fae26bdSAlan Somers# 472fae26bdSAlan Somers# TESTABILITY: explicit 482fae26bdSAlan Somers# 492fae26bdSAlan Somers# TEST_AUTOMATION_LEVEL: automated 502fae26bdSAlan Somers# 512fae26bdSAlan Somers# CODING_STATUS: COMPLETED (2007-06-14) 522fae26bdSAlan Somers# 532fae26bdSAlan Somers# __stc_assertion_end 542fae26bdSAlan Somers# 552fae26bdSAlan Somers################################################################################ 562fae26bdSAlan Somersfunction cleanup 572fae26bdSAlan Somers{ 582fae26bdSAlan Somers for dset in $rst_snap $rst_fs $orig_snap; do 592fae26bdSAlan Somers if datasetexists $dset; then 602fae26bdSAlan Somers log_must $ZFS destroy -fr $dset 612fae26bdSAlan Somers fi 622fae26bdSAlan Somers done 632fae26bdSAlan Somers 642fae26bdSAlan Somers for file in $fbackup $mnt_file $tmp_out; do 652fae26bdSAlan Somers if [[ -f $file ]]; then 662fae26bdSAlan Somers log_must $RM -f $file 672fae26bdSAlan Somers fi 682fae26bdSAlan Somers done 692fae26bdSAlan Somers 702fae26bdSAlan Somers if datasetexists $TESTPOOL/$TESTFS; then 712fae26bdSAlan Somers log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS 722fae26bdSAlan Somers log_must $ZFS create $TESTPOOL/$TESTFS 732fae26bdSAlan Somers log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS 742fae26bdSAlan Somers fi 752fae26bdSAlan Somers} 762fae26bdSAlan Somers 772fae26bdSAlan Somersverify_runnable "both" 782fae26bdSAlan Somerslog_assert "Verifying 'zfs receive -vn [<filesystem|snapshot>] " \ 792fae26bdSAlan Somers "and zfs receive -vn -d <filesystem>'" 802fae26bdSAlan Somers 812fae26bdSAlan Somerslog_onexit cleanup 822fae26bdSAlan Somers 832fae26bdSAlan Somerstypeset datasets="$TESTPOOL/$TESTFS $TESTPOOL" 842fae26bdSAlan Somerstypeset rst_fs=$TESTPOOL/$TESTFS/$TESTFS 852fae26bdSAlan Somerstypeset fbackup=$TMPDIR/fbackup.${TESTCASE_ID} 862fae26bdSAlan Somerstypeset tmp_out=$TMPDIR/tmpout.${TESTCASE_ID} 872fae26bdSAlan Somers 882fae26bdSAlan Somersfor orig_fs in $datasets ; do 892fae26bdSAlan Somers typeset rst_snap=$rst_fs@snap 902fae26bdSAlan Somers typeset orig_snap=$orig_fs@snap 912fae26bdSAlan Somers typeset verb_msg="receiving full stream of ${orig_snap} into ${rst_snap}" 922fae26bdSAlan Somers typeset dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}" 932fae26bdSAlan Somers 942fae26bdSAlan Somers if ! datasetexists $orig_fs; then 952fae26bdSAlan Somers log_must $ZFS create $orig_fs 962fae26bdSAlan Somers fi 972fae26bdSAlan Somers 982fae26bdSAlan Somers typeset mntpnt 992fae26bdSAlan Somers mntpnt=$(get_prop mountpoint $orig_fs) 1002fae26bdSAlan Somers if [[ $? -ne 0 ]] ; then 1012fae26bdSAlan Somers log_fail "get_prop mountpoint $orig_fs failed" 1022fae26bdSAlan Somers fi 1032fae26bdSAlan Somers 1042fae26bdSAlan Somers typeset mnt_file=$mntpnt/file1 1052fae26bdSAlan Somers 1062fae26bdSAlan Somers log_must $MKFILE 100m $mnt_file 1072fae26bdSAlan Somers log_must $ZFS snapshot $orig_snap 1082fae26bdSAlan Somers log_must eval "$ZFS send $orig_snap > $fbackup" 1092fae26bdSAlan Somers 1102fae26bdSAlan Somers for opt in "-v" "-vn"; do 1112fae26bdSAlan Somers if datasetexists $rst_fs; then 1122fae26bdSAlan Somers log_must $ZFS destroy -fr $rst_fs 1132fae26bdSAlan Somers fi 1142fae26bdSAlan Somers log_note "Check ZFS receive $opt [<filesystem|snapshot>]" 1152fae26bdSAlan Somers log_must eval "$ZFS receive $opt $rst_fs < $fbackup > $tmp_out 2>&1" 1162fae26bdSAlan Somers if [[ $opt == "-v" ]]; then 1172fae26bdSAlan Somers log_must eval "$GREP \"$verb_msg\" $tmp_out >/dev/null 2>&1" 1182fae26bdSAlan Somers if ! datasetexists $rst_snap; then 1192fae26bdSAlan Somers log_fail "dataset was not received, even though the"\ 1202fae26bdSAlan Somers " -v flag was used." 1212fae26bdSAlan Somers fi 1222fae26bdSAlan Somers else 1232fae26bdSAlan Somers log_must eval "$GREP \"$dryrun_msg\" $tmp_out >/dev/null 2>&1" 1242fae26bdSAlan Somers if datasetexists $rst_snap; then 1252fae26bdSAlan Somers log_fail "dataset was received, even though the -nv"\ 1262fae26bdSAlan Somers " flag was used." 1272fae26bdSAlan Somers fi 1282fae26bdSAlan Somers fi 1292fae26bdSAlan Somers done 1302fae26bdSAlan Somers 1312fae26bdSAlan Somers log_note "Check ZFS receive -vn -d <filesystem>" 1322fae26bdSAlan Somers if ! datasetexists $rst_fs; then 1332fae26bdSAlan Somers log_must $ZFS create $rst_fs 1342fae26bdSAlan Somers fi 1352fae26bdSAlan Somers log_must eval "$ZFS receive -vn -d -F $rst_fs <$fbackup >$tmp_out 2>&1" 1362fae26bdSAlan Somers typeset relative_path="" 1372fae26bdSAlan Somers if [[ ${orig_fs} == *"/"* ]]; then 1382fae26bdSAlan Somers relative_path=${orig_fs#*/} 1392fae26bdSAlan Somers fi 1402fae26bdSAlan Somers 1412fae26bdSAlan Somers typeset leaf_fs=${rst_fs}/${relative_path} 1422fae26bdSAlan Somers leaf_fs=${leaf_fs%/} 1432fae26bdSAlan Somers rst_snap=${leaf_fs}@snap 1442fae26bdSAlan Somers dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}" 1452fae26bdSAlan Somers 1462fae26bdSAlan Somers log_must eval "$GREP \"$dryrun_msg\" $tmp_out > /dev/null 2>&1" 1472fae26bdSAlan Somers 1482fae26bdSAlan Somers if datasetexists $rst_snap; then 1492fae26bdSAlan Somers log_fail "dataset $rst_snap should not existed." 1502fae26bdSAlan Somers fi 1512fae26bdSAlan Somers log_must $ZFS destroy -Rf $rst_fs 1522fae26bdSAlan Somers 1532fae26bdSAlan Somers cleanup 1542fae26bdSAlan Somersdone 1552fae26bdSAlan Somers 1562fae26bdSAlan Somerslog_pass "zfs receive -vn [<filesystem|snapshot>] and " \ 1572fae26bdSAlan Somers "zfs receive -vn -d <filesystem>' succeed." 158