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