Skip to content

RSYNC

########### Remote Synchronization (RSYNC) ########
Installed by default
Sync remote and optionally local directories and or files
working  in 2 modes;
1.) uses transport such as SSH to sync data – requieres rsync on target system
2.) uses rsyncd to  transfer of files (Daemon)

1-Client, ‘rsync’ is used to connect to both modes
rsync -bazf
-b(backup – preservers existing files with ~ suffix or delete),- a(archives stat info)
-z(compression), -v(verbose)

Note: rsyncs client is required on both client and server when using SSH for transport

rsync -bazv -e ssh source destination
(scp ./* root@xen1:/ — similar to scp command )
rsync -bazv -e ssh /home/kraneis/perl root@xen1:

tuxido:/home/kraneis# rsync -bazv -e ssh /home/kraneis/perl root@xen1:

root@xen1’s password:
building file list … done
perl/
perl/FILE1
perl/FILE2
perl/FILE3
perl/FILE4
perl/FILE5
perl/FILEIO1.PL
perl/FILEIO2.PL


You can see on the Remote System
xen1:~# ls
perl  test.txt

rsync -bazv -e ssh /home/kraneis/perl root@xen1: – syncs local /home/kraneis/perl with remote system and
backup target files as necessary

### Syncronize local with remote system #####
rsync -azv -e ssh root@xen1:/app2 /

xen1:~# ls -ltr /app2 -d
drwxr-xr-x 2 root root 4096 Apr 16 12:42 /app2
xen1:~# ls -ltr /app2
total 4
-rw-r–r– 1 root root 51 Apr 16 12:11 test.seq

tuxido(localsystem):/home/kraneis/perl# rsync -azv -e ssh root@xen1:/app2 /
root@xen1’s password:
receiving file list … done
app2/
app2/test.seq

sent 48 bytes  received 159 bytes  46.00 bytes/sec
total size is 51  speedup is 0.25

localsystem:
tuxido:/# cd app2
tuxido:/app2# ls
test.seq
tuxido:/app2# ls -ltr
total 4
-rw-r–r– 1 root root 51 2009-04-16 14:11 test.seq

You can use a sample bash script
#!/bin/bash
# syncronize local /app2 with remote /app2
rsync -azv -e ssh root@xen1:/app2 /
##END
———————————————————–

## rsyncd server – /etc/rsyncd.conf – binds to TCP:873###
Note to contact rsyncd server using rsync client, specify ‘::’ in host field
Note: rsync currently does NOT support synchronization between 2 remote hosts

rsync -azv -e ssh /app2 root@xen1::/

### /etc/default/rsync file ###
# defaults file for rsync daemon mode

# start rsync in daemon mode from init.d script?
#  only allowed values are “true”, “false”, and “inetd”
#  Use “inetd” if you want to start the rsyncd from inetd,
#  all this does is prevent the init.d script from printing a message
#  about not starting rsyncd (you still need to modify inetd’s config yourself).
#RSYNC_ENABLE=false
## Add by Kraneis
RSYNC_ENABLE=true

# which file should be used as the configuration file for rsync.
# This file is used instead of the default /etc/rsyncd.conf
# Warning: This option has no effect if the daemon is accessed
#          using a remote shell. When using a different file for
#          rsync you might want to symlink /etc/rsyncd.conf to
#          that file.
# RSYNC_CONFIG_FILE=


###############################################
look /usr/share/doc/rsync/examples# less rsyncd.conf
# sample rsyncd.conf configuration file

# GLOBAL OPTIONS

#motd file=/etc/motd
#log file=/var/log/rsyncd
# for pid file, do not use /var/run/rsync.pid if
# you are going to run rsync out of the init.d script.
pid file=/var/run/rsyncd.pid
#syslog facility=daemon
#socket options=

# MODULE OPTIONS

[ftp]

comment = public archive
path = /var/www/pub
use chroot = yes
#       max connections=10
lock file = /var/lock/rsyncd
# the default for read only is yes…
read only = yes
list = yes
uid = nobody
gid = nogroup
#       exclude =
#       exclude from =
#       include =
#       include from =
#       auth users =
#       secrets file = /etc/rsyncd.secrets
strict modes = yes
#       hosts allow =
#       hosts deny =
ignore errors = no
ignore nonreadable = yes
transfer logging = no
#       log format = %t: host %h (%a) %o %f (%l bytes). Total %b bytes.
timeout = 600
______________________________________________________________________________
we can use rsyncd.conf
[app2]
path = /app2
comment = App2
#auth users = user (can any user)
#secrets file = /etc/rsyncd.secrets (if enabled auth users )

then start Deamon
/etc/init.d/rsync start

don’t forget enable in /etc/default/rsync
#add by Kraneis
RSYNC_ENABLE=true

# which file should be used as the configuration file for rsync.
# This file is used instead of the default /etc/rsyncd.conf
# Warning: This option has no effect if the daemon is accessed
#          using a remote shell. When using a different file for
#          rsync you might want to symlink /etc/rsyncd.conf to
#          that file.
# RSYNC_CONFIG_FILE=

# what extra options to give rsync –daemon?
#  that excludes the –daemon; that’s always done in the init.d script
#  Possibilities are:
“/etc/default/rsync” 35 lines, 1389 characters written
xen1:~# /etc/init.d/rsync start
Starting rsync daemon: rsync.
xen1:~# ps -ef |grep -i rsy
root      1980     1  0 14:09 ?        00:00:00 /usr/bin/rsync –no-detach –daemon –config /etc/rsyncd.conf
root      1986  1969  0 14:10 hvc0     00:00:00 grep -i rsy

You can look from Client
tuxido# rsync xen1::
ftp                public archive
app2               App2

and sync with server
tuxido:~# rsync xen1::app2/
drwxr-xr-x        4096 2009/04/16 15:16:31 .
-rw-r–r–           0 2009/04/16 15:06:15 file1.txt
-rw-r–r–          51 2009/04/16 14:11:56 test.seq
drwxr-xr-x        4096 2009/04/16 15:08:19 test1
drwxr-xr-x        4096 2009/04/16 15:08:19 test2
drwxr-xr-x        4096 2009/04/16 15:09:59 test3
drwxr-xr-x        4096 2009/04/16 15:08:19 test4
drwxr-xr-x        4096 2009/04/16 15:08:19 test5
drwxr-xr-x        4096 2009/04/16 15:16:31 test6