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