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#
24# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26
27. $STF_SUITE/tests/cli_root/cli_common.kshlib
28
29#################################################################################
30#
31# __stc_assertion_start
32#
33# ID: zfs_receive_002_pos
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# TESTABILITY: explicit
45#
46# TEST_AUTOMATION_LEVEL: automated
47#
48# CODING_STATUS: COMPLETED (2005-09-06)
49#
50# __stc_assertion_end
51#
52################################################################################
53
54verify_runnable "global"
55
56function cleanup
57{
58	typeset -i i=0
59	typeset ds
60
61	while (( i < ${#orig_snap[*]} )); do
62		snapexists ${rst_snap[$i]} && \
63			log_must $ZFS destroy -f ${rst_snap[$i]}
64		snapexists ${orig_snap[$i]} && \
65			log_must $ZFS destroy -f ${orig_snap[$i]}
66		[[ -e ${bkup[$i]} ]] && \
67			log_must $RM -rf ${bkup[$i]}
68
69		(( i = i + 1 ))
70	done
71
72	for ds in $rst_vol $rst_root; do
73		datasetexists $ds && \
74			log_must $ZFS destroy -Rf $ds
75	done
76}
77
78log_assert "Verifying 'zfs receive <volume>' works."
79log_onexit cleanup
80
81set -A orig_snap "$TESTPOOL/$TESTVOL@init_snap" "$TESTPOOL/$TESTVOL@inc_snap"
82set -A bkup "$TMPDIR/fullbkup" "$TMPDIR/incbkup"
83rst_root=$TESTPOOL/rst_ctr
84rst_vol=$rst_root/$TESTVOL
85set -A rst_snap "${rst_vol}@init_snap" "${rst_vol}@inc_snap"
86
87#
88# Preparations for testing
89#
90log_must $ZFS create $rst_root
91[[ ! -d $TESTDIR1 ]] && \
92	log_must $MKDIR -p $TESTDIR1
93log_must $ZFS set mountpoint=$TESTDIR1 $rst_root
94
95typeset -i i=0
96while (( i < ${#orig_snap[*]} )); do
97	log_must $ZFS snapshot ${orig_snap[$i]}
98	if (( i < 1 )); then
99		log_must eval "$ZFS send ${orig_snap[$i]} > ${bkup[$i]}"
100	else
101		log_must eval "$ZFS send -i ${orig_snap[(( i - 1 ))]} \
102				${orig_snap[$i]} > ${bkup[$i]}"
103	fi
104
105	(( i = i + 1 ))
106done
107
108i=0
109while (( i < ${#bkup[*]} )); do
110	log_must eval "$ZFS receive $rst_vol < ${bkup[$i]}"
111	! datasetexists $rst_vol || ! snapexists ${rst_snap[$i]} && \
112		log_fail "Restoring volume fails."
113
114	(( i = i + 1 ))
115done
116
117log_pass "Verifying 'zfs receive <volume>' succeeds."
118