SOURCECODEBD.NET

Live Experience

Rsync on CentOS
 
Mirror a directory in HostA to HostB with rsync.
Basic usage of rsync is simply like follwos.

# rsync -av --exclude=(exclude dir) (mirrored directory) (destination directory)

However, if mirroed directory or destination directory is not local, root password is required. In that case, it's easy to mirror automatically by cron with this configuration.

Following example based on a environment HostA is [192.168.0.18], HostB is [192.168.0.20].

   
[1] Install xinetd first. It's necessary on HostA.  
 
[root@www ~]# yum -y install xinetd
[root@www ~]# vi /etc/xinetd.d/rsync

# default: off
# description: The rsync server is a good addition to an ftp server, as it
# allows crc checksumming etc.
service rsync
{
 disable  =no # change
 socket_type = stream
 wait   = no
 user   = root
 server  = /usr/bin/rsync
 server_args = --daemon
 log_on_failure  += USERID
}

[root@www ~]# /etc/rc.d/init.d/xinetd start
[root@www ~]# chkconfig xinetd on 
 
[2] Configure for HostA. This example based on a configuration to mirror files under /var/www/html to HostB.  
 
[root@www ~]# vi /etc/rsyncd.conf

#any name you like
[site]
# mirroed directory
path = /var/www/html
# IP address you allow that connects to this server
hosts allow = 192.168.0.20
hosts deny = *
list = true
uid = root
gid = root 
 
[3] Configure for HostB.  
 
[root@lan ~]# vi /etc/rsync_exclude.lst

# Write directory or files you don't want to mirror

test
test.txt 
 
[4] Run Rsync  
 
[root@lan ~]# rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst 192.168.0.18::site /home/backup

# add in cron if you'd like to run rsync automatically

[root@lan ~]# crontab -e

00 02 * * * rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst 192.168.0.18::site /home/backup

You are here: Home / CentOS / Configure Rsync on CentOS