rsync 安装 配置 自动化

本文介绍了如何在服务器端安装和配置rsync,包括解决依赖问题、编辑rsyncd.conf文件以及设置权限和允许的主机。同时,文章展示了如何在客户端安装rsync并创建脚本来定期从服务器拉取数据,通过crontab实现自动化备份。此外,还提及了增量备份的实现思路。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值