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