《Linux下使用rsync進(jìn)行數(shù)據(jù)備份的命令詳解》要點(diǎn):
本文介紹了Linux下使用rsync進(jìn)行數(shù)據(jù)備份的命令詳解,希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
對(duì)于運(yùn)維人員來(lái)說(shuō),數(shù)據(jù)備份是最重要的工作之一,rsync就是一款通過(guò)網(wǎng)絡(luò)備份重要數(shù)據(jù)的工具/軟件.
sync同樣是一個(gè)在類Unix和Window系統(tǒng)上通過(guò)網(wǎng)絡(luò)在系統(tǒng)間同步文件夾和文件的網(wǎng)絡(luò)協(xié)議,它可以復(fù)制或者顯示目錄并復(fù)制文件.rsync默認(rèn)監(jiān)聽(tīng)TCP 873端口,通過(guò)遠(yuǎn)程shell如rsh和ssh復(fù)制文件.同時(shí)要求必須在遠(yuǎn)程和本地系統(tǒng)上都安裝sync.
rsync的主要優(yōu)點(diǎn)是:
速度:最初會(huì)在本地和遠(yuǎn)程之間拷貝所有內(nèi)容.下次,只會(huì)傳輸發(fā)生改變的塊或者字節(jié).
安全:傳輸可以通過(guò)ssh協(xié)議加密數(shù)據(jù).
低帶寬:rsync可以在兩端壓縮和解壓數(shù)據(jù)塊.
sync命令語(yǔ)法:
#rsysnc [options] source path destination path
以下將根據(jù)sync的參數(shù)和應(yīng)用場(chǎng)景來(lái)給大家介紹具體的用法:
示例: 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)的用戶名和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
vi /usr/local/sbin/bkpscript
rsync -avz -e ‘ssh -p2093′ /home/test/ root@192.168.1.150:/oracle/data/
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/4599.html