Advertisement
Guest User

Untitled

a guest
Nov 16th, 2016
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. #!/bin/bash
  2. # Shutdown the VM
  3. # Cleanup existing files
  4. STARTING_DIR=$(pwd)
  5. rm -rf /mnt/test_backup/*
  6. rm -rf /mnt/test_restore/*
  7. ssh rb@192.168.1.2 "rm -rf /mnt/remote_backup/*"
  8.  
  9. echo "*********************"
  10. echo "($(date +%s)) Starting"
  11. echo "*********************"
  12.  
  13. #Variables
  14. VBOXUSER="vboxuser"
  15. VGROUP="jobVMHost-vg"
  16. LVOLUME="vm_images"
  17. SNAPSHOT_MNT="/mnt/snap_$LVOLUME"
  18. BACKUP_DIR="sftp://rb@192.168.1.2///mnt/remote_backup/jobVMHost_${LVOLUME}"
  19. RESTORE_DIR="/mnt/test_restore/restored_jobVMHost_vm_images"
  20.  
  21. #Create the snapshot
  22. echo "******************************"
  23. echo "($(date +%s)) Creating Snapshot"
  24. echo "******************************"
  25. lvcreate -L 20G -s -n snap_$LVOLUME /dev/$VGROUP/$LVOLUME
  26. mkdir $SNAPSHOT_MNT
  27.  
  28. echo "******************************"
  29. echo "($(date +%s)) Mounting Snapshot"
  30. echo "******************************"
  31. mount -o ro /dev/$VGROUP/snap_$LVOLUME $SNAPSHOT_MNT
  32. df -h $SNAPSHOT_MNT
  33.  
  34.  
  35. echo "**************************************"
  36. echo "($(date +%s)) Creating Initial Checksum"
  37. echo "**************************************"
  38. cd $SNAPSHOT_MNT
  39. hashdeep -rlc md5 * > $STARTING_DIR/checksums.txt
  40.  
  41. echo "*****************************************"
  42. echo "($(date +%s)) Running Duplicity for Backup"
  43. echo "*****************************************"
  44. echo "Checking space on remote server:"
  45. ssh rb@192.168.1.2 "df -h"
  46. export PASSPHRASE="testphrase"
  47. duplicity --tempdir /mnt/temp_storage --asynchronous-upload --volsize 256 -v8 $SNAPSHOT_MNT $BACKUP_DIR
  48.  
  49. echo "**********************"
  50. echo "($(date +%s)) Verifying"
  51. echo "**********************"
  52. df -h
  53. duplicity verify --tempdir /mnt/temp_storage --ignore-errors --num-retries 100 -v8 $BACKUP_DIR $SNAPSHOT_MNT
  54.  
  55.  
  56. echo "*************************"
  57. echo "($(date +%s)) Test Restore"
  58. echo "*************************"
  59. echo "Check space:"
  60. df -h
  61. duplicity restore --tempdir /mnt/temp_storage --num-retries 100 --ignore-errors -v8 $BACKUP_DIR $RESTORE_DIR
  62. unset PASSPHRASE
  63.  
  64. echo "************************************"
  65. echo "($(date +%s)) Check Restore Checksums"
  66. echo "************************************"
  67. cd $RESTORE_DIR
  68. hashdeep -ravvl -k $STARTING_DIR/checksums.txt *
  69.  
  70. echo "**********************************************"
  71. echo "($(date +%s)) Check Original Snapshot Checksums"
  72. echo "**********************************************"
  73. cd $SNAPSHOT_MNT
  74. hashdeep -ravvl -k $STARTING_DIR/checksums.txt *
  75.  
  76.  
  77. echo "**************************************************"
  78. echo "($(date +%s)) Unmount and remove snapshot mnt point"
  79. echo "**************************************************"
  80. umount -lfv $SNAPSHOT_MNT
  81. rm -rf $SNAPSHOT_MNT
  82.  
  83. echo "*******************************************"
  84. echo "($(date +%s)) Remove snapshot logical volume"
  85. echo "*******************************************"
  86. lvremove -f /dev/$VGROUP/$LVOLUME
  87.  
  88. echo "*************************"
  89. echo "($(date +%s)) All Complete"
  90. echo "*************************"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement