1#!/usr/local/bin/ksh93 -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# $FreeBSD$ 24 25# 26# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 27# Use is subject to license terms. 28# 29# ident "@(#)zfs_receive_001_pos.ksh 1.4 08/02/27 SMI" 30# 31 32. $STF_SUITE/tests/cli_root/cli_common.kshlib 33 34################################################################################# 35# 36# __stc_assertion_start 37# 38# ID: zfs_receive_001_pos 39# 40# DESCRIPTION: 41# Verifying 'zfs receive [<filesystem|snapshot>] -d <filesystem>' works. 42# 43# STRATEGY: 44# 1. Fill in fs with some data 45# 2. Create full and incremental send stream 46# 3. Receive the send stream 47# 4. Verify the restoring results. 48# 49# TESTABILITY: explicit 50# 51# TEST_AUTOMATION_LEVEL: automated 52# 53# CODING_STATUS: COMPLETED (2005-09-06) 54# 55# __stc_assertion_end 56# 57################################################################################ 58 59verify_runnable "both" 60 61function cleanup 62{ 63 typeset -i i=0 64 65 datasetexists $rst_root && \ 66 log_must $ZFS destroy -Rf $rst_root 67 while (( i < 2 )); do 68 snapexists ${orig_snap[$i]} && \ 69 log_must $ZFS destroy -f ${orig_snap[$i]} 70 log_must $RM -f ${bkup[$i]} 71 72 (( i = i + 1 )) 73 done 74 75 log_must $RM -rf $TESTDIR1 76} 77 78function recreate_root 79{ 80 datasetexists $rst_root && \ 81 log_must $ZFS destroy -Rf $rst_root 82 if [[ -d $TESTDIR1 ]] ; then 83 log_must $RM -rf $TESTDIR1 84 fi 85 log_must $ZFS create $rst_root 86 log_must $ZFS set mountpoint=$TESTDIR1 $rst_root 87} 88 89log_assert "Verifying 'zfs receive [<filesystem|snapshot>] -d <filesystem>' works." 90log_onexit cleanup 91 92typeset datasets="$TESTPOOL/$TESTFS $TESTPOOL" 93set -A bkup "$TMPDIR/fullbkup" "$TMPDIR/incbkup" 94orig_sum="" 95rst_sum="" 96rst_root=$TESTPOOL/rst_ctr 97rst_fs=${rst_root}/$TESTFS 98 99for orig_fs in $datasets ; do 100 # 101 # Preparations for testing 102 # 103 recreate_root 104 105 set -A orig_snap "${orig_fs}@init_snap" "${orig_fs}@inc_snap" 106 typeset mntpnt=$(get_prop mountpoint ${orig_fs}) 107 set -A orig_data "${mntpnt}/$TESTFILE1" "${mntpnt}/$TESTFILE2" 108 109 typeset relative_path="" 110 if [[ ${orig_fs} == *"/"* ]]; then 111 relative_path=${orig_fs#*/} 112 fi 113 114 typeset leaf_fs=${rst_root}/${relative_path} 115 leaf_fs=${leaf_fs%/} 116 rst_snap=${leaf_fs}@snap 117 118 set -A rst_snap "$rst_root/$TESTFS@init_snap" "$rst_root/$TESTFS@inc_snap" 119 set -A rst_snap2 "${leaf_fs}@init_snap" "${leaf_fs}@inc_snap" 120 set -A rst_data "$TESTDIR1/$TESTFS/$TESTFILE1" "$TESTDIR1/$TESTFS/$TESTFILE2" 121 set -A rst_data2 "$TESTDIR1/${relative_path}/$TESTFILE1" "$TESTDIR1/${relative_path}/$TESTFILE2" 122 123 typeset -i i=0 124 while (( i < ${#orig_snap[*]} )); do 125 log_must $FILE_WRITE -o create -f ${orig_data[$i]} \ 126 -b $BLOCK_SIZE -c $WRITE_COUNT 127 log_must $ZFS snapshot ${orig_snap[$i]} 128 if (( i < 1 )); then 129 log_must eval "$ZFS send ${orig_snap[$i]} > ${bkup[$i]}" 130 else 131 log_must eval "$ZFS send -i ${orig_snap[(( i - 1 ))]} \ 132 ${orig_snap[$i]} > ${bkup[$i]}" 133 fi 134 135 (( i = i + 1 )) 136 done 137 138 log_note "Verifying 'zfs receive <filesystem>' works." 139 i=0 140 while (( i < ${#bkup[*]} )); do 141 if (( i > 0 )); then 142 log_must $ZFS rollback ${rst_snap[0]} 143 fi 144 log_must eval "$ZFS receive $rst_fs < ${bkup[$i]}" 145 snapexists ${rst_snap[$i]} || \ 146 log_fail "Restoring filesystem fails. ${rst_snap[$i]} not exist" 147 compare_cksum ${orig_data[$i]} ${rst_data[$i]} 148 149 (( i = i + 1 )) 150 done 151 152 log_must $ZFS destroy -Rf $rst_fs 153 154 log_note "Verifying 'zfs receive <snapshot>' works." 155 i=0 156 while (( i < ${#bkup[*]} )); do 157 if (( i > 0 )); then 158 log_must $ZFS rollback ${rst_snap[0]} 159 fi 160 log_must eval "$ZFS receive ${rst_snap[$i]} <${bkup[$i]}" 161 snapexists ${rst_snap[$i]} || \ 162 log_fail "Restoring filesystem fails. ${rst_snap[$i]} not exist" 163 compare_cksum ${orig_data[$i]} ${rst_data[$i]} 164 165 (( i = i + 1 )) 166 done 167 168 log_must $ZFS destroy -Rf $rst_fs 169 170 log_note "Verfiying 'zfs receive -d <filesystem>' works." 171 172 i=0 173 while (( i < ${#bkup[*]} )); do 174 if (( i > 0 )); then 175 log_must $ZFS rollback ${rst_snap2[0]} 176 fi 177 log_must eval "$ZFS receive -d -F $rst_root <${bkup[$i]}" 178 snapexists ${rst_snap2[$i]} || \ 179 log_fail "Restoring filesystem fails. ${rst_snap2[$i]} not exist" 180 compare_cksum ${orig_data[$i]} ${rst_data2[$i]} 181 182 (( i = i + 1 )) 183 done 184 185 cleanup 186done 187 188log_pass "Verifying 'zfs receive [<filesystem|snapshot>] -d <filesystem>' succeeds." 189