/tests/zfs-tests/tests/functional/snapshot/snapshot_002_pos.ksh

https://github.com/adilger/zfs · Korn Shell · 129 lines · 60 code · 27 blank · 42 comment · 15 complexity · fb011f8e555415fa1b94b845e2700de5 MD5 · raw file

  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. # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
  24. # Use is subject to license terms.
  25. #
  26. #
  27. # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
  28. #
  29. . $STF_SUITE/include/libtest.shlib
  30. . $STF_SUITE/tests/functional/snapshot/snapshot.cfg
  31. #
  32. # DESCRIPTION:
  33. # An archive of a zfs file system and an archive of its snapshot
  34. # is identical even though the original file system has
  35. # changed since the snapshot was taken.
  36. #
  37. # STRATEGY:
  38. # 1) Create files in all of the zfs file systems
  39. # 2) Create a tarball of the file system
  40. # 3) Create a snapshot of the dataset
  41. # 4) Remove all the files in the original file system
  42. # 5) Create a tarball of the snapshot
  43. # 6) Extract each tarball and compare directory structures
  44. #
  45. verify_runnable "both"
  46. function cleanup
  47. {
  48. if [[ -d $CWD ]]; then
  49. cd $CWD || log_fail "Could not cd $CWD"
  50. fi
  51. snapexists $SNAPFS
  52. if [[ $? -eq 0 ]]; then
  53. log_must zfs destroy $SNAPFS
  54. fi
  55. if [[ -e $SNAPDIR ]]; then
  56. log_must rm -rf $SNAPDIR > /dev/null 2>&1
  57. fi
  58. if [[ -e $TESTDIR ]]; then
  59. log_must rm -rf $TESTDIR/* > /dev/null 2>&1
  60. fi
  61. }
  62. log_assert "Verify an archive of a file system is identical to " \
  63. "an archive of its snapshot."
  64. log_onexit cleanup
  65. typeset -i COUNT=21
  66. typeset OP=create
  67. [[ -n $TESTDIR ]] && \
  68. rm -rf $TESTDIR/* > /dev/null 2>&1
  69. log_note "Create files in the zfs filesystem..."
  70. typeset i=1
  71. while [ $i -lt $COUNT ]; do
  72. log_must file_write -o $OP -f $TESTDIR/file$i \
  73. -b $BLOCKSZ -c $NUM_WRITES -d $DATA
  74. (( i = i + 1 ))
  75. done
  76. log_note "Create a tarball from $TESTDIR contents..."
  77. CWD=$PWD
  78. cd $TESTDIR || log_fail "Could not cd $TESTDIR"
  79. log_must tar cf $TESTDIR/tarball.original.tar file*
  80. cd $CWD || log_fail "Could not cd $CWD"
  81. log_note "Create a snapshot and mount it..."
  82. log_must zfs snapshot $SNAPFS
  83. log_note "Remove all of the original files..."
  84. log_must rm -f $TESTDIR/file* > /dev/null 2>&1
  85. log_note "Create tarball of snapshot..."
  86. CWD=$PWD
  87. cd $SNAPDIR || log_fail "Could not cd $SNAPDIR"
  88. log_must tar cf $TESTDIR/tarball.snapshot.tar file*
  89. cd $CWD || log_fail "Could not cd $CWD"
  90. log_must mkdir $TESTDIR/original
  91. log_must mkdir $TESTDIR/snapshot
  92. CWD=$PWD
  93. cd $TESTDIR/original || log_fail "Could not cd $TESTDIR/original"
  94. log_must tar xf $TESTDIR/tarball.original.tar
  95. cd $TESTDIR/snapshot || log_fail "Could not cd $TESTDIR/snapshot"
  96. log_must tar xf $TESTDIR/tarball.snapshot.tar
  97. cd $CWD || log_fail "Could not cd $CWD"
  98. diff -q -r $TESTDIR/original $TESTDIR/snapshot > /dev/null 2>&1
  99. if [[ $? -eq 1 ]]; then
  100. log_fail "Directory structures differ."
  101. fi
  102. log_pass "Directory structures match."