1eb633035STom Caputi#!/bin/ksh -p 2eb633035STom Caputi# 3eb633035STom Caputi# CDDL HEADER START 4eb633035STom Caputi# 5eb633035STom Caputi# This file and its contents are supplied under the terms of the 6eb633035STom Caputi# Common Development and Distribution License ("CDDL"), version 1.0. 7eb633035STom Caputi# You may only use this file in accordance with the terms of version 8eb633035STom Caputi# 1.0 of the CDDL. 9eb633035STom Caputi# 10eb633035STom Caputi# A full copy of the text of the CDDL should have accompanied this 11eb633035STom Caputi# source. A copy of the CDDL is also available via the Internet at 12eb633035STom Caputi# http://www.illumos.org/license/CDDL. 13eb633035STom Caputi# 14eb633035STom Caputi# CDDL HEADER END 15eb633035STom Caputi# 16eb633035STom Caputi 17eb633035STom Caputi# 18eb633035STom Caputi# Copyright (c) 2017 Datto, Inc. All rights reserved. 19*e3bf7d5aSKody Kantor# Copyright 2020 Joyent, Inc. 20eb633035STom Caputi# 21eb633035STom Caputi 22eb633035STom Caputi. $STF_SUITE/include/libtest.shlib 23eb633035STom Caputi 24eb633035STom Caputi# 25eb633035STom Caputi# DESCRIPTION: 26eb633035STom Caputi# ZFS should receive streams from raw incremental sends. 27eb633035STom Caputi# 28eb633035STom Caputi# STRATEGY: 29eb633035STom Caputi# 1. Create an encrypted dataset 30eb633035STom Caputi# 2. Snapshot the dataset 31eb633035STom Caputi# 3. Create a file and get its checksum 32eb633035STom Caputi# 4. Snapshot the dataset 33eb633035STom Caputi# 5. Attempt to receive a raw send stream of the first snapshot 34eb633035STom Caputi# 6. Change the passphrase required to unlock the original filesystem 35eb633035STom Caputi# 7. Attempt and intentionally fail to receive the second snapshot 36eb633035STom Caputi# 8. Verify that the required passphrase hasn't changed on the receive side 37eb633035STom Caputi# 9. Attempt a real raw incremental send stream of the second snapshot 38eb633035STom Caputi# 10. Attempt load the key and mount the dataset 39eb633035STom Caputi# 11. Verify the checksum of the file is the same as the original 40eb633035STom Caputi# 41eb633035STom Caputi 42eb633035STom Caputiverify_runnable "both" 43eb633035STom Caputi 44eb633035STom Caputifunction cleanup 45eb633035STom Caputi{ 46eb633035STom Caputi datasetexists $TESTPOOL/$TESTFS1 && \ 47eb633035STom Caputi log_must zfs destroy -r $TESTPOOL/$TESTFS1 48eb633035STom Caputi 49eb633035STom Caputi datasetexists $TESTPOOL/$TESTFS2 && \ 50eb633035STom Caputi log_must zfs destroy -r $TESTPOOL/$TESTFS2 51eb633035STom Caputi 52eb633035STom Caputi [[ -f $ibackup ]] && log_must rm -f $ibackup 53eb633035STom Caputi} 54eb633035STom Caputi 55eb633035STom Caputilog_onexit cleanup 56eb633035STom Caputi 57eb633035STom Caputilog_assert "ZFS should receive streams from raw incremental sends" 58eb633035STom Caputi 59eb633035STom Caputitypeset ibackup="/var/tmp/ibackup.$$" 60eb633035STom Caputitypeset ibackup_trunc="/var/tmp/ibackup_trunc.$$" 61eb633035STom Caputitypeset passphrase="password" 62eb633035STom Caputitypeset passphrase2="password2" 63eb633035STom Caputitypeset snap1="$TESTPOOL/$TESTFS1@snap1" 64eb633035STom Caputitypeset snap2="$TESTPOOL/$TESTFS1@snap2" 65eb633035STom Caputi 66eb633035STom Caputilog_must eval "echo $passphrase | zfs create -o encryption=on" \ 67eb633035STom Caputi "-o keyformat=passphrase $TESTPOOL/$TESTFS1" 68eb633035STom Caputi 69eb633035STom Caputilog_must zfs snapshot $snap1 70eb633035STom Caputi 71eb633035STom Caputilog_must mkfile 1M /$TESTPOOL/$TESTFS1/$TESTFILE0 72*e3bf7d5aSKody Kantortypeset checksum=$(digest -a md5 /$TESTPOOL/$TESTFS1/$TESTFILE0) 73eb633035STom Caputi 74eb633035STom Caputilog_must zfs snapshot $snap2 75eb633035STom Caputi 76eb633035STom Caputilog_must eval "zfs send -w $snap1 | zfs receive $TESTPOOL/$TESTFS2" 77eb633035STom Caputilog_must eval "echo $passphrase2 | zfs change-key $TESTPOOL/$TESTFS1" 78eb633035STom Caputilog_must eval "zfs send -w -i $snap1 $snap2 > $ibackup" 79eb633035STom Caputi 80eb633035STom Caputitypeset trunc_size=$(stat -c %s $ibackup) 81eb633035STom Caputitrunc_size=$(expr $trunc_size - 64) 82eb633035STom Caputilog_must cp $ibackup $ibackup_trunc 83eb633035STom Caputilog_must truncate -s $trunc_size $ibackup_trunc 84eb633035STom Caputilog_mustnot eval "zfs receive $TESTPOOL/$TESTFS2 < $ibackup_trunc" 85eb633035STom Caputilog_mustnot eval "echo $passphrase2 | zfs load-key $TESTPOOL/$TESTFS2" 86eb633035STom Caputilog_must eval "echo $passphrase | zfs load-key $TESTPOOL/$TESTFS2" 87eb633035STom Caputilog_must zfs unload-key $TESTPOOL/$TESTFS2 88eb633035STom Caputi 89eb633035STom Caputilog_must eval "zfs receive $TESTPOOL/$TESTFS2 < $ibackup" 90eb633035STom Caputilog_must eval "echo $passphrase2 | zfs mount -l $TESTPOOL/$TESTFS2" 91eb633035STom Caputi 92*e3bf7d5aSKody Kantortypeset cksum1=$(digest -a md5 /$TESTPOOL/$TESTFS2/$TESTFILE0) 93eb633035STom Caputi[[ "$cksum1" == "$checksum" ]] || \ 94eb633035STom Caputi log_fail "Checksums differ ($cksum1 != $checksum)" 95eb633035STom Caputi 96eb633035STom Caputilog_pass "ZFS can receive streams from raw incremental sends" 97