centos6,rsync 3.X比对方法,一遍比对差别,一遍对差别的部分进行同步。linux
查看rysnc版本:redis
[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, symtimescentos
rsync 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.app
1.判断linux系统是否已安装了rsync,用命令rpm -qa rsync检查rpm是否安装。dom
rpm -qa rsync也叫作编译安装rsync
ssh
[root@backup ~]# rpm -qa rsync
rsync-3.0.6-12.el6.x86_64socket
若是使用rpm -qa rsync没有安装,那么就须要使用其余方式安装了。ide
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, symtimes加密
rsync 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 list
sent 30 bytes received 12 bytes 84.00 bytes/sec
total size is 158 speedup is 3.76
3.删除(必须保持本地端/tmp1没有,尽可能少用--delete)
rsync -avz --delete /tmp1 /mnt/
rsync拷贝注意事项:rsync -az /tmp1/ /mnt/
/tmp1/只包括temp1里面的内容,不包含文件名, 若是/tmp1后面不加/,就包括目录名/tmp1和里面的内容
2. 通道模式:
rsync -avzP -e‘ssh -p 22’/etc root@10.0.0.142:/tmp
通常配合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.txt
sent 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的方式传输数据重点)
内网不须要,加密性能有损失
跨机房拷贝:***(pptp,open***,ipsec)
rsync实时备份
sersync+rsync
inotify+rsync
定时备份
rsync +deamon