xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/tests/functional/rsend/send_partial_dataset.ksh (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1#!/bin/ksh
2# SPDX-License-Identifier: CDDL-1.0
3
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version a.0.
7# You may only use this file in accordance with the terms of version
8# a.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14
15#
16# Copyright (c) 2019 Datto Inc.
17# Copyright (c) 2020 by Delphix. All rights reserved.
18#
19
20. $STF_SUITE/include/libtest.shlib
21. $STF_SUITE/tests/functional/rsend/rsend.kshlib
22
23#
24# Description:
25# Verify that a partially received dataset can be sent with
26# 'zfs send --saved'.
27#
28# Strategy:
29# 1. Setup a pool with partially received filesystem
30# 2. Perform saved send without incremental
31# 3. Perform saved send with incremental
32# 4. Perform saved send with incremental, resuming from a token
33# 5. Perform negative tests for invalid command inputs
34#
35
36verify_runnable "both"
37
38log_assert "Verify that a partially received dataset can be sent with " \
39	"'zfs send --saved'."
40
41function cleanup
42{
43	destroy_dataset $POOL/testfs2 "-r"
44	destroy_dataset $POOL/stream "-r"
45	destroy_dataset $POOL/recvfs "-r"
46	destroy_dataset $POOL/partialfs "-r"
47}
48log_onexit cleanup
49
50log_must zfs create -o compression=off $POOL/testfs2
51log_must zfs create $POOL/stream
52mntpnt=$(get_prop mountpoint $POOL/testfs2)
53
54# Setup a pool with partially received filesystems
55log_must mkfile 1m $mntpnt/filea
56log_must zfs snap $POOL/testfs2@a
57log_must mkfile 1m $mntpnt/fileb
58log_must zfs snap $POOL/testfs2@b
59log_must eval "zfs send $POOL/testfs2@a | zfs recv $POOL/recvfs"
60log_must eval "zfs send -i $POOL/testfs2@a $POOL/testfs2@b > " \
61	"/$POOL/stream/inc.send"
62log_must eval "zfs send $POOL/testfs2@b > /$POOL/stream/full.send"
63mess_send_file /$POOL/stream/full.send
64mess_send_file /$POOL/stream/inc.send
65log_mustnot zfs recv -s $POOL/recvfullfs < /$POOL/stream/full.send
66log_mustnot zfs recv -s $POOL/recvfs < /$POOL/stream/inc.send
67
68# Perform saved send without incremental
69log_mustnot eval "zfs send --saved $POOL/recvfullfs | zfs recv -s " \
70	"$POOL/partialfs"
71token=$(zfs get -Hp -o value receive_resume_token $POOL/partialfs)
72log_must eval "zfs send -t $token | zfs recv -s $POOL/partialfs"
73file_check $POOL/recvfullfs $POOL/partialfs
74log_must zfs destroy -r $POOL/partialfs
75
76# Perform saved send with incremental
77log_must eval "zfs send $POOL/recvfs@a | zfs recv $POOL/partialfs"
78log_mustnot eval "zfs send --saved $POOL/recvfs | " \
79	"zfs recv -s $POOL/partialfs"
80token=$(zfs get -Hp -o value receive_resume_token $POOL/partialfs)
81log_must eval "zfs send -t $token | zfs recv -s $POOL/partialfs"
82file_check $POOL/recvfs $POOL/partialfs
83log_must zfs destroy -r $POOL/partialfs
84
85# Perform saved send with incremental, resuming from token
86log_must eval "zfs send $POOL/recvfs@a | zfs recv $POOL/partialfs"
87log_must eval "zfs send --saved $POOL/recvfs > " \
88	"/$POOL/stream/partial.send"
89mess_send_file /$POOL/stream/partial.send
90log_mustnot zfs recv -s $POOL/partialfs < /$POOL/stream/partial.send
91token=$(zfs get -Hp -o value receive_resume_token $POOL/partialfs)
92log_must eval "zfs send -t $token | zfs recv -s $POOL/partialfs"
93file_check $POOL/recvfs $POOL/partialfs
94
95# Perform negative tests for invalid command inputs
96set -A badargs \
97	"" \
98	"$POOL/recvfs@a" \
99	"-i $POOL/recvfs@a $POOL/recvfs@b" \
100	"-R $POOL/recvfs" \
101	"-p $POOL/recvfs" \
102	"-I $POOL/recvfs" \
103	"-h $POOL/recvfs"
104
105while (( i < ${#badargs[*]} ))
106do
107	log_mustnot eval "zfs send --saved ${badargs[i]} > /dev/null"
108	(( i = i + 1 ))
109done
110
111log_pass "A partially received dataset can be sent with 'zfs send --saved'."
112