My backup script has been amended so that if the external USB hard drive ceases to be mounted for any reason then the script will send an email telling me so, and its been commented as well to explain what each section does. It now reads as -
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #!/usr/bin/env bash
# Keith Edwards, GLLUG, December 2011.
# Additions from moggers87
#shell script for use with rsync in user crontab
# Variables
USB_DIR="/media/backup/back"
BACKUP_DIR="$USB_DIR/$(/bin/date +%Y%m%d)"
EMAIL="[email protected]"
SUBJECT="Backup Error"
EMAIL_MESSAGE="Couldn't find $USB_DIR, are you sure its plugged in or mounted?"
# Backup files
if [ -d $USB_DIR ]; then
[ -d $BACKUP_DIR ] || mkdir $BACKUP_DIR \
>> /home/boztu/cron/backup.txt 2>&1
/usr/bin/rsync -avz \
--exclude-from '/home/boztu/cron/xclude.txt' \
/home/boztu/ $BACKUP_DIR \
>> /home/boztu/cron/backup.txt 2>&1
# Delete those old backups! Yeah!
(find $USB_DIR -maxdepth 1 -type d -name "20*" | sort | tail -n 15; \
find $USB_DIR -maxdepth 1 -type d -name "20*") | \
sort | uniq -u | xargs -n1 rm -rf \
>> /home/boztu/cron/backup.txt 2>&1
else
# Send an email
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAIL_MESSAGE
fi
|
And a new script to tell me my ip address and route in a file which is useful for running a gobby session, which looks like this and is run from a cron job at midday each day -
1 2 3 4 5 | #!/usr/bin/env bash
# boudiccas july 2012
# to be run from the users cron to determine the ip route
curl ifconfig.me>>/home/boztu/cron/ip.txt
|
Comments
comments powered by Disqus