Just a quick gem I thought I share with you on how I use rsync to keep my servers backuped. Since the more recent versions of rsync you can list multiple directories (or folders) in the same (single) command. For this to work you need the -R option though. Here’s an example of my daily rsync command, backing up all important files:
Folders to backup
Below is a list of folders I find important to backup. Yours may vary:
- Some misc backups
- The web root for all sites
- Since this contains all relevant config files, I want to back this up!
- All users home folders
Here’s the rsync line I’m using to transfer multiple directories to the remote server in a single command:
[code wraplines="true"]rsync -avzR --log-file=/var/log/rsync.cron.log -e ssh /var/www /home /var/backups /etc [user]@[somedestination]:[remote_path][/code]
Note the -R option here to allow us to list multiple directories in a single command. The -log-file option is for my own sanity and to track down any errors by logging rsync messages in a new log file.
Rsync options and explanations
Here’s an explanation of the various options I use (these are case-sensitive):
- archive mode
- verbose output (tell rsync to let me know what’s going on)
- compress file data during the transfer
- use relative paths
- specify the remote shell to use (in my case ssh)
More details and further options can be found on the rsync man page.