PageRenderTime 29ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 1ms

/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_008_pos.ksh

http://github.com/zfsonlinux/zfs
Korn Shell | 148 lines | 86 code | 21 blank | 41 comment | 18 complexity | defc9616c69fd18553b008e36dd139e2 MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception
  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 2008 Sun Microsystems, Inc. All rights reserved.
  24. # Use is subject to license terms.
  25. #
  26. #
  27. # Copyright (c) 2016 by Delphix. All rights reserved.
  28. #
  29. . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
  30. #
  31. # DESCRIPTION:
  32. # Verifying 'zfs receive -vn [<filesystem|snapshot>]
  33. # and zfs receive -vn -d <filesystem>'
  34. #
  35. # STRATEGY:
  36. # 1. Fill in fs with some data
  37. # 2. Create full and incremental send stream
  38. # 3. run zfs receive with -v option
  39. # 3. Dryrun zfs receive with -vn option
  40. # 3. Dryrun zfs receive with -vn -d option
  41. # 4. Verify receive output and result
  42. #
  43. function cleanup
  44. {
  45. for dset in $rst_snap $rst_fs $orig_snap; do
  46. if datasetexists $dset; then
  47. log_must zfs destroy -fr $dset
  48. fi
  49. done
  50. for file in $fbackup $mnt_file $tmp_out; do
  51. if [[ -f $file ]]; then
  52. log_must rm -f $file
  53. fi
  54. done
  55. if datasetexists $TESTPOOL/$TESTFS; then
  56. log_must zfs destroy -Rf $TESTPOOL/$TESTFS
  57. log_must zfs create $TESTPOOL/$TESTFS
  58. log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
  59. fi
  60. }
  61. verify_runnable "both"
  62. log_assert "Verifying 'zfs receive -vn [<filesystem|snapshot>] " \
  63. "and zfs receive -vn -d <filesystem>'"
  64. log_onexit cleanup
  65. typeset datasets="$TESTPOOL/$TESTFS $TESTPOOL"
  66. typeset rst_fs=$TESTPOOL/$TESTFS/$TESTFS
  67. typeset fbackup=$TEST_BASE_DIR/fbackup.$$
  68. typeset tmp_out=$TEST_BASE_DIR/tmpout.$$
  69. for orig_fs in $datasets ; do
  70. typeset rst_snap=$rst_fs@snap
  71. typeset orig_snap=$orig_fs@snap
  72. typeset verb_msg="receiving full stream of ${orig_snap} into ${rst_snap}"
  73. typeset dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}"
  74. if ! datasetexists $orig_fs; then
  75. log_must zfs create $orig_fs
  76. fi
  77. typeset mntpnt
  78. mntpnt=$(get_prop mountpoint $orig_fs)
  79. if [[ $? -ne 0 ]] ; then
  80. log_fail "get_prop mountpoint $orig_fs failed"
  81. fi
  82. typeset mnt_file=$mntpnt/file1
  83. log_must mkfile 100m $mnt_file
  84. log_must zfs snapshot $orig_snap
  85. log_must eval "zfs send $orig_snap > $fbackup"
  86. for opt in "-v" "-vn"; do
  87. if datasetexists $rst_fs; then
  88. log_must zfs destroy -fr $rst_fs
  89. fi
  90. log_note "Check ZFS receive $opt [<filesystem|snapshot>]"
  91. log_must eval "zfs receive $opt $rst_fs < $fbackup > $tmp_out 2>&1"
  92. if [[ $opt == "-v" ]]; then
  93. log_must eval "grep \"$verb_msg\" $tmp_out >/dev/null 2>&1"
  94. if ! datasetexists $rst_snap; then
  95. log_fail "dataset was not received, even though the"\
  96. " -v flag was used."
  97. fi
  98. else
  99. log_must eval "grep \"$dryrun_msg\" $tmp_out >/dev/null 2>&1"
  100. if datasetexists $rst_snap; then
  101. log_fail "dataset was received, even though the -nv"\
  102. " flag was used."
  103. fi
  104. fi
  105. done
  106. log_note "Check ZFS receive -vn -d <filesystem>"
  107. if ! datasetexists $rst_fs; then
  108. log_must zfs create $rst_fs
  109. fi
  110. log_must eval "zfs receive -vn -d -F $rst_fs <$fbackup >$tmp_out 2>&1"
  111. typeset relative_path=""
  112. if [[ ${orig_fs} == *"/"* ]]; then
  113. relative_path=${orig_fs#*/}
  114. fi
  115. typeset leaf_fs=${rst_fs}/${relative_path}
  116. leaf_fs=${leaf_fs%/}
  117. rst_snap=${leaf_fs}@snap
  118. dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}"
  119. log_must eval "grep \"$dryrun_msg\" $tmp_out > /dev/null 2>&1"
  120. if datasetexists $rst_snap; then
  121. log_fail "dataset $rst_snap should not existed."
  122. fi
  123. log_must zfs destroy -Rf $rst_fs
  124. cleanup
  125. done
  126. log_pass "zfs receive -vn [<filesystem|snapshot>] and " \
  127. "zfs receive -vn -d <filesystem>' succeed."