- "Data, Meet rsync."
- It's Time To Get in rsync
- That Secure Feeling
- Moving On
It's Time To Get in rsync
That's it. Now, it's time to put this setup to use. You might want to test out your rsync connection by issuing the following command (assuming a server called "sciserv): rsync remote_host::". Note the double colon at the end of the server's name. The result should be something like this:
$ rsync sciserv:: website All our websites mailman Mailman lists and archives marcel Backup area for Marcel
Now, let's pretend that I am on the server where my mailman files live (mailman is a mailing-list manager). Using the following command, I will launch rsync to back up this entire area. Because this is the first time, we see something like this:
$ rsync -av /home/mailman sciserv::mailman/ building file list ...
Depending on how big the directory you are copying is, this "building file list..." process might take a few minutes. Before we look at the results, I should tell you something about the flags used with the command. The "-v" for verbose is kind of a giveaway, but the simple "-a" hides some amount of complexity in that it is the same as using the "-rlptgoD" flags. In order, this means that rsync should do a recursive copy; copy symbolic links; preserve permissions, modification times, group and owner information; and with the final "D", copy special files (device and block). When you press Enter, files go scrolling by, after which you will see something like this:
mailman/tests/test_message.py mailman/tests/test_runners.py mailman/tests/test_safedict.py mailman/tests/test_security_mgr.py mailman/tests/testall.py wrote 85515773 bytes read 149192 bytes 482619.52 bytes/sec total size is 84949774 speedup is 0.99
I included the tail end of my mailman directory transfer, but at the end, you'll notice that rsync provides a synopsis of the data transferred and the rate at which it was sent. When I run rsync again a little later with only a few things changed in my mailing lists, the process is much faster because only those files that are changed are transferred. Consequently, I get the following results:
wrote 580445 bytes read 6326 bytes 31717.35 bytes/sec total size is 84950558 speedup is 144.78
If you wanted this whole process to happen magically, you could set up a cron job to run whenever you like, and your data would always be up-to-date. Just remove the "-v" flag from the command to keep the output quieter.
One other thing that rsync should be able to do in order to be completely useful is delete files. If you are mirroring files and directories from one system to another, it stands to reason that you want that mirror to represent exactly what is on the original. If files have been deleted, you want them deleted on the backup server as well. This is where the "--delete" parameter comes into play. Assume that I routinely backed up a directory called "system_info" and that I deleted a configuration file called "sys001.conf".
$ rsync -av --delete /home/marcel/system_info sciserv::marcel/ building file list ... done deleting system_info/sys001.conf system_info/ wrote 504 bytes read 40 bytes 43.52 bytes/sec total size is 55084 speedup is 101.26
Using the above command, any files that have been deleted in my directory will also be deleted on the remote server.