對(duì)于各種組織和公司,數(shù)據(jù)對(duì)他們是最重要的,即使對(duì)于電子商務(wù),數(shù)據(jù)也是同樣重要的。Rsync是一款通過(guò)網(wǎng)絡(luò)備份重要數(shù)據(jù)的工具/軟件。它同樣是一個(gè)在類(lèi)Unix和Window系統(tǒng)上通過(guò)網(wǎng)絡(luò)在系統(tǒng)間同步文件夾和文件的網(wǎng)絡(luò)協(xié)議。Rsync可以復(fù)制或者顯示目錄并復(fù)制文件。Rsync默認(rèn)監(jiān)聽(tīng)TCP 873端口,通過(guò)遠(yuǎn)程shell如rsh和ssh復(fù)制文件。Rsync必須在遠(yuǎn)程和本地系統(tǒng)上都安裝。
rsync的主要好處是:
速度:最初會(huì)在本地和遠(yuǎn)程之間拷貝所有內(nèi)容。下次,只會(huì)傳輸發(fā)生改變的塊或者字節(jié)。
安全:傳輸可以通過(guò)ssh協(xié)議加密數(shù)據(jù)。
低帶寬:rsync可以在兩端壓縮和解壓數(shù)據(jù)塊。
語(yǔ)法:
#rsysnc [options] source path destination path
示例: 1 - 啟用壓縮
[root@localhost /]# rsync -zvr /home/aloft/ /backuphomedir
building file list ... done
.bash_logout
.bash_profile
.bashrc
sent 472 bytes received 86 bytes 1116.00 bytes/sec
total size is 324 speedup is 0.58
上面的rsync命令使用了-z來(lái)啟用壓縮,-v是可視化,-r是遞歸。上面在本地的/home/aloft/和/backuphomedir之間同步。
示例: 2 - 保留文件和文件夾的屬性
[root@localhost /]# rsync -azvr /home/aloft/ /backuphomedir
building file list ... done
./
.bash_logout
.bash_profile
.bashrc
sent 514 bytes received 92 bytes 1212.00 bytes/sec
total size is 324 speedup is 0.53
上面我們使用了-a選項(xiàng),它保留了所有人和所屬組、時(shí)間戳、軟鏈接、權(quán)限,并以遞歸模式運(yùn)行。
示例: 3 - 同步本地到遠(yuǎn)程主機(jī)
root@localhost /]# rsync -avz /home/aloft/ azmath@192.168.1.4:192.168.1.4:/share/rsysnctest/
Password:
building file list ... done
./
.bash_logout
.bash_profile
.bashrc
sent 514 bytes received 92 bytes 1212.00 bytes/sec
total size is 324 speedup is 0.53
上面的命令允許你在本地和遠(yuǎn)程機(jī)器之間同步。你可以看到,在同步文件到另一個(gè)系統(tǒng)時(shí)提示你輸入密碼。在做遠(yuǎn)程同步時(shí),你需要指定遠(yuǎn)程系統(tǒng)的用戶(hù)名和IP或者主機(jī)名。
示例: 4 - 遠(yuǎn)程同步到本地
[root@localhost /]# rsync -avz azmath@192.168.1.4:192.168.1.4:/share/rsysnctest/ /home/aloft/
Password:
building file list ... done
./
.bash_logout
.bash_profile
.bashrc
sent 514 bytes received 92 bytes 1212.00 bytes/sec
total size is 324 speedup is 0.53
上面的命令同步遠(yuǎn)程文件到本地。
示例: 5 - 找出文件間的不同
[root@localhost backuphomedir]# rsync -avzi /backuphomedir /home/aloft/
building file list ... done
cd+++++++ backuphomedir/
>f+++++++ backuphomedir/.bash_logout
>f+++++++ backuphomedir/.bash_profile
>f+++++++ backuphomedir/.bashrc
>f+++++++ backuphomedir/abc
>f+++++++ backuphomedir/xyz
sent 650 bytes received 136 bytes 1572.00 bytes/sec
total size is 324 speedup is 0.41
上面的命令幫助你找出源地址和目標(biāo)地址之間文件或者目錄的不同。
示例: 6 - 備份
rsync命令可以用來(lái)備份linux。
你可以在cron中使用rsync安排備份。
0 0 * * * /usr/local/sbin/bkpscript > /dev/null/p>
p> vi /usr/local/sbin/bkpscript
rsync -avz -e ‘ssh -p2093′ /home/test/ root@192.168.1.150:/oracle/data/