]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_001_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_send / zfs_send_001_pos.ksh
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
48 verify_runnable "both"
49
50 function cleanup
51 {
52         for snap in $init_snap $inc_snap $rst_snap $rst_inc_snap; do
53                 snapexists $snap && \
54                         log_must zfs destroy -f $snap
55         done
56
57         datasetexists $rst_root && \
58                 log_must zfs destroy -Rf $rst_root
59
60         for file in $full_bkup $inc_bkup \
61                         $init_data $inc_data
62         do
63                 [[ -e $file ]] && \
64                         log_must rm -f $file
65         done
66
67         [[ -d $TESTDIR1 ]] && \
68                 log_must rm -rf $TESTDIR1
69
70 }
71
72 log_assert "Verify 'zfs send' can create valid send streams as expected."
73 log_onexit cleanup
74
75 init_snap=$TESTPOOL/$TESTFS@init_snap
76 inc_snap=$TESTPOOL/$TESTFS@inc_snap
77 full_bkup=$TEST_BASE_DIR/fullbkup.$$
78 inc_bkup=$TEST_BASE_DIR/incbkup.$$
79 init_data=$TESTDIR/$TESTFILE1
80 inc_data=$TESTDIR/$TESTFILE2
81 orig_sum=""
82 rst_sum=""
83 rst_root=$TESTPOOL/rst_ctr
84 rst_snap=$rst_root/$TESTFS@init_snap
85 rst_inc_snap=$rst_root/$TESTFS@inc_snap
86 rst_data=$TESTDIR1/$TESTFS/$TESTFILE1
87 rst_inc_data=$TESTDIR1/$TESTFS/$TESTFILE2
88
89
90 log_note "Verify 'zfs send' can create full send stream."
91
92 #Pre-paration
93 log_must zfs create $rst_root
94 [[ ! -d $TESTDIR1 ]] && \
95         log_must mkdir -p $TESTDIR1
96 log_must zfs set mountpoint=$TESTDIR1 $rst_root
97
98 file_write -o create -f $init_data -b $BLOCK_SIZE -c $WRITE_COUNT
99
100 log_must zfs snapshot $init_snap
101 zfs send $init_snap > $full_bkup
102 (( $? != 0 )) && \
103         log_fail "'zfs send' fails to create full send"
104
105 log_note "Verify the send stream is valid to receive."
106
107 log_must zfs receive $rst_snap <$full_bkup
108 receive_check $rst_snap ${rst_snap%%@*}
109 compare_cksum $init_data $rst_data
110
111 log_note "Verify 'zfs send -i' can create incremental send stream."
112
113 file_write -o create -f $inc_data -b $BLOCK_SIZE -c $WRITE_COUNT -d 0
114
115 log_must zfs snapshot $inc_snap
116 zfs send -i $init_snap $inc_snap > $inc_bkup
117 (( $? != 0 )) && \
118         log_fail "'zfs send -i' fails to create incremental send"
119
120 log_note "Verify the incremental send stream is valid to receive."
121
122 log_must zfs rollback $rst_snap
123 log_must zfs receive $rst_inc_snap <$inc_bkup
124 receive_check $rst_inc_snap
125 compare_cksum $inc_data $rst_inc_data
126
127 log_pass "Verifying 'zfs receive' succeed."