#!/bin/bash -x # # This script uses mailx, which doesn't require a MTA (like postfix) to be # running. Create a ~/.mailrc file like this: # # set v15-compat # account gmail { # set smtp-use-starttls # set smtp-auth=login # set from="Your Name " # set mta=smtp://USER:PASSWORD@smtp.gmail.com:587 # } # # And then `chmod 600` the file so others can't see your password. # Directory on THIS computer to back up BACKUP=/home/anna/ # File containing directories and patterns to exclude (relative to $BACKUP) EXCLUDE=/home/anna/.config/backup.xclude # Name of backup server to use SERVER=cheesecake # Path where the backup will be placed # Note that this is on the client, using autofs BACKUP_DIRECTORY=/net/cheesecake/backups/`hostname -f` # Path on this machine where output should be written LOG=/tmp/backup.log # Address that will receive the email EMAIL_TO=schumaker.anna@gmail.com df -h -x rootfs -x tmpfs -x devtmpfs > $LOG echo "" >> $LOG function send_email { mailx -A gmail -s "Backup report: `hostname -f`" $EMAIL_TO < $LOG }; trap "send_email" EXIT nc -z -w 10 $SERVER 2049 if [ $? != 0 ]; then echo "$SERVER can't be found!" >> $LOG exit 1 fi rsync -axvhz --inplace --delete-delay --delete-excluded --exclude-from=$EXCLUDE $BACKUP $BACKUP_DIRECTORY >> $LOG notify-send "Backup finished!"