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 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# 24# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27 28. $STF_SUITE/tests/functional/cli_root/cli_common.kshlib 29 30# 31# DESCRIPTION: 32# Verifying 'zfs receive <volume>' works. 33# 34# STRATEGY: 35# 1. Fill in volume with some data 36# 2. Create full and incremental send stream 37# 3. Restore the send stream 38# 4. Verify the restoring results. 39# 40 41verify_runnable "global" 42 43function cleanup 44{ 45 typeset -i i=0 46 typeset ds 47 48 while (( i < ${#orig_snap[*]} )); do 49 snapexists ${rst_snap[$i]} && \ 50 log_must $ZFS destroy -f ${rst_snap[$i]} 51 snapexists ${orig_snap[$i]} && \ 52 log_must $ZFS destroy -f ${orig_snap[$i]} 53 [[ -e ${bkup[$i]} ]] && \ 54 log_must $RM -rf ${bkup[$i]} 55 56 (( i = i + 1 )) 57 done 58 59 for ds in $rst_vol $rst_root; do 60 datasetexists $ds && \ 61 log_must $ZFS destroy -Rf $ds 62 done 63} 64 65log_assert "Verifying 'zfs receive <volume>' works." 66log_onexit cleanup 67 68set -A orig_snap "$TESTPOOL/$TESTVOL@init_snap" "$TESTPOOL/$TESTVOL@inc_snap" 69set -A bkup "/var/tmp/fullbkup" "/var/tmp/incbkup" 70rst_root=$TESTPOOL/rst_ctr 71rst_vol=$rst_root/$TESTVOL 72set -A rst_snap "${rst_vol}@init_snap" "${rst_vol}@inc_snap" 73 74# 75# Preparations for testing 76# 77log_must $ZFS create $rst_root 78[[ ! -d $TESTDIR1 ]] && \ 79 log_must $MKDIR -p $TESTDIR1 80log_must $ZFS set mountpoint=$TESTDIR1 $rst_root 81 82typeset -i i=0 83while (( i < ${#orig_snap[*]} )); do 84 log_must $ZFS snapshot ${orig_snap[$i]} 85 if (( i < 1 )); then 86 log_must eval "$ZFS send ${orig_snap[$i]} > ${bkup[$i]}" 87 else 88 log_must eval "$ZFS send -i ${orig_snap[(( i - 1 ))]} \ 89 ${orig_snap[$i]} > ${bkup[$i]}" 90 fi 91 92 (( i = i + 1 )) 93done 94 95i=0 96while (( i < ${#bkup[*]} )); do 97 log_must eval "$ZFS receive $rst_vol < ${bkup[$i]}" 98 ! datasetexists $rst_vol || ! snapexists ${rst_snap[$i]} && \ 99 log_fail "Restoring volume fails." 100 101 (( i = i + 1 )) 102done 103 104log_pass "Verifying 'zfs receive <volume>' succeeds." 105