Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #-------------------------------------------------------------------------#
- # Written by: Christopher Stobie #
- # email: cstobie@esi-estech.com #
- # email: cjstobie@gmail.com #
- #-------------------------------------------------------------------------#
- # Note: To add more hosts/dst/dir just edit .rsync.txt and follow the syntax separating each by |
- # eg: newhost.com|/root/src.dir|/home/backup.dir
- mail="vchan@esi-estech.com, pvazquez@esi-estech.com, cstobie@esi-estech.com, dthompson@esi-estech.com"
- mapfile -t dst < /root/scripts/.dst.txt
- date=$(date +"%d-%m-%Y")
- count="1"
- spacer_func () {
- printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
- }
- do_rsync () {
- if [[ $# == 0 ]]
- then
- echo "No arguments supplied, script failure" >> /var/log/backups/file-backup.$date
- exit 1
- fi
- rsync -qv -s --stats -Rza --safe-links --exclude '*.core' --exclude='core.*' "$@"
- }
- if [[ -d /var/log/backups ]]
- then
- find /var/log/backups -maxdepth 1 -type f -exec mv -t /var/log/backups/old {} +
- find /var/log/backups -type f -ctime +7 -delete
- fi
- for i in "${dst[@]}"; do
- if [[ ! -d $i ]]
- then
- mkdir -p $i
- fi
- done
- while IFS='|' read -r host src dst; do
- echo -e "Report from: $host \n$host$src $dst"; spacer_func; do_rsync cstobie@$host$src $dst; spacer_func; echo -e "\n"
- done < /root/scripts/.rsync.txt &>/var/log/backups/file-backup.$date
- if [[ $? == 0 ]]
- then
- if [[ -f /var/log/backups/file-backup.$date ]]
- then
- mail -s 'Backup Report | file-backup.sh' $mail < /var/log/backups/file-backup.$date
- else
- 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
- fi
- else
- echo -e "The file-backup.sh script has failed. Please check `hostname` and investigate"| mail -s "file-backup.sh script failure" $mail
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement