1#! /usr/local/bin/ksh93 -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 http://www.opensolaris.org/os/licensing. 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. $STF_SUITE/include/libtest.kshlib 27 28################################################################################ 29# 30# __stc_assertion_start 31# 32# ID: snapshot_002_pos 33# 34# DESCRIPTION: 35# An archive of a zfs file system and an archive of its snapshot 36# is identical even though the original file system has 37# changed sinced the snapshot was taken. 38# 39# STRATEGY: 40# 1) Create files in all of the zfs file systems 41# 2) Create a tarball of the file system 42# 3) Create a snapshot of the dataset 43# 4) Remove all the files in the original file system 44# 5) Create a tarball of the snapshot 45# 6) Extract each tarball and compare directory structures 46# 47# TESTABILITY: explicit 48# 49# TEST_AUTOMATION_LEVEL: automated 50# 51# CODING_STATUS: COMPLETED (2005-07-04) 52# 53# __stc_assertion_end 54# 55################################################################################ 56 57verify_runnable "both" 58 59function cleanup 60{ 61 if [[ -d $CWD ]]; then 62 cd $CWD || log_fail "Could not cd $CWD" 63 fi 64 65 snapexists $SNAPFS 66 if [[ $? -eq 0 ]]; then 67 log_must $ZFS destroy $SNAPFS 68 fi 69 70 if [[ -e $SNAPDIR ]]; then 71 log_must $RM -rf $SNAPDIR > /dev/null 2>&1 72 fi 73 74 if [[ -e $TESTDIR ]]; then 75 log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 76 fi 77 78 if [[ -e $TMPDIR/zfs_snapshot2.${TESTCASE_ID} ]]; then 79 log_must $RM -rf $TMPDIR/zfs_snapshot2.${TESTCASE_ID} > /dev/null 2>&1 80 fi 81 82} 83 84log_assert "Verify an archive of a file system is identical to " \ 85 "an archive of its snapshot." 86 87log_onexit cleanup 88 89typeset -i COUNT=21 90typeset OP=create 91 92[[ -n $TESTDIR ]] && \ 93 $RM -rf $TESTDIR/* > /dev/null 2>&1 94 95log_note "Create files in the zfs filesystem..." 96populate_dir $TESTDIR/file $COUNT $NUM_WRITES $BLOCKSZ $DATA 97 98log_note "Create a tarball from $TESTDIR contents..." 99CWD=$PWD 100cd $TESTDIR || log_fail "Could not cd $TESTDIR" 101log_must $TAR cf $TESTDIR/tarball.original.tar file* 102cd $CWD || log_fail "Could not cd $CWD" 103 104log_note "Create a snapshot and mount it..." 105log_must $ZFS snapshot $SNAPFS 106 107log_note "Remove all of the original files..." 108log_must $RM -f $TESTDIR/file* > /dev/null 2>&1 109 110log_note "Create tarball of snapshot..." 111CWD=$PWD 112cd $SNAPDIR || log_fail "Could not cd $SNAPDIR" 113log_must $TAR cf $TESTDIR/tarball.snapshot.tar file* 114cd $CWD || log_fail "Could not cd $CWD" 115 116log_must $MKDIR $TESTDIR/original 117log_must $MKDIR $TESTDIR/snapshot 118 119CWD=$PWD 120cd $TESTDIR/original || log_fail "Could not cd $TESTDIR/original" 121log_must $TAR xf $TESTDIR/tarball.original.tar 122 123cd $TESTDIR/snapshot || log_fail "Could not cd $TESTDIR/snapshot" 124log_must $TAR xf $TESTDIR/tarball.snapshot.tar 125 126cd $CWD || log_fail "Could not cd $CWD" 127 128$DIRCMP $TESTDIR/original $TESTDIR/snapshot > $TMPDIR/zfs_snapshot2.${TESTCASE_ID} 129$GREP different $TMPDIR/zfs_snapshot2.${TESTCASE_ID} >/dev/null 2>&1 130if [[ $? -ne 1 ]]; then 131 log_fail "Directory structures differ." 132fi 133 134log_pass "Directory structures match." 135