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 (c) 2016, loli10K. All rights reserved.
25# Copyright (c) 2021, Pablo Correa Gómez. All rights reserved.
26#
27
28. $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
29. $STF_SUITE/tests/functional/cli_root/zfs_send/zfs_send.cfg
30
31#
32# DESCRIPTION:
33#	Verify 'zfs send' will avoid sending replication send
34#	streams when we're missing snapshots in the dataset
35#	hierarchy, unless -s|--skip-missing provided
36#
37# STRATEGY:
38#	1. Create a parent and child fs and then only snapshot the parent
39#	2. Verify sending with replication will fail
40#	3. Verify sending with skip-missing will print a warning but succeed
41#
42
43verify_runnable "both"
44
45function cleanup
46{
47	snapexists $SNAP && log_must zfs destroy -f $SNAP
48
49	datasetexists $PARENT && log_must zfs destroy -rf $PARENT
50
51	[[ -e $WARNF ]] && log_must rm -f $WARNF
52	rm -f $TEST_BASE_DIR/devnull
53}
54
55log_assert "Verify 'zfs send -Rs' works as expected."
56log_onexit cleanup
57
58PARENT=$TESTPOOL/parent
59CHILD=$PARENT/child
60SNAP=$PARENT@snap
61WARNF=$TEST_BASE_DIR/warn.2
62
63log_note "Verify 'zfs send -R' fails to generate replication stream"\
64	 " for datasets created before"
65
66log_must zfs create $PARENT
67log_must zfs create $CHILD
68log_must zfs snapshot $SNAP
69log_mustnot eval "zfs send -R $SNAP >$TEST_BASE_DIR/devnull"
70
71log_note "Verify 'zfs send -Rs' warns about missing snapshots, "\
72	 "but still succeeds"
73
74log_must eval "zfs send -Rs $SNAP 2> $WARNF >$TEST_BASE_DIR/devnull"
75log_must eval "[[ -s $WARNF ]]"
76
77log_pass "Verify 'zfs send -Rs' works as expected."
78