Synchronizing a Web Site Directory

bible:~/www # rsync -avrz . www.palmcoder.net:/var/www/palmcoder/blogimages receiving file list ... done blogimages/

blogimages/DSCN0156.thumb.jpg blogimages/DSCN0191.thumb.jpg blogimages/DSCN0718.jpg blogimages/dscn0456.jpg blogimages/palmcoder.gif wrote 96 bytes read 92643 bytes 10910.47 bytes/sec total size is 96350 speedup is 1.04

You can see that we have chosen to copy a single small directory with multiple files. In this example, the rsync command uses the parameters -azrv that correspond to the following:

■ -a — Enables an archive mode that keeps all of the file attributes of the files you are copying.

■ -v — Verbose mode prints out so you can see the files you are copying.

■ -r — Recursive copying traverses the directory structure of the directory you are copying.

By default rsync uses the SSH protocol for transport. This means that, provided rsync is installed on the destination server and an SSH server is running, the preceding command works fine. If you copied the appropriate public key (without a passphrase) to the destination server, this command can be run without the need for a password, and could, for example, be run from a script.

-71 - - r xample, when specifying the server (www.palmcoder.net), we also specified

' - ~ ■"■> ■ the directory to copy over, separated by a colon (:). As we have not put a forward slash (/) at the end of the blogimages directory, rsync copies the directory and its contents to our local machine. If a forward slash were added to the directory specified, we would copy only the contents of the directory and not the directory itself. Be very wary about this because it is easy to copy something you were not expecting if you miss a forward slash.

If you want to make sure any files that were deleted from the originating server were actually deleted on the local machine when synchronized, you need to add the -delete parameter to the command-line options.

Was this article helpful?

0 0

Post a comment