xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send-b.ksh (revision 4c87aefe8930bd07275b8dd2e96ea5f24d93a52e)
1#!/bin/ksh -p
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
15#
16
17. $STF_SUITE/include/libtest.shlib
18. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
19
20#
21# DESCRIPTION:
22# 'zfs send -b' should works as expected.
23#
24# STRATEGY:
25# 1. Create a source dataset and set some properties
26# 2. Verify command line options interact with '-b' correctly
27# 3. Send the dataset and its properties to a new "backup" destination
28# 4. Set some properties on the new "backup" dataset
29# 5. Restore the "backup" dataset to a new destination
30# 6. Verify only original (received) properties are sent from "backup"
31#
32
33verify_runnable "both"
34
35function cleanup
36{
37	for ds in "$SENDFS" "$BACKUP" "$RESTORE"; do
38		datasetexists $ds && log_must zfs destroy -r $ds
39	done
40}
41
42log_assert "'zfs send -b' should work as expected."
43log_onexit cleanup
44
45SENDFS="$TESTPOOL/sendfs"
46BACKUP="$TESTPOOL/backup"
47RESTORE="$TESTPOOL/restore"
48
49# 1. Create a source dataset and set some properties
50log_must zfs create $SENDFS
51log_must zfs snapshot "$SENDFS@s1"
52log_must zfs bookmark "$SENDFS@s1" "$SENDFS#bm"
53log_must zfs snapshot "$SENDFS@s2"
54log_must zfs set "compression=gzip" $SENDFS
55log_must zfs set "org.zfsonlinux:prop=val" $SENDFS
56log_must zfs set "org.zfsonlinux:snapprop=val" "$SENDFS@s1"
57
58# 2. Verify command line options interact with '-b' correctly
59typeset opts=("" "p" "Rp" "cew" "nv" "D" "DLPRcenpvw")
60for opt in ${opts[@]}; do
61	log_must eval "zfs send -b$opt $SENDFS@s1 > /dev/null"
62	log_must eval "zfs send -b$opt -i $SENDFS@s1 $SENDFS@s2 > /dev/null"
63	log_must eval "zfs send -b$opt -I $SENDFS@s1 $SENDFS@s2 > /dev/null"
64done
65for opt in ${opts[@]}; do
66	log_mustnot eval "zfs send -b$opt $SENDFS > /dev/null"
67	log_mustnot eval "zfs send -b$opt $SENDFS#bm > /dev/null"
68	log_mustnot eval "zfs send -b$opt -i $SENDFS#bm $SENDFS@s2 > /dev/null"
69done
70
71# Do 3..6 in a loop to verify various combination of "zfs send" options
72typeset opts=("" "p" "R" "pR" "cew")
73for opt in ${opts[@]}; do
74	# 3. Send the dataset and its properties to a new "backup" destination
75	# NOTE: only need to send properties (-p) here
76	log_must eval "zfs send -p $SENDFS@s1 | zfs recv $BACKUP"
77
78	# 4. Set some properties on the new "backup" dataset
79	# NOTE: override "received" values and set some new properties as well
80	log_must zfs set "compression=lz4" $BACKUP
81	log_must zfs set "exec=off" $BACKUP
82	log_must zfs set "org.zfsonlinux:prop=newval" $BACKUP
83	log_must zfs set "org.zfsonlinux:newprop=newval" $BACKUP
84	log_must zfs set "org.zfsonlinux:snapprop=newval" "$BACKUP@s1"
85	log_must zfs set "org.zfsonlinux:newsnapprop=newval" "$BACKUP@s1"
86
87	# 5. Restore the "backup" dataset to a new destination
88	log_must eval "zfs send -b$opt $BACKUP@s1 | zfs recv $RESTORE"
89
90	# 6. Verify only original (received) properties are sent from "backup"
91	log_must eval "check_prop_source $RESTORE compression gzip received"
92	log_must eval "check_prop_source $RESTORE org.zfsonlinux:prop val received"
93	log_must eval "check_prop_source $RESTORE@s1 org.zfsonlinux:snapprop val received"
94	log_must eval "check_prop_source $RESTORE exec on default"
95	log_must eval "check_prop_missing $RESTORE org.zfsonlinux:newprop"
96	log_must eval "check_prop_missing $RESTORE@s1 org.zfsonlinux:newsnapprop"
97
98	# cleanup
99	log_must zfs destroy -r $BACKUP
100	log_must zfs destroy -r $RESTORE
101done
102
103log_pass "'zfs send -b' works as expected."
104