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