Linux – Differential backup with TAR relative to specific weekday

backuplinuxtar

I want to have the following backup cycle on Debian Lenny:

Monday   : Full backup
Tuesday  : Differential backup relative to Monday
Wednesday: Differential backup relative to Monday
Thursday : Differential backup relative to Monday
Friday   : Differential backup relative to Monday
Saturday : Differential backup relative to Monday
Sunday   : Differential backup relative to Monday

Right now I use:

tar -czf /tmp/backup/all-sites-$(date +"%F").tar.gz --exclude '*/imagecache/*' --exclude '*/logs/*' /var/www/public_html/  > /tmp/backup/logfile 2>&1

Should I use --after-date or --newer option? If so, what is the syntax for those options?

The examples on Google / MAN pages makes me more confused that enlighten me.

Best Answer

I would use --newer. This checks the ctime, which any action on the files/directories in question will update. So this will catch any changes at all, even permissions changes, which is likely what you want. If you don't care about anything but actual modification of the files/directories, you can use --newer-mtime. On my system at least, --newer and --after-date are synonyms.

As far as syntax, you need to pass in a date string as an argument to the "--newer" flag. I typically do this by creating a file with the date of my last full backup when I do a full, which contains something like "20-Mar" (i.e. "date +%d-%b"), and then using that file to fill in the parameter when using --newer:

--newer `cat /path/to/datefile`
Related Topic