本文共 3217 字,大约阅读时间需要 10 分钟。
centos6,rsync 3.X比对方法,一遍比对差异,一遍对差异的部分进行同步。
查看rysnc版本:
[root@backup ~]# rsync --version
rsync version 3.0.6 protocol version 30 Copyright (C) 1996-2009 by Andrew Tridgell, Wayne Davison, and others. Web site: http://rsync.samba.org/ Capabilities: 64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints, socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace, append, ACLs, xattrs, iconv, symtimesrsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you
are welcome to redistribute it under certain conditions. See the GNU General Public Licence for details.1.判断linux系统是否已安装了rsync,用命令rpm -qa rsync检查rpm是否安装。
rpm -qa rsync也叫做编译安装rsync
[root@backup ~]# rpm -qa rsync
rsync-3.0.6-12.el6.x86_64如果使用rpm -qa rsync没有安装,那么就需要使用其他方式安装了。
2.判断rsync版本使用命令rsync --version
[root@oldboy ~]# rsync --version
rsync version 3.0.6 protocol version 30 Copyright (C) 1996-2009 by Andrew Tridgell, Wayne Davison, and others. Web site: http://rsync.samba.org/ Capabilities: 64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints, socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace, append, ACLs, xattrs, iconv, symtimesrsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you
are welcome to redistribute it under certain conditions. See the GNU General Public Licence for details.rsync三种工作模式:
local本地模式:rsync(cp,rm)
本地模式举例:1.本地拷贝
[root@backup ~]# rsync /etc/hosts /data/
[root@backup ~]# cat /data/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 [root@backup ~]# rsync vzrtopg /etc/hosts /mnt/ rsync: link_stat "/root/vzrtopg" failed: No such file or directory (2) rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]2.保持属性拷贝:-vzrtopg一般讲用-avz就够了
[root@backup ~]# rsync -vzrtopg /etc/hosts /mnt/
sending incremental file listsent 30 bytes received 12 bytes 84.00 bytes/sec
total size is 158 speedup is 3.763.删除(必须保持本地端/tmp1没有,尽量少用--delete)
rsync -avz --delete /tmp1 /mnt/
rsync拷贝注意事项:rsync -az /tmp1/ /mnt/
/tmp1/只包括temp1里面的内容,不包含文件名, 如果/tmp1后面不加/,就包括目录名/tmp1和里面的内容
2. 通道模式:
rsync -avzP -e‘ssh -p 22’/etc
一般配合ssh key免密钥使用,结合定时任务
举例:把本地/data/a.txt文件通过ssh通道拷贝到远端主机ip为10.0.0.31的/data路径下面
[root@backup data]# rsync -avz /data/a.txt -e 'ssh -p 22' root@10.0.0.31:/data
root@10.0.0.31's password: sending incremental file list a.txtsent 66 bytes received 31 bytes 21.56 bytes/sec
total size is 0 speedup is 0.00到目录机器10.0.0.31查看是否拷贝成功
[root@oldboy ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:EB:DA:9F inet addr:10.0.0.31 Bcast:10.0.0.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:feeb:da9f/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:838 errors:0 dropped:0 overruns:0 frame:0 TX packets:798 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:85079 (83.0 KiB) TX bytes:95638 (93.3 KiB)[root@oldboy ~]# ls /data
3. daemon模式:(以守护进程socket的方式传输数据重点)
内网不需要,加密性能有损失
跨机房拷贝:vpn(pptp,openvpn,ipsec)
rsync实时备份
sersync+rsync
inotify+rsync
定时备份
rsync +deamon
本文转自sandshell博客51CTO博客,原文链接http://blog.51cto.com/sandshell/1950966如需转载请自行联系原作者
sandshell