152942Sbrian#!/bin/ksh
252942Sbrian
352942Sbrian#
452942Sbrian# This file and its contents are supplied under the terms of the
552942Sbrian# Common Development and Distribution License ("CDDL"), version a.0.
652942Sbrian# You may only use this file in accordance with the terms of version
752942Sbrian# a.0 of the CDDL.
852942Sbrian#
952942Sbrian# A full copy of the text of the CDDL should have accompanied this
1052942Sbrian# source.  A copy of the CDDL is also available via the Internet at
1152942Sbrian# http://www.illumos.org/license/CDDL.
1252942Sbrian#
1352942Sbrian
1452942Sbrian#
1552942Sbrian# Copyright (c) 2019 Datto Inc.
1652942Sbrian# Copyright (c) 2020 by Delphix. All rights reserved.
1752942Sbrian#
1852942Sbrian
1952942Sbrian. $STF_SUITE/include/libtest.shlib
2052942Sbrian. $STF_SUITE/tests/functional/rsend/rsend.kshlib
2152942Sbrian
2252942Sbrian#
2352942Sbrian# Description:
2452942Sbrian# Verify that a partially received dataset can be sent with
2552942Sbrian# 'zfs send --saved'.
2652942Sbrian#
2752942Sbrian# Strategy:
2852942Sbrian# 1. Setup a pool with partially received filesystem
2952942Sbrian# 2. Perform saved send without incremental
3052942Sbrian# 3. Perform saved send with incremental
3152942Sbrian# 4. Perform saved send with incremental, resuming from a token
3252942Sbrian# 5. Perform negative tests for invalid command inputs
3352942Sbrian#
3452942Sbrian
3552942Sbrianverify_runnable "both"
3652942Sbrian
3774916Sbrianlog_assert "Verify that a partially received dataset can be sent with " \
3874916Sbrian	"'zfs send --saved'."
3952942Sbrian
4052942Sbrianfunction cleanup
4152942Sbrian{
4252942Sbrian	destroy_dataset $POOL/testfs2 "-r"
4352942Sbrian	destroy_dataset $POOL/stream "-r"
4452942Sbrian	destroy_dataset $POOL/recvfs "-r"
4552942Sbrian	destroy_dataset $POOL/partialfs "-r"
4652942Sbrian}
4752942Sbrianlog_onexit cleanup
4852942Sbrian
4952942Sbrianlog_must zfs create -o compression=off $POOL/testfs2
5052942Sbrianlog_must zfs create $POOL/stream
5152942Sbrianmntpnt=$(get_prop mountpoint $POOL/testfs2)
5271006Sbrian
5352942Sbrian# Setup a pool with partially received filesystems
5452942Sbrianlog_must mkfile 1m $mntpnt/filea
5552942Sbrianlog_must zfs snap $POOL/testfs2@a
5696582Sbrianlog_must mkfile 1m $mntpnt/fileb
5752942Sbrianlog_must zfs snap $POOL/testfs2@b
5852942Sbrianlog_must eval "zfs send $POOL/testfs2@a | zfs recv $POOL/recvfs"
5952942Sbrianlog_must eval "zfs send -i $POOL/testfs2@a $POOL/testfs2@b > " \
6052942Sbrian	"/$POOL/stream/inc.send"
6152942Sbrianlog_must eval "zfs send $POOL/testfs2@b > /$POOL/stream/full.send"
6252942Sbrianmess_send_file /$POOL/stream/full.send
6352942Sbrianmess_send_file /$POOL/stream/inc.send
6452942Sbrianlog_mustnot zfs recv -s $POOL/recvfullfs < /$POOL/stream/full.send
6552942Sbrianlog_mustnot zfs recv -s $POOL/recvfs < /$POOL/stream/inc.send
6652942Sbrian
6752942Sbrian# Perform saved send without incremental
6852942Sbrianlog_mustnot eval "zfs send --saved $POOL/recvfullfs | zfs recv -s " \
6952942Sbrian	"$POOL/partialfs"
7052942Sbriantoken=$(zfs get -Hp -o value receive_resume_token $POOL/partialfs)
7152942Sbrianlog_must eval "zfs send -t $token | zfs recv -s $POOL/partialfs"
7252942Sbrianfile_check $POOL/recvfullfs $POOL/partialfs
7352942Sbrianlog_must zfs destroy -r $POOL/partialfs
7452942Sbrian
7552942Sbrian# Perform saved send with incremental
7652942Sbrianlog_must eval "zfs send $POOL/recvfs@a | zfs recv $POOL/partialfs"
7752942Sbrianlog_mustnot eval "zfs send --saved $POOL/recvfs | " \
7852942Sbrian	"zfs recv -s $POOL/partialfs"
7952942Sbriantoken=$(zfs get -Hp -o value receive_resume_token $POOL/partialfs)
8052942Sbrianlog_must eval "zfs send -t $token | zfs recv -s $POOL/partialfs"
8152942Sbrianfile_check $POOL/recvfs $POOL/partialfs
8252942Sbrianlog_must zfs destroy -r $POOL/partialfs
8381634Sbrian
8481634Sbrian# Perform saved send with incremental, resuming from token
8552942Sbrianlog_must eval "zfs send $POOL/recvfs@a | zfs recv $POOL/partialfs"
8652942Sbrianlog_must eval "zfs send --saved $POOL/recvfs > " \
8752942Sbrian	"/$POOL/stream/partial.send"
8852942Sbrianmess_send_file /$POOL/stream/partial.send
8952942Sbrianlog_mustnot zfs recv -s $POOL/partialfs < /$POOL/stream/partial.send
9081634Sbriantoken=$(zfs get -Hp -o value receive_resume_token $POOL/partialfs)
9181634Sbrianlog_must eval "zfs send -t $token | zfs recv -s $POOL/partialfs"
9252942Sbrianfile_check $POOL/recvfs $POOL/partialfs
9352942Sbrian
9474916Sbrian# Perform negative tests for invalid command inputs
9596582Sbrianset -A badargs \
9652942Sbrian	"" \
9752942Sbrian	"$POOL/recvfs@a" \
9852942Sbrian	"-i $POOL/recvfs@a $POOL/recvfs@b" \
9952942Sbrian	"-R $POOL/recvfs" \
10052942Sbrian	"-p $POOL/recvfs" \
10152942Sbrian	"-I $POOL/recvfs" \
10252942Sbrian	"-h $POOL/recvfs"
10352942Sbrian
10452942Sbrianwhile (( i < ${#badargs[*]} ))
10552942Sbriando
10652942Sbrian	log_mustnot eval "zfs send --saved ${badargs[i]} > /dev/null"
10796582Sbrian	(( i = i + 1 ))
10852942Sbriandone
10952942Sbrian
11052942Sbrianlog_pass "A partially received dataset can be sent with 'zfs send --saved'."
11152942Sbrian