Efficient Rotating Daily backups with rsync
Systems administrators typically use the date command in combination with cp -R to provide backup functionality. In a cronjob, the command
cp -R /path/to/backup /backup/destination/backup-`date +%u`
So what will this do? It will create seven distinct directories, one for each day of the week (1 through 7). When overwriting your old backups, you can either delete them first, or set cp to overwrite them. Neither is really optional.
Instead, if your backups don't change a lot, you can use rsync to help speed things up a bit. rsync is an open-source utility that provides fast incremental file transfer.
Instead of using cp, use rsync with two additional parameters: -av and --delete.
rsync -av --delete /path/to/backup /backup/destination/backup-`date +%u`
This has the advantage of needing to copy fewer files, since only the changes are copied over. Your backup from last week is likely to have 90% of files in common with the latest backup: so why waste time deleting the files which are the same.
Where can you go with this? Well, you can set up rsync to transfer files to a remote system without needing passwords. This is incredibly useful for doing your rotating backups to a remote system.
This is not a substitute for a long-term backup strategy. I also wouldn't recommend it for log files or similar groups of rapidly-rotated files. It is a fairly efficient solution for short-term backup needs, and provides a useful and quick way to have an offsite copy of your backup for disaster recovery or those oops moments. It's also useful for the files of CMS-powered sites, as user-submitted content tends only to accumulate.