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) 2012, 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
33. $STF_SUITE/tests/functional/cli_root/zfs_send/zfs_send.cfg
34
35#
36# DESCRIPTION:
37#	Verify 'zfs send' can create valid send streams as expected.
38#
39# STRATEGY:
40#	1. Fill in fs with some data
41#	2. Create a full send streams with the fs
42#	3. Receive the send stream and verify the data integrity
43#	4. Fill in fs with some new data
44#	5. Create an incremental send stream with the fs
45#	6. Receive the incremental send stream and verify the data integrity.
46#
47
48verify_runnable "both"
49
50function cleanup
51{
52	for snap in $init_snap $inc_snap $rst_snap $rst_inc_snap; do
53                snapexists $snap && destroy_dataset $snap -f
54        done
55
56	datasetexists $rst_root && destroy_dataset $rst_root -Rf
57
58	for file in $full_bkup $inc_bkup \
59			$init_data $inc_data
60	do
61		[[ -e $file ]] && \
62			log_must rm -f $file
63	done
64
65	[[ -d $TESTDIR1 ]] && \
66		log_must rm -rf $TESTDIR1
67
68}
69
70log_assert "Verify 'zfs send' can create valid send streams as expected."
71log_onexit cleanup
72
73init_snap=$TESTPOOL/$TESTFS@init_snap
74inc_snap=$TESTPOOL/$TESTFS@inc_snap
75full_bkup=$TEST_BASE_DIR/fullbkup.$$
76inc_bkup=$TEST_BASE_DIR/incbkup.$$
77init_data=$TESTDIR/$TESTFILE1
78inc_data=$TESTDIR/$TESTFILE2
79orig_sum=""
80rst_sum=""
81rst_root=$TESTPOOL/rst_ctr
82rst_snap=$rst_root/$TESTFS@init_snap
83rst_inc_snap=$rst_root/$TESTFS@inc_snap
84rst_data=$TESTDIR1/$TESTFS/$TESTFILE1
85rst_inc_data=$TESTDIR1/$TESTFS/$TESTFILE2
86
87
88log_note "Verify 'zfs send' can create full send stream."
89
90#Pre-paration
91log_must zfs create $rst_root
92[[ ! -d $TESTDIR1 ]] && \
93	log_must mkdir -p $TESTDIR1
94log_must zfs set mountpoint=$TESTDIR1 $rst_root
95
96file_write -o create -f $init_data -b $BLOCK_SIZE -c $WRITE_COUNT
97
98log_must zfs snapshot $init_snap
99log_must eval "zfs send $init_snap > $full_bkup"
100
101log_note "Verify the send stream is valid to receive."
102
103log_must zfs receive $rst_snap <$full_bkup
104receive_check $rst_snap ${rst_snap%%@*}
105compare_cksum $init_data $rst_data
106
107log_note "Verify 'zfs send -i' can create incremental send stream."
108
109file_write -o create -f $inc_data -b $BLOCK_SIZE -c $WRITE_COUNT -d 0
110
111log_must zfs snapshot $inc_snap
112log_must eval "zfs send -i $init_snap $inc_snap > $inc_bkup"
113
114log_note "Verify the incremental send stream is valid to receive."
115
116log_must zfs rollback $rst_snap
117log_must zfs receive $rst_inc_snap <$inc_bkup
118receive_check $rst_inc_snap
119compare_cksum $inc_data $rst_inc_data
120
121log_pass "Verifying 'zfs receive' succeed."
122