Advertisement
Guest User

Untitled

a guest
Sep 10th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. #!/bin/bash -
  2.  
  3. ## UUID of the drive you wish to Backup too.
  4. DEVuuid="c9fb0697-7837-433c-af62-7991f052cc16"
  5. ## The Directory where you wish to mount the disk.
  6. DIRbck="/admin/backup"
  7. ## The directory which you wish to backup too.
  8. BCKdir="$DIRbck/`date +%Y%m%d`"
  9. ## The command to backup your system.
  10. CMDsfc="rsync -aAXv --exclude=/admin/* \
  11. --exclude=/dev/* \
  12. --exclude=/proc/* \
  13. --exclude=/sys/* \
  14. --exclude=/tmp/* \
  15. --exclude=/run/* \
  16. --exclude=/mnt/* \
  17. --exclude=/mnt2/* \
  18. --exclude=/media/* \
  19. --exclude=/lost+found"
  20.  
  21. ## Checking if you are root.
  22. root_sfc(){
  23. if [ "root" != "$USER" ]; then
  24. echo "You are not root!"
  25. exit 0
  26. fi
  27. }
  28.  
  29. ## Check the filesystems integrity.
  30. fsck_sfc(){
  31. echo "Running fsck $DEVdev"
  32. fsck -yV $DEVdev 2>&1
  33. backup_sfc
  34. }
  35.  
  36. ## Mounting the backup disk drive.
  37. mount_sfc(){
  38. if grep -qs "$DIRbck" /proc/mounts; then
  39. echo "$DIRbck is already mounted. It shouldn't be."
  40. echo "Exiting...."
  41. exit 0
  42. else
  43. echo "$DIRbck is not mounted. Attempting to mount $DEVdev to $DIRbck"
  44. mount $DEVdev $DIRbck
  45. if [ $? -eq 0 ]; then
  46. echo "$DEVdev mounted successfully to $DIRbck!"
  47. else
  48. echo "Something went wrong with the mount..."
  49. echo "Exiting...."
  50. exit 0
  51. fi
  52. fi
  53. }
  54.  
  55. ## Unmount the backup disk drive.
  56. umount_sfc(){
  57. if grep -qs "$DEVdev" /proc/mounts; then
  58. echo "$DEVdev is mounted. Attempting to unmount."
  59. umount $DEVdev
  60. if [ $? -eq 0 ]; then
  61. echo "$DEVdev unmounted successfully!"
  62. fsck_sfc
  63. else
  64. echo "Something went wrong with the mount..."
  65. exit 0
  66. fi
  67. else
  68. echo "$DEVdev is not mounted"
  69. fsck_sfc
  70. fi
  71. }
  72.  
  73. ## Final unmount of the backup disk drive after backup has completed.
  74. finalumount_sfc(){
  75. if grep -qs "$DEVdev" /proc/mounts; then
  76. echo "$DEVdev is mounted. Attempting to unmount."
  77. umount $DEVdev
  78. if [ $? -eq 0 ]; then
  79. echo "$DEVdev unmounted successfully!"
  80. exit 0
  81. else
  82. echo "Something went wrong with the mount..."
  83. exit 0
  84. fi
  85. else
  86. echo "$DEVdev is not mounted."
  87. echo "Backup was successful."
  88. exit 0
  89. fi
  90. }
  91.  
  92. ## Backup data to disk.
  93. backup_sfc(){
  94. mount_sfc
  95. if [ -d "$BCKdir" ]; then
  96. echo "Destination is $BCKdir. Hope that's ok."
  97. else
  98. mkdir $BCKdir
  99. echo "Created new destination as $BCKdir. Hope that's ok."
  100. fi
  101. echo -n "Backing up: "
  102. $CMDsfc / $BCKdir
  103. sync
  104. echo "done!"
  105. umount $DIRbck
  106. finalumount_sfc
  107. }
  108.  
  109. ## Check to see if the mount point exists.
  110. check_sfc(){
  111. root_sfc
  112. ## Find out which disk the UUID is associated with.
  113. DEVdev=`blkid | grep $DEVuuid | cut -d ":" -f 1`
  114. if [ -d "$DIRbck" ]; then
  115. echo "Mount point $DIRbck exists."
  116. umount_sfc
  117. else
  118. echo "Mount point $DIRbck doesn't exist. I will create it"
  119. mkdir -p $DIRbck
  120. fi
  121. check_sfc
  122. }
  123. check_sfc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement