My backup script currently rsync's all files in users home dir and dumps a mysql file onto the backup hard drive.
Currently my file looks like this:
BACKUPDIR=`date +%d`'-'`date +%m`'-'`date +%y`'--'`date +%T`
chown acorn:acorn /backup/acornbackup/html/$BACKUPDIR
chmod 655 /backup/acornbackup/html/$BACKUPDIR
#Rsync data to new directory
rsync -a /home/acorn/ /backup/acornbackup/html/$BACKUPDIR/
chown acorn:acorn /backup/acornbackup/mysql/$BACKUPDIR
chmod 655 /backup/acornbackup/mysql/$BACKUPDIR
#Dump mysql data
mysqldump -uuser -ppass acorn_data > /backup/acornbackup/mysql/$BACKUPDIR/acorn_data.sql
chown acorn:acorn -R /backup/acornbackup/
chmod 655 -R /backup/acornbackup/
(the chmod 655 is because the backups are to be viewable from a browser until i setup a backup system)
What i want to do is keep the last days backups (if backups are done every 6 hours, the last 4).
Also i would like to further break it up into days (e.g when a day has passed the final backup is placed into a directory with just the date as a name) I would then like to keep the last 7 days worth of backups.
I can then expand it to include week directories, month directories and year directories, however once i know how to do the days ill be able to work out the rest.
Can anyone help or point me in the right direction on where to look for help?
Centation Web Services Bristol based web design
Offering website design, SEO, website hosting, website development and domain registration.
Are you doing backup mirrors every four hours? That seems a little wasteful of time and space. I would recommend doing a mirror backup every day, and then incremental backups (diffs) every four hours after that. You could easily do a mirror on even days (or even once a week) and then do incrementals in between your mirrors.
I personally use rdiff-backup, its extremely powerful and pretty easy to use.
The cron looks fine; but it is easier to use */6 instead of the comma-delimited numbers.
For the backups, what I would probably do is have one script run daily, and that script would delete the backup from 7 days ago. You could do this pretty eaisly in PHP.
Then I'd have another run weekly to put that backup into a separate directory. That sounds like the easiest thing to do.
I'd probably write the whole thing in php, since you can execute system calls in PHP. It depends which language you are most familiar with, but PHP is pretty good with dates, which you'd need to find which backup to delete.