7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / cli_root / zfs_receive / zfs_receive_002_pos.ksh
blobe33112ea15500c4b4b7ce0993d34149ab3628ecb
1 #!/bin/ksh -p
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2016 by Delphix. All rights reserved.
32 . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
35 # DESCRIPTION:
36 # Verifying 'zfs receive <volume>' works.
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.
45 verify_runnable "global"
47 function cleanup
49 typeset -i i=0
50 typeset ds
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]}
60 (( i = i + 1 ))
61 done
63 for ds in $rst_vol $rst_root; do
64 datasetexists $ds && \
65 log_must zfs destroy -Rf $ds
66 done
69 log_assert "Verifying 'zfs receive <volume>' works."
70 log_onexit cleanup
72 set -A orig_snap "$TESTPOOL/$TESTVOL@init_snap" "$TESTPOOL/$TESTVOL@inc_snap"
73 set -A bkup "/var/tmp/fullbkup" "/var/tmp/incbkup"
74 rst_root=$TESTPOOL/rst_ctr
75 rst_vol=$rst_root/$TESTVOL
76 set -A rst_snap "${rst_vol}@init_snap" "${rst_vol}@inc_snap"
79 # Preparations for testing
81 log_must zfs create $rst_root
82 [[ ! -d $TESTDIR1 ]] && \
83 log_must mkdir -p $TESTDIR1
84 log_must zfs set mountpoint=$TESTDIR1 $rst_root
86 typeset -i i=0
87 while (( 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]}"
96 (( i = i + 1 ))
97 done
99 i=0
100 while (( 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."
105 (( i = i + 1 ))
106 done
108 log_pass "Verifying 'zfs receive <volume>' succeeds."