PageRenderTime 28ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/zfsonlinux/zfs
Korn Shell | 176 lines | 105 code | 30 blank | 41 comment | 21 complexity | 10d44ae5001a3fb2683127227138725d 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) 2012, 2016 by Delphix. All rights reserved.
  28. #
  29. . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
  30. #
  31. # DESCRIPTION:
  32. # Verifying 'zfs receive [<filesystem|snapshot>] -d <filesystem>' works.
  33. #
  34. # STRATEGY:
  35. # 1. Fill in fs with some data
  36. # 2. Create full and incremental send stream
  37. # 3. Receive the send stream
  38. # 4. Verify the restoring results.
  39. #
  40. verify_runnable "both"
  41. function cleanup
  42. {
  43. typeset -i i=0
  44. datasetexists $rst_root && \
  45. log_must zfs destroy -Rf $rst_root
  46. while (( i < 2 )); do
  47. snapexists ${orig_snap[$i]} && \
  48. log_must zfs destroy -f ${orig_snap[$i]}
  49. log_must rm -f ${bkup[$i]}
  50. (( i = i + 1 ))
  51. done
  52. log_must rm -rf $TESTDIR1
  53. }
  54. function recreate_root
  55. {
  56. datasetexists $rst_root && \
  57. log_must zfs destroy -Rf $rst_root
  58. if [[ -d $TESTDIR1 ]] ; then
  59. log_must rm -rf $TESTDIR1
  60. fi
  61. log_must zfs create $rst_root
  62. log_must zfs set mountpoint=$TESTDIR1 $rst_root
  63. }
  64. log_assert "Verifying 'zfs receive [<filesystem|snapshot>] -d <filesystem>' works."
  65. log_onexit cleanup
  66. typeset datasets="$TESTPOOL/$TESTFS $TESTPOOL"
  67. set -A bkup "$TEST_BASE_DIR/fullbkup" "$TEST_BASE_DIR/incbkup"
  68. orig_sum=""
  69. rst_sum=""
  70. rst_root=$TESTPOOL/rst_ctr
  71. rst_fs=${rst_root}/$TESTFS
  72. for orig_fs in $datasets ; do
  73. #
  74. # Preparations for testing
  75. #
  76. recreate_root
  77. set -A orig_snap "${orig_fs}@init_snap" "${orig_fs}@inc_snap"
  78. typeset mntpnt=$(get_prop mountpoint ${orig_fs})
  79. set -A orig_data "${mntpnt}/$TESTFILE1" "${mntpnt}/$TESTFILE2"
  80. typeset relative_path=""
  81. if [[ ${orig_fs} == *"/"* ]]; then
  82. relative_path=${orig_fs#*/}
  83. fi
  84. typeset leaf_fs=${rst_root}/${relative_path}
  85. leaf_fs=${leaf_fs%/}
  86. rst_snap=${leaf_fs}@snap
  87. set -A rst_snap "$rst_root/$TESTFS@init_snap" "$rst_root/$TESTFS@inc_snap"
  88. set -A rst_snap2 "${leaf_fs}@init_snap" "${leaf_fs}@inc_snap"
  89. set -A rst_data "$TESTDIR1/$TESTFS/$TESTFILE1" "$TESTDIR1/$TESTFS/$TESTFILE2"
  90. set -A rst_data2 "$TESTDIR1/${relative_path}/$TESTFILE1" "$TESTDIR1/${relative_path}/$TESTFILE2"
  91. typeset -i i=0
  92. while (( i < ${#orig_snap[*]} )); do
  93. file_write -o create -f ${orig_data[$i]} -b 512 \
  94. -c 8 >/dev/null 2>&1
  95. (( $? != 0 )) && \
  96. log_fail "Writing data into zfs filesystem fails."
  97. log_must zfs snapshot ${orig_snap[$i]}
  98. if (( i < 1 )); then
  99. log_must eval "zfs send ${orig_snap[$i]} > ${bkup[$i]}"
  100. else
  101. log_must eval "zfs send -i ${orig_snap[(( i - 1 ))]} \
  102. ${orig_snap[$i]} > ${bkup[$i]}"
  103. fi
  104. (( i = i + 1 ))
  105. done
  106. log_note "Verifying 'zfs receive <filesystem>' works."
  107. i=0
  108. while (( i < ${#bkup[*]} )); do
  109. if (( i > 0 )); then
  110. log_must zfs rollback ${rst_snap[0]}
  111. fi
  112. log_must eval "zfs receive $rst_fs < ${bkup[$i]}"
  113. snapexists ${rst_snap[$i]} || \
  114. log_fail "Restoring filesystem fails. ${rst_snap[$i]} not exist"
  115. compare_cksum ${orig_data[$i]} ${rst_data[$i]}
  116. (( i = i + 1 ))
  117. done
  118. log_must zfs destroy -Rf $rst_fs
  119. log_note "Verifying 'zfs receive <snapshot>' works."
  120. i=0
  121. while (( i < ${#bkup[*]} )); do
  122. if (( i > 0 )); then
  123. log_must zfs rollback ${rst_snap[0]}
  124. fi
  125. log_must eval "zfs receive ${rst_snap[$i]} <${bkup[$i]}"
  126. snapexists ${rst_snap[$i]} || \
  127. log_fail "Restoring filesystem fails. ${rst_snap[$i]} not exist"
  128. compare_cksum ${orig_data[$i]} ${rst_data[$i]}
  129. (( i = i + 1 ))
  130. done
  131. log_must zfs destroy -Rf $rst_fs
  132. log_note "Verifying 'zfs receive -d <filesystem>' works."
  133. i=0
  134. while (( i < ${#bkup[*]} )); do
  135. if (( i > 0 )); then
  136. log_must zfs rollback ${rst_snap2[0]}
  137. fi
  138. log_must eval "zfs receive -d -F $rst_root <${bkup[$i]}"
  139. snapexists ${rst_snap2[$i]} || \
  140. log_fail "Restoring filesystem fails. ${rst_snap2[$i]} not exist"
  141. compare_cksum ${orig_data[$i]} ${rst_data2[$i]}
  142. (( i = i + 1 ))
  143. done
  144. cleanup
  145. done
  146. log_pass "Verifying 'zfs receive [<filesystem|snapshot>] -d <filesystem>' succeeds."