Advertisement
Guest User

backup.sh

a guest
Dec 30th, 2016
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.73 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. exec > /home/kane/backup-logs/backup.sh.log
  4.  
  5. clear
  6.  
  7. echo "Backup beggining on `date`"
  8.  
  9. echo "Getting mail backup from HERMES"
  10. rsync -va --chown=kane:pool-rw --chmod=775 --temp-dir=/mnt/Downloads/tmp/rsync administrator@hermes:/home/administrator/backup/mail.tar /mnt/pool/Backups/HERMES/mail/
  11. wait
  12.  
  13. echo "Backing up to pool" #pool is the main storage pool at /mnt/pool
  14. echo "Backing up pictures"
  15. rsync -hrtvpogP --chown=kane:pool-rw --chmod=775 --temp-dir=/mnt/Downloads/tmp/rsync /mnt/pool/Pictures/ /mnt/pool/Backups/Pictures/
  16. wait
  17. echo "Backing up owncloud"
  18. rsync -hrtvpogP --chown=kane:pool-rw --chmod=775 --temp-dir=/mnt/Downloads/tmp/rsync --delete /mnt/pool/cloud/ /mnt/pool/Backups/cloud/
  19. wait
  20. echo "Backing up HELIOS"
  21. rsync -hrtvpogP --chown=kane:pool-rw --chmod=775 --temp-dir=/mnt/Downloads/tmp/rsync --delete /backup/* /mnt/pool/Backups/Computers/HELIOS/
  22. wait
  23. #If number of backups is greater than 4 delete the old backups
  24. BACKUPS=( /mnt/pool/Backups/Computers/HELIOS/*.tar.gz )
  25.         while [ ${#BACKUPS[@]} -gt 4 ]
  26.         do
  27.                 rm ${BACKUPS[0]}
  28.                 BACKUPS=( /mnt/pool/Backups/Computers/HELIOS/*.tar.gz )
  29.         done
  30.  
  31. #Log in to each machine via ssh and rsync backup tars
  32. SYSTEM=("administrator@HERMES" "administrator@HERA" "administrator@HEPHAESTUS" "administrator@CHRONOS" "administrator@ATLAS" "administrator@LOKI" "kane@HYRON" "administrator@VPS")
  33. for ((i = 0; i < ${#SYSTEM[@]}; i++))
  34. do
  35.     DIR=$( echo "${SYSTEM[$i]}" | awk '{print substr($0,index($0,"@")+1)}' ) #get system name from user@system string
  36.     echo "Backing up $DIR"
  37.     rsync -htrvpogP --chown=kane:pool-rw --chmod=775 --temp-dir=/mnt/Downloads/tmp/rsync --delete ${SYSTEM[$i]}:/backup/* /mnt/pool/Backups/Computers/$DIR/
  38.     wait
  39.     BACKUPS=( /mnt/pool/Backups/Computers/$DIR/*.tar.gz )
  40.     while [ ${#BACKUPS[@]} -gt 4 ]
  41.     do
  42.         rm ${BACKUPS[0]}
  43.         BACKUPS=( /mnt/pool/Backups/Computers/$DIR/*.tar.gz )
  44.     done
  45. done
  46.  
  47. echo "Backing up virtual machines"
  48. #Get VM images from most recent weekly snapshot
  49. SNAP=(/mnt/Virtual/.zfs/snapshot/zfs-auto-snap_weekly*)
  50. LATEST=${SNAP[${#SNAP[@]} - 1]}
  51.  
  52. rsync -hrtvpogP --chown=kane:pool-rw --chmod=775 --delete $LATEST/* /mnt/pool/Backups/Virtual\ Machines/
  53. wait
  54. #Do the same for HYRON
  55. SNAP=(`ssh root@hyron ls /.snapshot | grep 1w`)
  56. LATEST=${SNAP[${#SNAP[@]} - 1]}
  57.  
  58. rsync -hrtvpogP --chown=kane:pool-rw --chmod=775 --delete root@10.10.1.220:/.snapshot/$LATEST/virtual/* /mnt/pool/Backups/Virtual\ Machines/
  59. wait
  60.  
  61.  
  62. echo "Backing up to local" #Local is the ZFS pool at /mnt/backups
  63. rsync -hrtvpogP --chown=kane:kane --chmod=775 --delete /mnt/pool/Backups/* /mnt/backups/
  64. wait
  65.  
  66. echo
  67. echo "Backup Complete"
  68. echo
  69. echo "Beggining snapraid sync"
  70. sudo -u kane /home/kane/scripts/snapraid.sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement