]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - zfs/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_008_pos.ksh
UBUNTU: SAUCE: Update zfs to e02aaf17f15ad274fa1f24c9c826f1477911ea3f
[mirror_ubuntu-zesty-kernel.git] / zfs / tests / zfs-tests / tests / functional / cli_root / zfs_receive / zfs_receive_008_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 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
29
30 #
31 # DESCRIPTION:
32 # Verifying 'zfs receive -vn [<filesystem|snapshot>]
33 # and zfs receive -vn -d <filesystem>'
34 #
35 # STRATEGY:
36 # 1. Fill in fs with some data
37 # 2. Create full and incremental send stream
38 # 3. run zfs receive with -v option
39 # 3. Dryrun zfs receive with -vn option
40 # 3. Dryrun zfs receive with -vn -d option
41 # 4. Verify receive output and result
42 #
43 function cleanup
44 {
45 for dset in $rst_snap $rst_fs $orig_snap; do
46 if datasetexists $dset; then
47 log_must $ZFS destroy -fr $dset
48 fi
49 done
50
51 for file in $fbackup $mnt_file $tmp_out; do
52 if [[ -f $file ]]; then
53 log_must $RM -f $file
54 fi
55 done
56
57 if datasetexists $TESTPOOL/$TESTFS; then
58 log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS
59 log_must $ZFS create $TESTPOOL/$TESTFS
60 log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
61 fi
62 }
63
64 verify_runnable "both"
65 log_assert "Verifying 'zfs receive -vn [<filesystem|snapshot>] " \
66 "and zfs receive -vn -d <filesystem>'"
67
68 log_onexit cleanup
69
70 typeset datasets="$TESTPOOL/$TESTFS $TESTPOOL"
71 typeset rst_fs=$TESTPOOL/$TESTFS/$TESTFS
72 typeset fbackup=/var/tmp/fbackup.$$
73 typeset tmp_out=/var/tmp/tmpout.$$
74
75 for orig_fs in $datasets ; do
76 typeset rst_snap=$rst_fs@snap
77 typeset orig_snap=$orig_fs@snap
78 typeset verb_msg="receiving full stream of ${orig_snap} into ${rst_snap}"
79 typeset dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}"
80
81 if ! datasetexists $orig_fs; then
82 log_must $ZFS create $orig_fs
83 fi
84
85 typeset mntpnt
86 mntpnt=$(get_prop mountpoint $orig_fs)
87 if [[ $? -ne 0 ]] ; then
88 log_fail "get_prop mountpoint $orig_fs failed"
89 fi
90
91 typeset mnt_file=$mntpnt/file1
92
93 log_must $MKFILE 100m $mnt_file
94 log_must $ZFS snapshot $orig_snap
95 log_must eval "$ZFS send $orig_snap > $fbackup"
96
97 for opt in "-v" "-vn"; do
98 if datasetexists $rst_fs; then
99 log_must $ZFS destroy -fr $rst_fs
100 fi
101 log_note "Check ZFS receive $opt [<filesystem|snapshot>]"
102 log_must eval "$ZFS receive $opt $rst_fs < $fbackup > $tmp_out 2>&1"
103 if [[ $opt == "-v" ]]; then
104 log_must eval "$GREP \"$verb_msg\" $tmp_out >/dev/null 2>&1"
105 if ! datasetexists $rst_snap; then
106 log_fail "dataset was not received, even though the"\
107 " -v flag was used."
108 fi
109 else
110 log_must eval "$GREP \"$dryrun_msg\" $tmp_out >/dev/null 2>&1"
111 if datasetexists $rst_snap; then
112 log_fail "dataset was received, even though the -nv"\
113 " flag was used."
114 fi
115 fi
116 done
117
118 log_note "Check ZFS receive -vn -d <filesystem>"
119 if ! datasetexists $rst_fs; then
120 log_must $ZFS create $rst_fs
121 fi
122 log_must eval "$ZFS receive -vn -d -F $rst_fs <$fbackup >$tmp_out 2>&1"
123 typeset relative_path=""
124 if [[ ${orig_fs} == *"/"* ]]; then
125 relative_path=${orig_fs#*/}
126 fi
127
128 typeset leaf_fs=${rst_fs}/${relative_path}
129 leaf_fs=${leaf_fs%/}
130 rst_snap=${leaf_fs}@snap
131 dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}"
132
133 log_must eval "$GREP \"$dryrun_msg\" $tmp_out > /dev/null 2>&1"
134
135 if datasetexists $rst_snap; then
136 log_fail "dataset $rst_snap should not existed."
137 fi
138 log_must $ZFS destroy -Rf $rst_fs
139
140 cleanup
141 done
142
143 log_pass "zfs receive -vn [<filesystem|snapshot>] and " \
144 "zfs receive -vn -d <filesystem>' succeed."