Rsync
servidor rsync

Rsync tutorial
http://www.fredshack.com/docs/rsync.html
Home
Last modif ied: 23-02-2007
Rsync tutorial
What is Rsync?
Rsy nc is a v ery usef ul alternativ e to rcp written by Andrew Tridgell and Paul Mackerras. This tool lets y ou copy
f iles and directories between a local host and a remote host (source and destination can also be local if y ou need.)
The main adv antage of using Rsy nc instead of rcp, is that rsy nc can use SSH as a secure channel, send/receiv e
only the by tes inside f iles that changed since the last replication, and remov e f iles on the destination host if those
f iles were deleted on the source host to keep both hosts in sy nc. In addition to using rcp/ssh f or transport, y ou can
also use Rsy nc itself , in which case y ou will connect to TCP port 873.
Whether y ou rely on SSH or use Rsy nc explicitely , Rsy nc still needs to be installed on both hosts. A Win32 port is
av ailable if y ou need, so y ou can hav e either one of the host or both be NT hosts. Rsy nc's web site has some
good inf os and links. There is also an HOWTO.
Configuring /etc/rsyncd.conf
Being co-written by Andrew Tridgell, author of Samba, it's no surprise that Rsy nc's conf iguration f ile looks just like
Samba (and Windows' :-), and that Rsy nc lets y ou create projects that look like shared directories under Samba.
Accessing remote resources through this indirect channel of f ers more independence, as it lets y ou mov e f iles on
the source Rsy nc serv er without changing any thing on the destination host.
Any parameters listed bef ore any [module] section are global, def ault parameters.
Each module is a sy mbolic name f or a directory on the local host. Here's an example:
#/etc/rsyncd.conf
secrets file = /etc/rsyncd.secrets
motd file = /etc/rsyncd.motd #Below are actually defaults, but to be on the safe
side...
read only = yes
list = yes
uid = nobody
gid = nobody
[out]
comment = Great stuff from remote.acme.com
path = /home/rsync/out
[confidential]
comment = For your eyes only
path = /home/rsync/secret-out
auth users = joe,jane
hosts allow = *.acme.com
hosts deny = *
list = false
1 de 4
16/07/10 09:17
Rsync tutorial
http://www.fredshack.com/docs/rsync.html
Note: Rsy nc will not grant access to a protected share if the password f ile (/etc/rsy ncd.secrets, here) is world-
readable.
Running RSYNCd
Per the manual page:
The rsy nc daemon is launched by specif y ing the --daemon option to rsy nc. You can launch it either
v ia inetd or as a stand-alone daemon. When run v ia inetd y ou should add a line like this to
/etc/services:
rsync 873/tcp
... and a single line something like this to /etc/inetd.conf:
rsync stream tcp nowait root /usr/bin/rsync rsyncd --daemon
You will then need to send inetd a HUP signal to tell it to reread its conf ig f ile. Note that y ou should
not send the rsy nc serv er a HUP signal to f orce it to reread the /etc/rsyncd.conf. The f ile is
re-read on each client connection.
Per the HOWTO:
The rsy nc daemon is robust, so it is saf e to launch it as a stand-alone serv er. The code that loops
waiting f or requests is only a f ew lines long then it f orks a new copy . If the f orked process dies then
it doesn't harm the main daemon.
The big adv antage of running as a daemon will come when the planned directory cache sy stem is
implemented. The caching sy stem will probably only be enable when running as a daemon. For this
reason, busy sites is recommended to run rsy nc as a daemon. Also, the daemon mode makes it
easy to limit the number of concurrent connections.
Since it's not included in the 2.4.3 RPM package, here's the init script to be copied as /etc/rc.d/init.d/rsyncd
with sy mlinks to /etc/rc.d/rc3.d:
#!/bin/sh
# Rsyncd This shell script takes care of starting and stopping the rsync daemon
# description: Rsync is an awesome replication tool.
# Source function library.
. /etc/rc.d/init.d/functions
[ -f /usr/bin/rsync ] || exit 0
case "$1" in
start)
action "Starting rsyncd: " /usr/bin/rsync --daemon
;;
stop)
action "Stopping rsyncd: " killall rsync
;;
*)
2 de 4
16/07/10 09:17
Rsync tutorial
http://www.fredshack.com/docs/rsync.html
echo "Usage: rsyncd {start|stop}"
exit 1
esac
exit 0
Here's an example under Linux on how to set up a replication through SSH:
rsync -avz -e ssh rsync@remote.acme.com:/home/rsync/out/ /home/rsync/from_remote
An important thing here, is that the presence or absence of a trailing "/" in the source directory determines whether
the directory itself is copied, or simply the contents of this source directory .
In other words, the abov e means that the local host must hav e a directory av ailable (here, /home/rsync
/from_remote to receiv e the contents of /home/rsync/out sitting on the remote host, otherwise Rsy nc will happily
download all f iles into the path giv en as destination without asking f or conf irmation, and y ou could end up with a big
mess.
On the other hand, rsync -avz -e ssh rsync@remote.acme.com:/home/rsync/out /home/rsync/from_remote
means that the an "out" sub-directory is f irst created under /home/rsync/from_remote on the destination host, and
will be populated with the contents of the remote directory ./out. In this case, f iles will be sav e on the local host in
/home/rsync/from_remote/out, so the f ormer commands looks like a better choice.
Here's how to replicate an Rsy nc share f rom a remote host:
rsync -avz rsync@remote.acme.com::out /home/rsync/in
Notice that we do not use a path to giv e the source resource, but instead just a name ("out"), and that we use :: to
separate the serv er's name and the resource it of f ers. In the Rsy nc conf iguration that we'll see just below, this is
shown as a [out] section. This way , admins on remote.acme.com can mov e f iles on their serv er; As long as they
remember to update the actual path in the [out] section (eg. PATH=/home/rsync/out to PATH=/home/outgoing),
remote Rsy nc users are not af f ected.
An Rsy nc serv er display s the list of av ailable anony mous shares through rsync remote.acme.com::. Note the
::. For added security , it is possible to prompt f or a password when listing priv ate shares, so that only authorized
remote users know about the Rsy nc shares av ailable f rom y our serv er.
Any NT version?
The NT port only requires the latest and greatest RSYNCx.EXE and Cy gnus' CYGWIN1.DLL. The easiest is to keep
both in the same directory , but the DLL can be located in any directory f ound in y our PATH env ironment v ariable.
Robert Scholte's excellent tutorial on using the NT port of Rsy nc can be f ound here.
Instructions on how to install rsy nc as an NT serv ice are here.
Here's an example based on the sample abov e:
C:\Rsync>rsync243 -avz joe@linux.acme.com::confidential ./confidential
Password:
receiving file list ... done
./
./
wrote 109 bytes read 123 bytes 66.29 bytes/sec
3 de 4
16/07/10 09:17
Rsync tutorial
http://www.fredshack.com/docs/rsync.html
total size is 0 speedup is 0.00
Useful com m and-line sw itches
-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
Resources
http://members.ozemail.com.au/~mstev eb/rsy nc/
http://www.ccp14.ac.uk/ccp14admin/rsy nc/
http://optics.ph.unimelb.edu.au/help/rsy nc/
http://sunsite.dk/SunSITE/guides/rsy nc/
http://sunsite.dk/SunSITE/guides/rsy nc/rsy nc-mirroring02.html
f tp://f tp.minn.net/usr/mmchen/
http://www.uwsg.indiana.edu/security /rsy nc.html
http://f ilewatcher.org/sec/rsy nc.html
http://f reeos.com/printer.php?entry ID=4042
A Tutorial on Using rsy nc
Rsnapshot (higher-lev el backup utility based on rsy nc, improv ed ease-of -use, allows y ou to keep multiple
snapshots in time of y our data, local or remote)
4 de 4
16/07/10 09:17

