1#! /bin/ksh -p 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or https://opensource.org/licenses/CDDL-1.0. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22 23# 24# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27 28# 29# Copyright (c) 2013, 2016 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/include/libtest.shlib 33. $STF_SUITE/tests/functional/snapshot/snapshot.cfg 34 35# 36# DESCRIPTION: 37# An archive of a zfs dataset and an archive of its snapshot 38# changed since the snapshot was taken. 39# 40# STRATEGY: 41# 1) Create some files in a ZFS dataset 42# 2) Create a tarball of the dataset 43# 3) Create a snapshot of the dataset 44# 4) Remove all the files in the original dataset 45# 5) Create a tarball of the snapshot 46# 6) Extract each tarball and compare directory structures 47# 48 49verify_runnable "both" 50 51function cleanup 52{ 53 if [[ -d $CWD ]]; then 54 log_must cd $CWD 55 fi 56 57 snapexists $SNAPCTR && log_must zfs destroy $SNAPCTR 58 59 if [ -e $SNAPDIR1 ]; then 60 log_must rm -rf $SNAPDIR1 61 fi 62 63 if [ -e $TESTDIR1 ]; then 64 log_must rm -rf $TESTDIR1/* 65 fi 66 67 if [ -d "$SNAPSHOT_TARDIR" ]; then 68 log_must rm -rf $SNAPSHOT_TARDIR 69 fi 70} 71 72log_assert "Verify that an archive of a dataset is identical to " \ 73 "an archive of the dataset's snapshot." 74 75SNAPSHOT_TARDIR="$(mktemp -d /tmp/zfstests_snapshot_006.XXXXXX)" 76log_onexit cleanup 77 78typeset -i COUNT=21 79typeset OP=create 80 81[ -n $TESTDIR1 ] && rm -rf $TESTDIR1/* 82 83log_note "Create files in the zfs dataset ..." 84 85typeset i=1 86while [ $i -lt $COUNT ]; do 87 log_must file_write -o $OP -f $TESTDIR1/file$i \ 88 -b $BLOCKSZ -c $NUM_WRITES -d $DATA 89 (( i = i + 1 )) 90done 91 92log_note "Create a tarball from $TESTDIR1 contents..." 93CWD=$PWD 94log_must cd $TESTDIR1 95log_must tar cf $SNAPSHOT_TARDIR/original.tar . 96log_must cd $CWD 97 98log_note "Create a snapshot and mount it..." 99log_must zfs snapshot $SNAPCTR 100 101log_note "Remove all of the original files..." 102log_must rm -f $TESTDIR1/file* 103 104log_note "Create tarball of snapshot..." 105CWD=$PWD 106log_must cd $SNAPDIR1 107log_must tar cf $SNAPSHOT_TARDIR/snapshot.tar . 108log_must cd $CWD 109 110log_must mkdir $TESTDIR1/original mkdir $TESTDIR1/snapshot 111 112CWD=$PWD 113log_must cd $TESTDIR1/original 114log_must tar xf $SNAPSHOT_TARDIR/original.tar 115 116log_must cd $TESTDIR1/snapshot 117log_must tar xf $SNAPSHOT_TARDIR/snapshot.tar 118 119log_must cd $CWD 120 121log_must directory_diff $TESTDIR1/original $TESTDIR1/snapshot 122log_pass "Directory structures match." 123