Monday, July 15, 2013

rsync - a tool for synchronizing files

Rsync is a powerful Unix-type command line tool. I use it to backup my data. The rsync in Mac OX S is version 2.69. Today I upgrade it to version 3.09.

1. Download rsync source file rsync-3.0.9.tar.gz, extract and install:
    $ tar xzvf rsync-3.0.9.tar.gz
    $ cd rsync-3.0.9
    $ ./configure
    $ make 
    $ sudo make install
    It install rsync to /usr/local/bin, so need make a symbolic link:
    $ sudo mv /usr/bin/rsync rsync.old (change old rsync name)
    $ sudo ln -s /usr/local/bin/rsync /usr/bin/rsync

    2. Normally I use it mirror my data in iMac to the portable hard drive with:
    $ rsync -avhn --size-only --stats --delete --progress Source/ destination/ 
    •  -a option means archive mode, equals -rlptgoD options. It will recurse into directories and ensure  that  symbolic  links,  devices, attributes,  permissions,  ownerships,  etc.  are preserved in the transfer. Many times I needn't perserve owner and group information, so -rlt is ok.
    • -v verbose 
    • -h human readable output numbers 
    • -n dry run without actual backup. Had better run first with -n to see what changes will be made. Then delete -n option for actual backup.
    • -stats give some file-transfer stats. check it first before delete -n option.
    • --delete delete the files in destiantion but not in source. So do a mirror backup instead of an incremental backup.
    • --progress show progess during transfer.
    • should add slash in srouce folder and destiantion folder.  or some strange thing will happen :), such as a new folder is created.
    • --size-only, rsync compares modified time and size of the file in source and destination then decides if transfer the file. But in my use, it seems rsync copy some files that not change. So --size-only option can save time.

      No comments: