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