Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- exec > /home/kane/backup-logs/backup.sh.log
- clear
- echo "Backup beggining on `date`"
- echo "Getting mail backup from HERMES"
- 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/
- wait
- echo "Backing up to pool" #pool is the main storage pool at /mnt/pool
- echo "Backing up pictures"
- rsync -hrtvpogP --chown=kane:pool-rw --chmod=775 --temp-dir=/mnt/Downloads/tmp/rsync /mnt/pool/Pictures/ /mnt/pool/Backups/Pictures/
- wait
- echo "Backing up owncloud"
- rsync -hrtvpogP --chown=kane:pool-rw --chmod=775 --temp-dir=/mnt/Downloads/tmp/rsync --delete /mnt/pool/cloud/ /mnt/pool/Backups/cloud/
- wait
- echo "Backing up HELIOS"
- rsync -hrtvpogP --chown=kane:pool-rw --chmod=775 --temp-dir=/mnt/Downloads/tmp/rsync --delete /backup/* /mnt/pool/Backups/Computers/HELIOS/
- wait
- #If number of backups is greater than 4 delete the old backups
- BACKUPS=( /mnt/pool/Backups/Computers/HELIOS/*.tar.gz )
- while [ ${#BACKUPS[@]} -gt 4 ]
- do
- rm ${BACKUPS[0]}
- BACKUPS=( /mnt/pool/Backups/Computers/HELIOS/*.tar.gz )
- done
- #Log in to each machine via ssh and rsync backup tars
- SYSTEM=("administrator@HERMES" "administrator@HERA" "administrator@HEPHAESTUS" "administrator@CHRONOS" "administrator@ATLAS" "administrator@LOKI" "kane@HYRON" "administrator@VPS")
- for ((i = 0; i < ${#SYSTEM[@]}; i++))
- do
- DIR=$( echo "${SYSTEM[$i]}" | awk '{print substr($0,index($0,"@")+1)}' ) #get system name from user@system string
- echo "Backing up $DIR"
- rsync -htrvpogP --chown=kane:pool-rw --chmod=775 --temp-dir=/mnt/Downloads/tmp/rsync --delete ${SYSTEM[$i]}:/backup/* /mnt/pool/Backups/Computers/$DIR/
- wait
- BACKUPS=( /mnt/pool/Backups/Computers/$DIR/*.tar.gz )
- while [ ${#BACKUPS[@]} -gt 4 ]
- do
- rm ${BACKUPS[0]}
- BACKUPS=( /mnt/pool/Backups/Computers/$DIR/*.tar.gz )
- done
- done
- echo "Backing up virtual machines"
- #Get VM images from most recent weekly snapshot
- SNAP=(/mnt/Virtual/.zfs/snapshot/zfs-auto-snap_weekly*)
- LATEST=${SNAP[${#SNAP[@]} - 1]}
- rsync -hrtvpogP --chown=kane:pool-rw --chmod=775 --delete $LATEST/* /mnt/pool/Backups/Virtual\ Machines/
- wait
- #Do the same for HYRON
- SNAP=(`ssh root@hyron ls /.snapshot | grep 1w`)
- LATEST=${SNAP[${#SNAP[@]} - 1]}
- rsync -hrtvpogP --chown=kane:pool-rw --chmod=775 --delete root@10.10.1.220:/.snapshot/$LATEST/virtual/* /mnt/pool/Backups/Virtual\ Machines/
- wait
- echo "Backing up to local" #Local is the ZFS pool at /mnt/backups
- rsync -hrtvpogP --chown=kane:kane --chmod=775 --delete /mnt/pool/Backups/* /mnt/backups/
- wait
- echo
- echo "Backup Complete"
- echo
- echo "Beggining snapraid sync"
- sudo -u kane /home/kane/scripts/snapraid.sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement