#!/bin/bash
BKPATH="/whatever/you/want"
YEAR=$(date '+%Y')
MONTH=$(date '+%m')
DAY=$(date '+%d')
ROTATE_DAY="30"
#THIS FUNCTION WILL DELETE ANY FILES AND DIRECTORIES OLDER THAN THE VALUE
#DEFINED IN $ROTATE_DAY
function delete_old () {
find $BKPATH/mail $BKPATH/logs* -type f -mtime +$1 -exec rm {} \;
find $BKPATH/mail $BKPATH//logs* -depth -type d -empty -exec rmdir {} \;
}
#THIS FUNCTION PERFORMS THE BACKUP
function do_backup () {
mkdir -p $BKPATH/mail/$YEAR/$MONTH/$DAY #make directory
mkdir -p $BKPATH/logs/$YEAR/$MONTH/$DAY
mkdir -p $BKPATH/system
nice -n19 tar czf $BKPATH/mail/$YEAR/$MONTH/$DAY/matt_mail.tgz /home/matt/Maildir >/dev/null 2>&1
nice -n19 tar cvzf $BKPATH/logs/$YEAR/$MONTH/$DAY/logs.tgz /var/log >/dev/null 2>&1
rsync -rq /home/ $BKPATH/system/home/
rsync -rq /etc/ $BKPATH/system/etc/
rsync -rq /usr/local/bin $BKPATH/system/usrlocal/
rsync -rq /root $BKPATH/system/root/
}
delete_old $ROTATE_DAY
do_backup
A reference and information dump of a politics, technology, marketing, and media junky.
Saturday, January 27, 2007
My Backup Script
I use it to backup my home server: