xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_005_neg.ksh (revision 694c35faa87b858ecdadfe4fc592615f4eefbb07)
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. $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
29
30#
31# DESCRIPTION:
32#	Verify 'zfs receive' fails with unsupported scenarios.
33#	including:
34#	(1) Invalid send streams;
35#	(2) The received incremental send doesn't match the filesystem
36#	    latest status.
37#
38# STRATEGY:
39#	1. Preparation for unsupported scenarios
40#	2. Execute 'zfs receive'
41#	3. Verify the results are failed
42#
43
44verify_runnable "both"
45
46function cleanup
47{
48	typeset snap
49	typeset bkup
50
51	for snap in $init_snap $inc_snap; do
52		snapexists $snap && \
53			log_must $ZFS destroy -f $snap
54	done
55
56	datasetexists $rst_root && \
57		log_must $ZFS destroy -Rf $rst_root
58
59	for bkup in $full_bkup $inc_bkup; do
60		[[ -e $bkup ]] && \
61			log_must $RM -f $bkup
62	done
63}
64
65log_assert "Verify 'zfs receive' fails with unsupported scenarios."
66log_onexit cleanup
67
68init_snap=$TESTPOOL/$TESTFS@initsnap
69inc_snap=$TESTPOOL/$TESTFS@incsnap
70rst_root=$TESTPOOL/rst_ctr
71rst_init_snap=$rst_root/$TESTFS@init_snap
72rst_inc_snap=$rst_root/$TESTFS@inc_snap
73full_bkup=/var/tmp/full_bkup.$$
74inc_bkup=/var/tmp/inc_bkup.$$
75
76log_must $ZFS create $rst_root
77log_must $ZFS snapshot $init_snap
78log_must eval "$ZFS send $init_snap > $full_bkup"
79
80log_note "'zfs receive' fails with invalid send streams."
81log_mustnot eval "$ZFS receive $rst_init_snap < /dev/zero"
82log_mustnot eval "$ZFS receive -d $rst_root </dev/zero"
83
84log_must eval "$ZFS receive $rst_init_snap < $full_bkup"
85
86log_note "Unmatched send stream with restoring filesystem" \
87	" cannot be received."
88log_must $ZFS snapshot $inc_snap
89log_must eval "$ZFS send -i $init_snap $inc_snap > $inc_bkup"
90#make changes on the restoring filesystem
91log_must $TOUCH $ZFSROOT/$rst_root/$TESTFS/tmpfile
92log_mustnot eval "$ZFS receive $rst_inc_snap < $inc_bkup"
93log_mustnot eval "$ZFS receive -d $rst_root < $inc_bkup"
94
95log_pass "Unsupported scenarios to 'zfs receive' fail as expected."
96