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 file system and an archive of its snapshot 38# is identical even though the original file system has 39# changed since the snapshot was taken. 40# 41# STRATEGY: 42# 1) Create files in all of the zfs file systems 43# 2) Create a tarball of the file system 44# 3) Create a snapshot of the dataset 45# 4) Remove all the files in the original file system 46# 5) Create a tarball of the snapshot 47# 6) Extract each tarball and compare directory structures 48# 49 50verify_runnable "both" 51 52function cleanup 53{ 54 [ -d $CWD ] && log_must cd $CWD 55 56 snapexists $SNAPFS && log_must zfs destroy $SNAPFS 57 58 [ -e $SNAPDIR ] && log_must rm -rf $SNAPDIR 59 [ -e $TESTDIR ] && log_must rm -rf $TESTDIR/* 60 [ -d "$SNAPSHOT_TARDIR" ] && log_must rm -rf $SNAPSHOT_TARDIR 61} 62 63log_assert "Verify an archive of a file system is identical to " \ 64 "an archive of its snapshot." 65 66SNAPSHOT_TARDIR="$(mktemp -d /tmp/zfstests_snapshot_002.XXXXXX)" 67log_onexit cleanup 68 69typeset -i COUNT=21 70typeset OP=create 71 72[ -n $TESTDIR ] && rm -rf $TESTDIR/* 73 74log_note "Create files in the zfs filesystem..." 75 76typeset i=1 77while [ $i -lt $COUNT ]; do 78 log_must file_write -o $OP -f $TESTDIR/file$i \ 79 -b $BLOCKSZ -c $NUM_WRITES -d $DATA 80 (( i = i + 1 )) 81done 82 83log_note "Create a tarball from $TESTDIR contents..." 84CWD=$PWD 85log_must cd $TESTDIR 86log_must tar cf $SNAPSHOT_TARDIR/original.tar . 87log_must cd $CWD 88 89log_note "Create a snapshot and mount it..." 90log_must zfs snapshot $SNAPFS 91 92log_note "Remove all of the original files..." 93log_must rm -f $TESTDIR/file* 94 95log_note "Create tarball of snapshot..." 96CWD=$PWD 97log_must cd $SNAPDIR 98log_must tar cf $SNAPSHOT_TARDIR/snapshot.tar . 99log_must cd $CWD 100 101log_must mkdir $TESTDIR/original $TESTDIR/snapshot 102 103CWD=$PWD 104log_must cd $TESTDIR/original 105log_must tar xf $SNAPSHOT_TARDIR/original.tar 106 107log_must cd $TESTDIR/snapshot 108log_must tar xf $SNAPSHOT_TARDIR/snapshot.tar 109 110log_must cd $CWD 111 112log_must directory_diff $TESTDIR/original $TESTDIR/snapshot 113log_pass "Directory structures match." 114