Linux下数据自动同步之rsync

Linux大全评论882 views阅读模式

rsync是类unix系统下的数据镜像备份工具,从软件的命名上就可以看出来了——remote sync。

Windows下数据自动备份同步之Rsync  http://www.linuxidc.com/Linux/2014-01/95722.htm
 
一、实验环境
服务端:Linux CentOS 6.0 (192.168.1.220)
客户端1:Linux Centos 6.0 (192.168.1.96)
客户端2:windows 7 (192.168.1.97)

--------------------------------------------------------------------------------
 
二、安装配置rsync
yum -y install xinetd rsync
chkconfig xinetd on
chkconfig rsync on
sed -i  '/disable/s/yes/no/' /etc/xinetd.d/rsync
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT
/etc/init.d/iptables save
service iptables restart
touch /etc/rsyncd.conf
cat << eof >> /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 4
stirict modes = yes
port = 873
[webbackup]
path = /var/www/html/
comment = This is a test
ignore errors
read only = false
list = no
hosts allow = 192.168.1.96,192.168.1.97
hosts deny = 0.0.0.0/0
auth users = bakweb
secrets file =/etc/rsyncd.pw
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
eof
echo "bakweb:00123456" >> /etc/rsyncd.pw
chown root.root /etc/rsyncd.pw
chmod 600 /etc/rsyncd.pw
service xinetd restart
 
注:验证用户名:bakweb 密码:00123456 ;把上面的内容复制粘贴或者您也可以把上面的内容复制然后贴到脚本里执行即可;

--------------------------------------------------------------------------------
 
三、Linux主机客户端安装与配置
yum -y install xinetd rsync
echo "00123456" >> /etc/rsyncd.pw
chown root.root /etc/rsyncd.pw
chmod 600 /etc/rsyncd.pw
mkdir /root/test
 
同步数据:
rsync -vzrtopg --progress --delete bakweb@192.168.1.220::webbackup /root/test --password-file=/etc/rsyncd.pw
 
rsync命令参数:
-v表示verbose详细显示
-z表示压缩
-r表示recursive递归
-t表示保持原文件创建时间
-o表示保持原文件属主
-p表示保持原文件的参数
-g表示保持原文件的所属组
 
注:如果您需要定期同步数据,把上面同步数据的命令增加到 crontab 里定时同步即可哈;

--------------------------------------------------------------------------------
 
四、Windows主机客户端安装与配置

4.1 下载cwRsync 4.0.5

下载地址:http://www.linuxidc.com/Linux/2014-01/95721.htm 

--------------------------------------------------------------------------------
 
4.2 安装及配置
下载后,直接解压出来,然后双击安装,一直 “NEXT” 结束,简单得不能再简单了;
 
进入电脑e盘-新建test文件夹;
 
进入电脑e盘-test文件夹-新建html文件夹;
 
进入电脑e盘-test文件夹-新建rsyncd.txt 文件,写入00123456,保存退出;然后把rsyncd.txt的后缀名更改为pw,即rsyncd.pw
 
注:上面只是准备在E:\test\html 目录下,进行实验测试,您可以根据您的实际情况,进行相应调整;

--------------------------------------------------------------------------------
 
4.3 同步数据
打开cmd
>cd G:\Program Files\cwRsync\bin
>rsync.exe -vzrtopg --progress --delete bakweb@192.168.1.220::webbackup /cygdrive/e/test/html --password-file=/cygdrive/e/test/rsyncd.pw
 
注:由于我的操作系统是安装在G盘,而且rsync的客户端也安装在这个盘上,所以我是切换到该目录下,调用rsync.exe 程序来同步的哦;您得根据您的实际情况,进行相应调整;
 
注:如果您需要定时同步数据的话,写一个 .bat文件,放在安装目录的bin目录下,然后设置到计划任务里执行即可哈;

Rsync 的详细介绍:请点这里
Rsync 的下载地址:请点这里

推荐阅读:

利用inotifywait监控主机文件和目录 http://www.linuxidc.com/Linux/2013-03/81075.htm

利用inotify+rsync实现Linux文件批量更新 http://www.linuxidc.com/Linux/2012-01/52132.htm

企鹅博客
  • 本文由 发表于 2019年10月3日 16:42:55
  • 转载请务必保留本文链接:https://www.qieseo.com/160454.html

发表评论