Tuesday, March 23, 2010

Using Rsync

Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied. It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use.

Let's begin with by creating Rsync backup server, here an /etc/rsync.conf example configuration file

# rsync daemon configuration

uid = nobody
gid = nobody
use chroot = yes
max connections = 4
syslog facility = local5
pid file = /var/run/rsyncd.pid

uid = thinkpad
gid = thinkpad
path = /home/thinkpad/backup
comment = Thinkpad's backup directory
auth users = ajhwb
secrets file = /etc/rsyncd.secrets
read only = no

auth user is a comma separated list for user who will be accepted, you also need to provide secrets file when using this option. This a sample /etc/rsyncd.secrets file

# rsync secrets file
# format username:password for each line

In order to restricting another user to access this file, set it's file permission to

#chmod 600 /etc/rsyncd.secrets

If everything in set, we are ready to start rsync as daemon, for starting automatically use your system init startup script.

#rsync --daemon

This is a simple command used to backup (exactly is synchronizing) a directory into the server (in this case we use localhost)

rsync --azuv --delete --delete-after /hacking/rtpatch-2.4 ajhwb@localhost::ajhwb/rtpatch-2.4

To retrieve directory and it's contents

rsync --azuv --delete --delete-after ajhwb@localhost::ajhwb/rtpatch-2.4 /hacking/rtpatch-2.4

In this example, another host alternative format is rsync://ajhwb@localhost/ajhwb/rtpatch-2.4

Rsync is very flexible tool, comes with many options and interesting configurations, explore this by yourself. Happy syncing!

Rsync website http://rsync.samba.org/