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 && destroy_dataset $ds -r 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.openzfs:prop=val" $SENDFS 56log_must zfs set "org.openzfs: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" 68done 69 70# Do 3..6 in a loop to verify various combination of "zfs send" options 71typeset opts=("" "p" "R" "pR" "cew") 72for opt in ${opts[@]}; do 73 # 3. Send the dataset and its properties to a new "backup" destination 74 # NOTE: only need to send properties (-p) here 75 log_must eval "zfs send -p $SENDFS@s1 | zfs recv $BACKUP" 76 77 # 4. Set some properties on the new "backup" dataset 78 # NOTE: override "received" values and set some new properties as well 79 log_must zfs set "compression=lz4" $BACKUP 80 log_must zfs set "exec=off" $BACKUP 81 log_must zfs set "org.openzfs:prop=newval" $BACKUP 82 log_must zfs set "org.openzfs:newprop=newval" $BACKUP 83 log_must zfs set "org.openzfs:snapprop=newval" "$BACKUP@s1" 84 log_must zfs set "org.openzfs:newsnapprop=newval" "$BACKUP@s1" 85 86 # 5. Restore the "backup" dataset to a new destination 87 log_must eval "zfs send -b$opt $BACKUP@s1 | zfs recv $RESTORE" 88 89 # 6. Verify only original (received) properties are sent from "backup" 90 log_must eval "check_prop_source $RESTORE compression gzip received" 91 log_must eval "check_prop_source $RESTORE org.openzfs:prop val received" 92 log_must eval "check_prop_source $RESTORE@s1 org.openzfs:snapprop val received" 93 log_must eval "check_prop_source $RESTORE exec on default" 94 log_must eval "check_prop_missing $RESTORE org.openzfs:newprop" 95 log_must eval "check_prop_missing $RESTORE@s1 org.openzfs:newsnapprop" 96 97 # cleanup 98 log_must zfs destroy -r $BACKUP 99 log_must zfs destroy -r $RESTORE 100done 101 102log_pass "'zfs send -b' works as expected." 103