One new script and one amended script, first cab off the rank is an amended backup script.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash 
#(c) Keith Edwards, GLLUG, December 2011.
#    Additions from moggers87 
# shell script for use with rsync in user crontab.

USB_DIR="/media/backup" 
BACKUP_DIR="$USB_DIR/$(/bin/date +%Y%m%d)"

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 
fi

This works from users crontab and is run every 3 hours and backups to an external USB hardrive. It only keeps 15 of the backups, which is a fortnights worth + todays, and deletes the old ones.

This script takes the backup and compresses it to date.tar.gz, and is run from the users crontab twice a month on the 1st and the 15th after the last backup of the day.Its called compress.sh.

1
2
3
4
5
6
#!/bin/bash -x 
# by boudiccas July 2012 
# shell script for use with tar in user crontab

cd /media/backup 
date=$(date +%Y%m%d); /bin/tar -cvzf "$date.tar.gz" "$date">>/home/boztu/cron/log.txt 2>&1


Comments

comments powered by Disqus