1f38cb554SJohn Wren Kennedy#! /bin/ksh -p
2f38cb554SJohn Wren Kennedy#
3f38cb554SJohn Wren Kennedy# CDDL HEADER START
4f38cb554SJohn Wren Kennedy#
5f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the
6f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License").
7f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License.
8f38cb554SJohn Wren Kennedy#
9f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing.
11f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions
12f38cb554SJohn Wren Kennedy# and limitations under the License.
13f38cb554SJohn Wren Kennedy#
14f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
15f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
17f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
18f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
19f38cb554SJohn Wren Kennedy#
20f38cb554SJohn Wren Kennedy# CDDL HEADER END
21f38cb554SJohn Wren Kennedy#
22f38cb554SJohn Wren Kennedy
23f38cb554SJohn Wren Kennedy#
24f38cb554SJohn Wren Kennedy# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25f38cb554SJohn Wren Kennedy# Use is subject to license terms.
26f38cb554SJohn Wren Kennedy#
27f38cb554SJohn Wren Kennedy
28f38cb554SJohn Wren Kennedy#
29*1d32ba66SJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30f38cb554SJohn Wren Kennedy#
31f38cb554SJohn Wren Kennedy
32f38cb554SJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib
33f38cb554SJohn Wren Kennedy. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
34f38cb554SJohn Wren Kennedy
35f38cb554SJohn Wren Kennedy#
36f38cb554SJohn Wren Kennedy# DESCRIPTION:
37f38cb554SJohn Wren Kennedy# An archive of a zfs file system and an archive of its snapshot
38f38cb554SJohn Wren Kennedy# is identical even though the original file system has
39f38cb554SJohn Wren Kennedy# changed sinced the snapshot was taken.
40f38cb554SJohn Wren Kennedy#
41f38cb554SJohn Wren Kennedy# STRATEGY:
42f38cb554SJohn Wren Kennedy# 1) Create files in all of the zfs file systems
43f38cb554SJohn Wren Kennedy# 2) Create a tarball of the file system
44f38cb554SJohn Wren Kennedy# 3) Create a snapshot of the dataset
45f38cb554SJohn Wren Kennedy# 4) Remove all the files in the original file system
46f38cb554SJohn Wren Kennedy# 5) Create a tarball of the snapshot
47f38cb554SJohn Wren Kennedy# 6) Extract each tarball and compare directory structures
48f38cb554SJohn Wren Kennedy#
49f38cb554SJohn Wren Kennedy
50f38cb554SJohn Wren Kennedyverify_runnable "both"
51f38cb554SJohn Wren Kennedy
52f38cb554SJohn Wren Kennedyfunction cleanup
53f38cb554SJohn Wren Kennedy{
54f38cb554SJohn Wren Kennedy	if [[ -d $CWD ]]; then
55f38cb554SJohn Wren Kennedy		cd $CWD || log_fail "Could not cd $CWD"
56f38cb554SJohn Wren Kennedy	fi
57f38cb554SJohn Wren Kennedy
58f38cb554SJohn Wren Kennedy        snapexists $SNAPFS
59f38cb554SJohn Wren Kennedy        if [[ $? -eq 0 ]]; then
60*1d32ba66SJohn Wren Kennedy                log_must zfs destroy $SNAPFS
61f38cb554SJohn Wren Kennedy        fi
62f38cb554SJohn Wren Kennedy
63f38cb554SJohn Wren Kennedy        if [[ -e $SNAPDIR ]]; then
64*1d32ba66SJohn Wren Kennedy                log_must rm -rf $SNAPDIR > /dev/null 2>&1
65f38cb554SJohn Wren Kennedy        fi
66f38cb554SJohn Wren Kennedy
67f38cb554SJohn Wren Kennedy        if [[ -e $TESTDIR ]]; then
68*1d32ba66SJohn Wren Kennedy                log_must rm -rf $TESTDIR/* > /dev/null 2>&1
69f38cb554SJohn Wren Kennedy        fi
70f38cb554SJohn Wren Kennedy
71f38cb554SJohn Wren Kennedy	if [[ -e /tmp/zfs_snapshot2.$$ ]]; then
72*1d32ba66SJohn Wren Kennedy		log_must rm -rf /tmp/zfs_snapshot2.$$ > /dev/null 2>&1
73f38cb554SJohn Wren Kennedy	fi
74f38cb554SJohn Wren Kennedy
75f38cb554SJohn Wren Kennedy}
76f38cb554SJohn Wren Kennedy
77f38cb554SJohn Wren Kennedylog_assert "Verify an archive of a file system is identical to " \
78f38cb554SJohn Wren Kennedy    "an archive of its snapshot."
79f38cb554SJohn Wren Kennedy
80f38cb554SJohn Wren Kennedylog_onexit cleanup
81f38cb554SJohn Wren Kennedy
82f38cb554SJohn Wren Kennedytypeset -i COUNT=21
83f38cb554SJohn Wren Kennedytypeset OP=create
84f38cb554SJohn Wren Kennedy
85f38cb554SJohn Wren Kennedy[[ -n $TESTDIR ]] && \
86*1d32ba66SJohn Wren Kennedy    rm -rf $TESTDIR/* > /dev/null 2>&1
87f38cb554SJohn Wren Kennedy
88f38cb554SJohn Wren Kennedylog_note "Create files in the zfs filesystem..."
89f38cb554SJohn Wren Kennedy
90f38cb554SJohn Wren Kennedytypeset i=1
91f38cb554SJohn Wren Kennedywhile [ $i -lt $COUNT ]; do
92*1d32ba66SJohn Wren Kennedy	log_must file_write -o $OP -f $TESTDIR/file$i \
93f38cb554SJohn Wren Kennedy	    -b $BLOCKSZ -c $NUM_WRITES -d $DATA
94f38cb554SJohn Wren Kennedy
95f38cb554SJohn Wren Kennedy	(( i = i + 1 ))
96f38cb554SJohn Wren Kennedydone
97f38cb554SJohn Wren Kennedy
98f38cb554SJohn Wren Kennedylog_note "Create a tarball from $TESTDIR contents..."
99f38cb554SJohn Wren KennedyCWD=$PWD
100f38cb554SJohn Wren Kennedycd $TESTDIR || log_fail "Could not cd $TESTDIR"
101*1d32ba66SJohn Wren Kennedylog_must tar cf $TESTDIR/tarball.original.tar file*
102f38cb554SJohn Wren Kennedycd $CWD || log_fail "Could not cd $CWD"
103f38cb554SJohn Wren Kennedy
104f38cb554SJohn Wren Kennedylog_note "Create a snapshot and mount it..."
105*1d32ba66SJohn Wren Kennedylog_must zfs snapshot $SNAPFS
106f38cb554SJohn Wren Kennedy
107f38cb554SJohn Wren Kennedylog_note "Remove all of the original files..."
108*1d32ba66SJohn Wren Kennedylog_must rm -f $TESTDIR/file* > /dev/null 2>&1
109f38cb554SJohn Wren Kennedy
110f38cb554SJohn Wren Kennedylog_note "Create tarball of snapshot..."
111f38cb554SJohn Wren KennedyCWD=$PWD
112f38cb554SJohn Wren Kennedycd $SNAPDIR || log_fail "Could not cd $SNAPDIR"
113*1d32ba66SJohn Wren Kennedylog_must tar cf $TESTDIR/tarball.snapshot.tar file*
114f38cb554SJohn Wren Kennedycd $CWD || log_fail "Could not cd $CWD"
115f38cb554SJohn Wren Kennedy
116*1d32ba66SJohn Wren Kennedylog_must mkdir $TESTDIR/original
117*1d32ba66SJohn Wren Kennedylog_must mkdir $TESTDIR/snapshot
118f38cb554SJohn Wren Kennedy
119f38cb554SJohn Wren KennedyCWD=$PWD
120f38cb554SJohn Wren Kennedycd $TESTDIR/original || log_fail "Could not cd $TESTDIR/original"
121*1d32ba66SJohn Wren Kennedylog_must tar xf $TESTDIR/tarball.original.tar
122f38cb554SJohn Wren Kennedy
123f38cb554SJohn Wren Kennedycd $TESTDIR/snapshot || log_fail "Could not cd $TESTDIR/snapshot"
124*1d32ba66SJohn Wren Kennedylog_must tar xf $TESTDIR/tarball.snapshot.tar
125f38cb554SJohn Wren Kennedy
126f38cb554SJohn Wren Kennedycd $CWD || log_fail "Could not cd $CWD"
127f38cb554SJohn Wren Kennedy
128*1d32ba66SJohn Wren Kennedydircmp $TESTDIR/original $TESTDIR/snapshot > /tmp/zfs_snapshot2.$$
129*1d32ba66SJohn Wren Kennedygrep different /tmp/zfs_snapshot2.$$ >/dev/null 2>&1
130f38cb554SJohn Wren Kennedyif [[ $? -ne 1 ]]; then
131f38cb554SJohn Wren Kennedy	log_fail "Directory structures differ."
132f38cb554SJohn Wren Kennedyfi
133f38cb554SJohn Wren Kennedy
134f38cb554SJohn Wren Kennedylog_pass "Directory structures match."
135