logo

Pages


Erick’s Games

Faith

Older Games

Other Blogs

Posts

Categories

 

March 2009
S M T W T F S
« Feb   Apr »
1234567
891011121314
15161718192021
22232425262728
293031  



Comments

Administration

Quick and dirty guide to rsync

March 11, 2009

rsync is a software application for Unix systems which synchronizes files and directories from one location to another while minimizing data transfer using delta encoding when appropriate. (Thanks, Wikipedia.) Since this is supposed to be a quick tutorial, we’ll skip the formal lecture and get on with some usage examples.

1) sync a whole directory from one location on the local filesystem to another, while keeping all metadata such as ownership and permissions in tact:

rsync -azvrP /media/disk/source /home/user/destination

Important note: if source does not have a trailing slash, it will create the directory source/ inside destination/ — if it does have a trailing slash, it will copy only the contents of source but not source/ itself. This is similar to `cp /source` vs. `cp /source/*`

2) sync from a local machine over ssh to a remote server

rsync -zvrP /home/user/source user@10.10.10.100:

rsync uses ssh for remote connections by default, so there is nothing special you have to do besides the remote destination syntax which is identical to scp. (Obviously, sshd must be running on the server.) In this example there is nothing after the colon, meaning it defaults to the user’s home directory.

3) sync from a local machine over ssh to a remote server on a non-standard ssh port to a non-home directory

rsync -e ’ssh -p 12345′ -zvrP /home/user/source root@10.10.10.100:/usr/local/

The -e flag takes a string identical to what you would use if you were using ssh manually. In this example, ’ssh -p 12345′ connects using port 12345 on the server. The other difference is the destination directory on the end of the remote IP. To copy from a server to yourself, simply reverse source and destination.

4) sync one directory to another, except for files ending in .iso and .img

rsync zvrP –exclude ‘*.iso’ –exclude ‘*.img’ /home/user/source /media/destination/

Nothing new here except for the –exclude option. (Those are TWO dashes, not one! Wordpress likes to change things without my permission.) This is useful for when you’re backing up a directory but don’t care to transfer huge files that you can easily re-download. For more details about fine-grained exclusion, see the rsync man page.

Command line options
Personally, about 95% of my rsync usage is accomplished with -zvrP. Below is a quick table of all the options seen in the previous examples.

-a: archive (implies -rlptoD)
  -r: recursive
  -l: copy symlinks as symlinks
  -p: preserve permissions
  -t: preserve modification times
  -g: preserve group
  -o: preserve owner (root only)
  -D: (implies --devices --specials)
    --devices: recreates character/block devices
        (receiving end must be root)
    --specials: transfer special files like named sockets

-z: compress during transfer
-v: verbose
-r: recursive
-P:
  --partial: keep partially transferred files
  --progress: show progress during transfer

-e: specify the remote shell to use
--exclude: excludes files matching PATTERN
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Technorati

2 Responses to “Quick and dirty guide to rsync”

  1. 1
    brantNo Gravatar Says:

    Thanks for publishing this! I searched the web for “quick rsync guide” and found exactly what I needed here. =)

  2. 2
    Bookmarks for May 5th through June 14th | David.R.Gilson Says:

    [...] Quick and dirty guide to rsync | The Sillican Files – rsync is a software application for Unix systems which synchronizes files and directories from one location to another while minimizing data transfer using delta encoding when appropriate. (Thanks, Wikipedia.) Since this is supposed to be a quick tutorial, we’ll skip the formal lecture and get on with some usage examples. [...]

Leave a Reply

Google