Simple rsync Backup

This is a simple rsync backup that creates daily, monthly, and yearly incremental backups. This type of script would allow for recovery of just about any critical file going back many months or years. Very nice for a quick enterprise backup to impress your boss. I use it for my home web server. If the web server is hacked, the pages are protected under the www folder and will not be touched. Restore is a snap. Combine this with a great MySQL database backup and you are set.

# Author: Kevin Verhoeven
# Description: Script to backup data based on daily, monthly, and yearly increments
#
[ ! -f asof.dat ] && touch asof.dat
ATIME=$(stat -c "%y" asof.dat)

rm asof.dat
touch asof.dat
if [ `date +%e` -eq 1 ]; then
     date +%B >> asof.dat
fi
if [ `date +%Y` -gt ${ATIME:0:4} ]; then
      echo ${ATIME:0:4} >> asof.dat
fi
date +%A >> asof.dat
for i in $(cat asof.dat); do [ ! -d destination/$i/ ] && mkdir destination/$i/;touch destination/$i/rsyncbackup.log;rsync -av --stats "source/" "destination/$i/" > "destination/$i/rsyncbackup.log"; done

One comment

Leave a Reply