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 https://opensource.org/licenses/CDDL-1.0. 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]} && destroy_dataset ${rst_snap[$i]} -f 54 snapexists ${orig_snap[$i]} && destroy_dataset ${orig_snap[$i]} -f 55 [[ -e ${bkup[$i]} ]] && \ 56 log_must rm -rf ${bkup[$i]} 57 58 (( i = i + 1 )) 59 done 60 61 for ds in $rst_vol $rst_root; do 62 datasetexists $ds && destroy_dataset $ds -Rf 63 done 64} 65 66log_assert "Verifying 'zfs receive <volume>' works." 67log_onexit cleanup 68 69set -A orig_snap "$TESTPOOL/$TESTVOL@init_snap" "$TESTPOOL/$TESTVOL@inc_snap" 70set -A bkup "$TEST_BASE_DIR/fullbkup" "$TEST_BASE_DIR/incbkup" 71rst_root=$TESTPOOL/rst_ctr 72rst_vol=$rst_root/$TESTVOL 73set -A rst_snap "${rst_vol}@init_snap" "${rst_vol}@inc_snap" 74 75# 76# Preparations for testing 77# 78log_must zfs create $rst_root 79[[ ! -d $TESTDIR1 ]] && \ 80 log_must mkdir -p $TESTDIR1 81log_must zfs set mountpoint=$TESTDIR1 $rst_root 82 83typeset -i i=0 84while (( i < ${#orig_snap[*]} )); do 85 log_must zfs snapshot ${orig_snap[$i]} 86 if (( i < 1 )); then 87 log_must eval "zfs send ${orig_snap[$i]} > ${bkup[$i]}" 88 else 89 log_must eval "zfs send -i ${orig_snap[(( i - 1 ))]} \ 90 ${orig_snap[$i]} > ${bkup[$i]}" 91 fi 92 93 (( i = i + 1 )) 94done 95 96i=0 97while (( i < ${#bkup[*]} )); do 98 log_must eval "zfs receive $rst_vol < ${bkup[$i]}" 99 ! datasetexists $rst_vol || ! snapexists ${rst_snap[$i]} && \ 100 log_fail "Restoring volume fails." 101 102 (( i = i + 1 )) 103done 104 105log_pass "Verifying 'zfs receive <volume>' succeeds." 106