Linux: rsync Tutorial
rsync is a command line util that lets you do one-way copying/updating from one machine to another.
The remote machine must also have rsync installed. (it's installed by default in linux)
# copy the local dir # ~/web/ # to the remote dir # ~/ # on the machine with domain name “example.org”, using login joe # via the ssh protocol rsync -z -a -v -t --rsh="ssh -l joe" ~/web/ firstname.lastname@example.org:~/
Here's what the options mean:
Archived mode, basically making the file's meta data (owner/perm/timestamp) same as the local file (when possible) and do recursive (i.e. Upload the whole dir).
Tip: use this ONLY between linux and Mac machines. Because Windows and unix have different file permission systems. [see Linux: File Permission System] If any machine is Microsoft Windows, use
- “recursive”, all sub directories and files
- Use compression for transmission. (compress files first, transmit, uncompress. This saves bandwidth.)
- Verbose mode. Print out which files is being updated.
Copy timestamp from source to destination. If you don't, rsync will basically update every file. Timestamp is used by rsync to check if file's been updated.
Ignore file names that matches glob_pattern in source directory. (i.e. If it matches, don't upload it, nor delete it on remote server) For example,
*.javacmeans all files ending in
- If a file/dir in destination is not in source directory, delete it.
rsync on windows path
on Microsoft Windows, the path with drive letter
should be replaced by
# rsync example. sync/upload my website on my local machine to my web server # but use --exclude to exclude some dir or files on source dir # use --delete to delete files on target that are not in source rsync -z -a -v -t --exclude="*~" --exclude=".DS_Store" --exclude=".bash_history" --exclude="*/_curves_robert_yates/*.png" --exclude="logs/*" --exclude="xlogs/*" --delete --rsh="ssh -l joe" ~/web/ email@example.com:~/
# rsync from Windows to Mac # use -r instead -a rsync -z -r -v --delete --rsh="ssh -l xah" ~/web/ firstname.lastname@example.org:~/web/
rsync remote to local
Here's a example of reverse direction.
rsync -z -a -v -t --rsh="ssh -l joe" email@example.com:~/web/ ~/
This will get everything from the remote machine, to local machine.