Synchronizes files and directories by rsync

it2026-08-18  12

Synchronizes files and directories from one location to another location by rsync.

The example below is for automatical settings.

Copy files and directories in /data/proclog/ouxingning on a HostA[192.168.201.1] to in /data/ouxingning/backup on HostB[192.168.201.2].

1) Configure on Destination Host

yum -y install rsync xinetd [root@ouxingning-5320-007 ~]# 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 # yes change to no flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID } [root@ouxingning-5320-007 ~]# /etc/rc.d/init.d/xinetd start 正在启动 xinetd: [确定] [root@ouxingning-5320-007 ~]# chkconfig xinetd on [root@ouxingning-5320-007 ~]# mkdir -p /data/ouxingning/backup [root@ouxingning-5320-007~]# vi /etc/rsyncd.conf # indicates the source host, any name you like[backuplog] # destination directory path = /data/ouxingning/backup # hosts you allow to copy (specify source host) hosts allow = 192.168.201.1 hosts deny = * list = true uid = root gid = root read only = false # specifie the name of a file that contains the username:password pairs secrets file = /etc/rsyncd.secrets vi /etc/rsyncd.secrets root:123456 chmod 600 /etc/rsyncd.secrets

 

2) Configure on Source Host

[root@www ~]# yum -y install rsync [root@www ~]# vi /etc/rsync_exclude.lst # specify files or directories you'd like to exclude to copy test test.txt

 

3) It's OK, Execute rsync on Source Host like follows

[root@www ~]# rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst /data/proclog/ouxingning/ 192.168.201.2::backuplog # Add in cron if you'd like to run reguraly [root@www ~]# crontab -e # run at 2:00 AM in a day 00 02 * * * rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst /data/proclog/ouxingning/ 192.168.201.2::backuplog

 

ps:

vi /etc/sysconf/selinx

setenforce 0

#shell: setenforce 0 

 

 

转载于:https://www.cnblogs.com/ouxingning/archive/2012/11/02/synchronizes_files_by_rsync.html

相关资源:数据结构—成绩单生成器
最新回复(0)