Advertisement
Guest User

Untitled

a guest
Nov 14th, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.02 KB | None | 0 0
  1. #!/bin/bash
  2. #-------------------------------------------------------------------------#
  3. #                    Written by: Christopher Stobie                       #
  4. #                    email: cstobie@esi-estech.com                        #
  5. #                    email: cjstobie@gmail.com                            #
  6. #-------------------------------------------------------------------------#
  7. # Note: To add more hosts/dst/dir just edit .rsync.txt and follow the syntax separating each by |
  8. # eg: newhost.com|/root/src.dir|/home/backup.dir
  9. mail="vchan@esi-estech.com, pvazquez@esi-estech.com, cstobie@esi-estech.com, dthompson@esi-estech.com"
  10. mapfile -t dst < /root/scripts/.dst.txt
  11. date=$(date +"%d-%m-%Y")
  12. count="1"
  13.  
  14. spacer_func () {
  15. printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
  16. }
  17.  
  18. do_rsync () {
  19. if [[ $# == 0 ]]
  20.  then
  21.    echo "No arguments supplied, script failure" >> /var/log/backups/file-backup.$date
  22.    exit 1
  23. fi
  24. rsync -qv -s --stats -Rza --safe-links --exclude '*.core' --exclude='core.*' "$@"
  25. }
  26.  
  27. if [[ -d /var/log/backups ]]
  28.  then
  29.   find /var/log/backups -maxdepth 1 -type f -exec mv -t /var/log/backups/old {} +
  30.   find /var/log/backups -type f -ctime +7 -delete
  31. fi
  32.  
  33. for i in "${dst[@]}"; do
  34.  if [[ ! -d $i ]]
  35.    then
  36.      mkdir -p $i
  37.  fi
  38. done
  39.  
  40. while IFS='|'  read -r host src dst; do
  41.   echo -e "Report from: $host \n$host$src  $dst"; spacer_func;  do_rsync cstobie@$host$src $dst; spacer_func; echo -e "\n"
  42. done < /root/scripts/.rsync.txt &>/var/log/backups/file-backup.$date
  43.  
  44. if [[ $? == 0 ]]
  45.  then
  46.    if [[ -f /var/log/backups/file-backup.$date ]]
  47.     then
  48.      mail -s 'Backup Report | file-backup.sh' $mail < /var/log/backups/file-backup.$date
  49.     else
  50.       echo -e "There could be something wrong\n We could not find a backup log file\n Check host `hostname` for further details" | mail -s "Backup Report | file-backup log NOT found" $mail
  51.    fi
  52.  else
  53.    echo -e "The file-backup.sh script has failed. Please check `hostname` and investigate"| mail -s "file-backup.sh script failure" $mail
  54. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement