The rsync utility is a fancy way to synchronize files and directories, either locally or across a network. We like to use it to make backups so we don’t have to worry when we mess something up. Yes, we could use cp or something equally boring, but we like the speed and flexibility of rsync. In this example, we’re copying files locally, but we could as easily be making remote backups to another server somewhere else.
1. | mkdir ~/.BACKUPDIR
Create a directory to house your backups. Ideally, you’ll create the directory on a different physical disk from the stuff you’re backing up, but do what you can. We’re creating a backup directory that’s a subdirectory of the home directory, which will help protect us against self-inflicted damages but not against a disk failure. (We trust the system administrator for protecting against disk failures...er, Eric, you are up-to-date on our backups, aren’t you?!) | |
2. | rsync -v -a /home/jdoe/data ~/
→ .BACKUPDIR
Specify the rsync command, the –v (for verbose) and –a (for archive) options, and the source and destination directories (Code Listing 17.8). Code Listing 17.8. The rsync utility is a handy tool for making backups. Note that it takes much less time for all updates after the first one.
|
✓ Tips
If rsync isn’t available on your system, revisit Chapter 14 to learn how to install it.
When you subsequently run rsync, you’ll discover that it’s far faster because it copies only the files that have changed. Handy, huh?
You can gain benefits from rsync if you start making backups across a network. For example, you can synchronize your Web server content with your friend’s content located on a different server. Check the rsync man page (man rsync) for the specifics.