1d583b39bSJohn Wren Kennedy#!/bin/ksh -p
2d583b39bSJohn Wren Kennedy#
3d583b39bSJohn Wren Kennedy# CDDL HEADER START
4d583b39bSJohn Wren Kennedy#
5d583b39bSJohn Wren Kennedy# The contents of this file are subject to the terms of the
6d583b39bSJohn Wren Kennedy# Common Development and Distribution License (the "License").
7d583b39bSJohn Wren Kennedy# You may not use this file except in compliance with the License.
8d583b39bSJohn Wren Kennedy#
9d583b39bSJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10d583b39bSJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing.
11d583b39bSJohn Wren Kennedy# See the License for the specific language governing permissions
12d583b39bSJohn Wren Kennedy# and limitations under the License.
13d583b39bSJohn Wren Kennedy#
14d583b39bSJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
15d583b39bSJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16d583b39bSJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
17d583b39bSJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
18d583b39bSJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
19d583b39bSJohn Wren Kennedy#
20d583b39bSJohn Wren Kennedy# CDDL HEADER END
21d583b39bSJohn Wren Kennedy#
22d583b39bSJohn Wren Kennedy
23d583b39bSJohn Wren Kennedy#
24d583b39bSJohn Wren Kennedy# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25d583b39bSJohn Wren Kennedy# Use is subject to license terms.
26d583b39bSJohn Wren Kennedy#
27d583b39bSJohn Wren Kennedy
28*1d32ba66SJohn Wren Kennedy#
29*1d32ba66SJohn Wren Kennedy# Copyright (c) 2016 by Delphix. All rights reserved.
30*1d32ba66SJohn Wren Kennedy#
31*1d32ba66SJohn Wren Kennedy
32d583b39bSJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib
33d583b39bSJohn Wren Kennedy
34d583b39bSJohn Wren Kennedy#
35d583b39bSJohn Wren Kennedy# DESCRIPTION:
36d583b39bSJohn Wren Kennedy#	'zfs recv -F' should fail if the incremental stream does not match
37d583b39bSJohn Wren Kennedy#
38d583b39bSJohn Wren Kennedy# STRATEGY:
39d583b39bSJohn Wren Kennedy#	1. Create pool and fs.
40d583b39bSJohn Wren Kennedy#	2. Create some files in fs and take snapshots.
41d583b39bSJohn Wren Kennedy#	3. Keep the incremental stream and restore the stream to the pool
42d583b39bSJohn Wren Kennedy#	4. Verify receiving the stream fails
43d583b39bSJohn Wren Kennedy#
44d583b39bSJohn Wren Kennedy
45d583b39bSJohn Wren Kennedyverify_runnable "both"
46d583b39bSJohn Wren Kennedy
47d583b39bSJohn Wren Kennedyfunction cleanup
48d583b39bSJohn Wren Kennedy{
49d583b39bSJohn Wren Kennedy	for snap in $snap2 $snap1; do
50*1d32ba66SJohn Wren Kennedy		datasetexists $snap && log_must zfs destroy -rf $snap
51d583b39bSJohn Wren Kennedy	done
52d583b39bSJohn Wren Kennedy	for file in $ibackup $mntpnt/file1 $mntpnt/file2; do
53*1d32ba66SJohn Wren Kennedy		[[ -f $file ]] && log_must rm -f $file
54d583b39bSJohn Wren Kennedy	done
55d583b39bSJohn Wren Kennedy}
56d583b39bSJohn Wren Kennedy
57d583b39bSJohn Wren Kennedylog_assert "'zfs recv -F' should fail if the incremental stream does not match"
58d583b39bSJohn Wren Kennedylog_onexit cleanup
59d583b39bSJohn Wren Kennedy
60d583b39bSJohn Wren Kennedyfs=$TESTPOOL/$TESTFS
61d583b39bSJohn Wren Kennedysnap1=$fs@snap1
62d583b39bSJohn Wren Kennedysnap2=$fs@snap2
63d583b39bSJohn Wren Kennedyibackup=/var/tmp/ibackup.$$
64d583b39bSJohn Wren Kennedy
65*1d32ba66SJohn Wren Kennedydatasetexists $fs || log_must zfs create $fs
66d583b39bSJohn Wren Kennedy
67d583b39bSJohn Wren Kennedymntpnt=$(get_prop mountpoint $fs) || log_fail "get_prop mountpoint $fs"
68*1d32ba66SJohn Wren Kennedylog_must mkfile 10m $mntpnt/file1
69*1d32ba66SJohn Wren Kennedylog_must zfs snapshot $snap1
70*1d32ba66SJohn Wren Kennedylog_must mkfile 10m $mntpnt/file2
71*1d32ba66SJohn Wren Kennedylog_must zfs snapshot $snap2
72d583b39bSJohn Wren Kennedy
73*1d32ba66SJohn Wren Kennedylog_must eval "zfs send -i $snap1 $snap2 > $ibackup"
74d583b39bSJohn Wren Kennedy
75*1d32ba66SJohn Wren Kennedylog_must zfs destroy $snap1
76*1d32ba66SJohn Wren Kennedylog_must zfs destroy $snap2
77*1d32ba66SJohn Wren Kennedylog_mustnot eval "zfs receive -F $fs < $ibackup"
78d583b39bSJohn Wren Kennedy
79*1d32ba66SJohn Wren Kennedylog_must mkfile 20m $mntpnt/file1
80*1d32ba66SJohn Wren Kennedylog_must rm -rf $mntpnt/file2
81*1d32ba66SJohn Wren Kennedylog_must zfs snapshot $snap1
82*1d32ba66SJohn Wren Kennedylog_mustnot eval "zfs receive -F $snap2 < $ibackup"
83d583b39bSJohn Wren Kennedy
84d583b39bSJohn Wren Kennedylog_pass "'zfs recv -F' should fail if the incremental stream does not match"
85