rsync备份工具.pdf

上传:yuguohe20299 浏览: 38 推荐: 0 文件:PDF 大小:367.81KB 上传时间:2020-07-29 07:05:22 版权申诉
rsync是linux系统下的数据镜像备份工具。使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH、rsync主机同步51#模块验证用户名称,可使用空格或者逗号隔丌多个用户名52 auth users = yz53#注释54 comment some description about this moudle5#排除目录,多个之间使用空格隔开56 exclude test1/ test2/5758 codeTmp]59 path =/tmp/codeGo list=no61 auth users = yz14.编辑密码文件 rsync. secrets[root@Master a]# vi /etc/rsyncd/rsync. secrets2 yz: 007bleach3 yz1: 007bleach启动 rsync服务rsync服务启动1 root(@Master w#/usr/bin/rsync --daemon --config=/etc/rsync/rsyncd conf#默认配置文件是/etc/ rsync.conf,所以需要显式的指定配置文件2 [ root@Master ] nohup /usr/bin/rsync --daemon --config-/etc/rsync/rsyncd.conf#假设使用 putty, shell终端操作保证终端断开进程仍然执行查看 rsync服务是否成功1 root@Master test1]# ps -aux grep rsync2root76488.88.8114748392ss11:169:88 rsync-- daemonconfig=/etc/rsyncd/ rsyncd conf3 root 7650 0.0 0.0 112728 972 pts/1 S+ 11: 17 0: 00 grep --color=auto rsyncdrsync客户端配置安装客户端[root@client yum -y install rsync2测试I [root@client w]# rsync -avzP yz@192.168.6. 138: mysqlData/tmp/test2 rootaclient w]# rsync -avzP--delete yz@192.168.6.138: mysqlData/tmp/test/3客户端数据和服务器端数据保持致,会除在客户端目录里但是不在服务器模块里的文件(夹)4 root@client w]# vi/tmp/yz. password5 007bleach6 rootaclient w]# chmod 600/tmp/yz. password7#指定传输吋候的密码文件,密码文件权限6088 rootaClient w# rsync -azvP --delete --password-file=/tmp/yz. password yz@192. 168.6.138:: mysqlData/tmp/test9#测试已经不用输入密码就可以同步完成注意进行测试时服务器端文件要先创建好rsync常用参数-V详细模式输出传输时候显示进度等信息z传输时进行压缩提高传输速率- compuress-level=num可以按级别压缩对子目录以递归模式,即目录下的所有目录都同样传输-t保持文件时间信息o保持文件属性信息g保持稳健属组信息a归档模式相当于 rtopgP显示同步过程及传输时进度信息-e使用信道协议指定替代rsh的shel程序如sshexclude= PATTERN指定排除不需要传输的文件支持*来代替仼意字符D保持设备文件信息l保留软连接H,-hard-inks保留硬链接常用的选项为aVz设置定时任务创建一个$h脚本1 [root@client w]# vi rsync. sh2 rootaclient w]# rsync -azvP --delete--password-file=/tmp/yz. password yz@192. 168.6.138:: mysqlData /tmp/test/>/dev/null 2>&13[root@C1ient~]# chmod755 rsync.sh#脚本设置权限1[root@c1ient~]# crontab-e#冻加计划任务每5分钟执行sh脚本5*/5****~/ rsync.sh使用not进行实时同步1客户端安装 Inotify(1921686.140)1rootaclientw#wgethttp://github.com/downloads/rvoicilas/inotifytools/inotify-tooIs-3. 14. tar. gz2 [ rootaclient w]# tar -zvXf inotify-tools-314tar.gz3 [root@Client w]# cd inotify-tools-3144 root@client inotify-tools-314#./configure --prefix=/usr/local/inotify5 rootaclient inotify-tools-3 14# make & make install2.编写脚本进行监控文件和执行同步root(@client w]# vi/home/yz/inotify. sh2 root@client w# chmod 755/home /yz/inotify. sh3 root@client u]# cat /home/yz/inotify. sh4 #!/bin/bash5host=192168.6.138#备份服务器ip6src=/home/y2/#在源服务器上所要监控的备份目录,目录要以/结束,不然会在目标服务器直接创建yz目录7des=mysq1Data#模块名,和目标服务器上定义同步8 password=/etc/ rsync. password#执行数据同步密码文件9user=yz#行数据同步的用户名0 inotify=/us/1oca1/ inotify# inotify安装目录11 Inotify)/bin/inotifywait -mrq--timefmt ' %d/%m/ %y %H: %M'--format9T%w%f%e'-e modify, delete, create, attrib $src while read files12 do13 rsynC -avZP --delete --timeout=100--password-file=$password ssrc susershost: $des14 echo "Sifiles was rsynced">>/tmp/rsync. log 2>&115 done3启动脚本并测试1 [root@client N]# nohup /home/yz/inotify. sh2 root@client N]# touch /home/yz/(1.9).txt3 [root@client w# ls /home/yz/41. txt 2. txt 3. txt 4.txt 5. txt 6. txt 7. txt 8. txt 9.txt inotify. sh4返回目标服务器查看是否自动生成1 root@Master w]# ls /home/yz/2 1. txt 2. txt 3. txt 4. txt 5.txt 6. txt 7. txt 8.txt 9. txt inotify. sh
上传资源
用户评论