PageRenderTime 26ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/zfsonlinux/zfs
Korn Shell | 93 lines | 38 code | 14 blank | 41 comment | 11 complexity | 80367dd18777014d68f8bb213be6ee27 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 2007 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/include/libtest.shlib
  30. #
  31. # DESCRIPTION:
  32. # 'zfs recv -F' to force rollback.
  33. #
  34. # STRATEGY:
  35. # 1. Create pool and fs.
  36. # 2. Create some files in fs and take a snapshot1.
  37. # 3. Create another files in fs and take snapshot2.
  38. # 4. Create incremental stream from snapshot1 to snapshot2.
  39. # 5. fs rollback to snapshot1 and modify fs.
  40. # 6. Verify 'zfs recv -F' can force rollback.
  41. #
  42. verify_runnable "both"
  43. function cleanup
  44. {
  45. for snap in $snap2 $snap1; do
  46. datasetexists $snap && log_must zfs destroy -rf $snap
  47. done
  48. for file in $ibackup $mntpnt/file1 $mntpnt/file2; do
  49. [[ -f $file ]] && log_must rm -f $file
  50. done
  51. }
  52. log_assert "'zfs recv -F' to force rollback."
  53. log_onexit cleanup
  54. ibackup=$TEST_BASE_DIR/ibackup.$$
  55. fs=$TESTPOOL/$TESTFS; snap1=$fs@snap1; snap2=$fs@snap2
  56. mntpnt=$(get_prop mountpoint $fs) || log_fail "get_prop mountpoint $fs"
  57. log_must mkfile 10m $mntpnt/file1
  58. log_must zfs snapshot $snap1
  59. log_must mkfile 10m $mntpnt/file2
  60. log_must zfs snapshot $snap2
  61. log_must eval "zfs send -i $snap1 $snap2 > $ibackup"
  62. log_note "Verify 'zfs receive' succeed, if filesystem was not modified."
  63. log_must zfs rollback -r $snap1
  64. log_must eval "zfs receive $fs < $ibackup"
  65. if [[ ! -f $mntpnt/file1 || ! -f $mntpnt/file2 ]]; then
  66. log_fail "'zfs receive' failed."
  67. fi
  68. log_note "Verify 'zfs receive' failed if filesystem was modified."
  69. log_must zfs rollback -r $snap1
  70. log_must rm -rf $mntpnt/file1
  71. log_mustnot eval "zfs receive $fs < $ibackup"
  72. # Verify 'zfs receive -F' to force rollback whatever filesystem was modified.
  73. log_must zfs rollback -r $snap1
  74. log_must rm -rf $mntpnt/file1
  75. log_must eval "zfs receive -F $fs < $ibackup"
  76. if [[ ! -f $mntpnt/file1 || ! -f $mntpnt/file2 ]]; then
  77. log_fail "'zfs receive -F' failed."
  78. fi
  79. log_pass "'zfs recv -F' to force rollback passed."