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