rsync服务器端
安装RSYNC
一、下载、安装rsync
#tar zxvf rsync-2.6.9.tar.gz
#cd rsync-2.6.9
#./configure --prefix=/usr/local/rsync
#make
#make install
或者
yum install rsync -y
安装如果出错:
error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
解决办法如下:
1.在/etc/ld.so.conf中加一行/usr/local/lib,
ldconfig
即可
如果没有xinetd ,则 yum -y install xinetd
默认也许没有rsyncd.conf则
vi /etc/rsyncd.conf
以下被涂掉的为rsync服务密码:
注意:我们为了安全起见,最好用户不要使用超级用户 root,用普用户即可。
这里,我们同步 [cncarweb] 里路径的文件到客户端,以此为例子做增量备份和实时同步。
以下是更安全的、更全面的配置文件:
[root@carschina ~]# cat /etc/rsyncd.conf
secrets file = /etc/rsyncd.secrets
motd file = /etc/rsyncd.motd
read only = yes
list = yes
uid = root
gid = wheel
hosts allow = 127.0.0.1 184.171.168.58 218.85.133.184 61.187.235.117 115.238.73.233 61.160.210.41 219.129.216.248 222.76.215.108
max connections = 24
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
timeout = 300
################################################
[web_all]
path = /data/backup/all_web
auth users = rsy_user
[svn_clubcar]
path = /data/svn/svn_clubcar/files/svn_clubcar
auth users = rsy_user
read only = no
[530la]
path = /data/web/530la
read only = no
auth users = rsy_user
################################################
[carschina.com]
path = /data2/web/carschina.com
auth users = rsy_user
#######################################################
[our_cc]
path = /data2/web/ourcarschinacom
auth users = rsy_user
######################################djbzmz 2010-02-04 ZhuZhan 4 ge#############
[yiqiwangcom]
path = /data2/web/yiqiwangcom
auth users = rsy_user
RSYNC 启动:
/usr/local/bin/rsync --daemon
或有些
/usr/local/rsync/bin/rsync --daemon
可以将以上加入到 /etc/rc.local 随系统启动而启动。
如果需要立即停止:可以killall rsync
rsync客户端:
安装RSYNC即可。
拉取服务器[cncarweb]数据脚本:
rsy_XXXcom_from_XXIP_to_local.sh
被涂掉的是服务器的IP和客户端拉取数据存放的目录。
--password-file=/etc/rsync.pwd 为rsync服务器的服务密码。
--exclude 为忽略、排除哪些文件。rsync对文件和目录一视同仁。
crontab -e 做定时任务:
15 9 * * * /data/sh/rsy/rsy_XXXcom_from_XXIP_to_local.sh >>/data/logs/rsy/rsy_XXXcom_from_XXIP_to_local.log 2>&1
注意一定要规范化。
#每隔七天将数据往中心服务器做增量备份
以下代码待纠正。很多不完整。
#!/bin/sh
BDIR=/home/$USER
EXCLUDES=$HOME/cron/excludes
BSERVER=owl
export RSYNC_PASSWORD=XXX
#####################################################################
BACKUPDIR=`date +%A`
OPTS="--force --ignore-errors --delete-excluded --exclude-from=$EXCLUDES
--delete --backup --backup-dir=/$BACKUPDIR -a"
export PATH=$PATH:/bin:/usr/bin:/usr/local/bin
# the following line clears the last weeks incremental directory
[ -d $HOME/emptydir ] || mkdir $HOME/emptydir
rsync --delete -a $HOME/emptydir/ $BSERVER::$USER/$BACKUPDIR/
rmdir $HOME/emptydir
# now the actual transfer
rsync $OPTS $BDIR $BSERVER::$USER/current