User Tools

Site Tools


linux:sysadmin:cmd:rsync

rsync

Remote file copy - Synchronize file trees across local disks, directories or across a network. See http://www.fredshack.com/docs/rsync.html for more information.

Example

Sync over ssh with excludes

Synchronize live server with test server (executed from live server ⇒ load files to test server):

rsync -av --exclude '*.jpg' --exclude '*.JPG' --exclude '*.zip' --exclude '*/cache/*' --exclude '*.bak' --exclude '*.bz2' --exclude '*/sessions/*' /srv/www/ root@192.168.63.233:/srv/www/

Rsync Client/Server

Server Setup

On the server named wikiserver.local

  1. activate rsync deamon in xinet.d
    1. set “disable = no” in /etc/xinet.d/rsync
  2. edit or create /etc/rsyncd.conf
    [wiki-data]
    comment = wiki-export
    path = /srv/wiki/data
    read only = true
    list = true
    #uid = adminname
    #gid = adminname
    #auth users = adminname
    #hosts allow = 10.10.105.0/24

Sync from client

rsync -avz wikiserver.local::wiki-data /srv/wiki/data

Useful command-line switches

-v, --verbose increase verbosity
-q, --quiet decrease verbosity
-c, --checksum always checksum
-a, --archive archive mode.
      It is a quick way of saying you want recursion and want to preserve everything.
-r, --recursive recurse into directories
-R, --relative use relative path names
-u, --update update only (don't overwrite newer files)
-t, --times preserve times
-n, --dry-run show what would have been transferred
-W, --whole-file copy whole files, no incremental checks
-I, --ignore-times Normally rsync will skip any files that are already the same 
      length and have the same time-stamp. This option turns off this behavior.
--existing only update files that already exist
--delete delete files that don't exist on the sending side
--delete-after delete after transferring, not before
--force force deletion of directories even if not empty
-c, --checksum always checksum
--size-only only use file size when determining if a file should be transferred
--progress show progress during transfer
-z, --compress compress file data
--exclude=PATTERN exclude files matching PATTERN
--daemon run as a rsync daemon
--password-file=FILE get password from FILE
/srv/wiki.niwos.com/data/pages/linux/sysadmin/cmd/rsync.txt · Last modified: 2011/06/21 14:25 (external edit)