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 2007 Sun Microsystems, Inc. All rights reserved. 27# Use is subject to license terms. 28# 29# ident "@(#)zfs_receive_002_pos.ksh 1.2 07/01/09 SMI" 30# 31 32. $STF_SUITE/tests/cli_root/cli_common.kshlib 33 34################################################################################# 35# 36# __stc_assertion_start 37# 38# ID: zfs_receive_002_pos 39# 40# DESCRIPTION: 41# Verifying 'zfs receive <volume>' works. 42# 43# STRATEGY: 44# 1. Fill in volume with some data 45# 2. Create full and incremental send stream 46# 3. Restore 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 "global" 60 61function cleanup 62{ 63 typeset -i i=0 64 typeset ds 65 66 while (( i < ${#orig_snap[*]} )); do 67 snapexists ${rst_snap[$i]} && \ 68 log_must $ZFS destroy -f ${rst_snap[$i]} 69 snapexists ${orig_snap[$i]} && \ 70 log_must $ZFS destroy -f ${orig_snap[$i]} 71 [[ -e ${bkup[$i]} ]] && \ 72 log_must $RM -rf ${bkup[$i]} 73 74 (( i = i + 1 )) 75 done 76 77 for ds in $rst_vol $rst_root; do 78 datasetexists $ds && \ 79 log_must $ZFS destroy -Rf $ds 80 done 81} 82 83log_assert "Verifying 'zfs receive <volume>' works." 84log_onexit cleanup 85 86set -A orig_snap "$TESTPOOL/$TESTVOL@init_snap" "$TESTPOOL/$TESTVOL@inc_snap" 87set -A bkup "$TMPDIR/fullbkup" "$TMPDIR/incbkup" 88rst_root=$TESTPOOL/rst_ctr 89rst_vol=$rst_root/$TESTVOL 90set -A rst_snap "${rst_vol}@init_snap" "${rst_vol}@inc_snap" 91 92# 93# Preparations for testing 94# 95log_must $ZFS create $rst_root 96[[ ! -d $TESTDIR1 ]] && \ 97 log_must $MKDIR -p $TESTDIR1 98log_must $ZFS set mountpoint=$TESTDIR1 $rst_root 99 100typeset -i i=0 101while (( i < ${#orig_snap[*]} )); do 102 log_must $ZFS snapshot ${orig_snap[$i]} 103 if (( i < 1 )); then 104 log_must eval "$ZFS send ${orig_snap[$i]} > ${bkup[$i]}" 105 else 106 log_must eval "$ZFS send -i ${orig_snap[(( i - 1 ))]} \ 107 ${orig_snap[$i]} > ${bkup[$i]}" 108 fi 109 110 (( i = i + 1 )) 111done 112 113i=0 114while (( i < ${#bkup[*]} )); do 115 log_must eval "$ZFS receive $rst_vol < ${bkup[$i]}" 116 ! datasetexists $rst_vol || ! snapexists ${rst_snap[$i]} && \ 117 log_fail "Restoring volume fails." 118 119 (( i = i + 1 )) 120done 121 122log_pass "Verifying 'zfs receive <volume>' succeeds." 123