我們?cè)诜?wù)器之間數(shù)據(jù)傳輸較大的文件的時(shí)候,如果用 wget 命令拉取文件或者是 FTP 下載到本地后再上傳,這樣的效率是比較低的,而且容易因?yàn)榫W(wǎng)絡(luò)異常導(dǎo)致無(wú)法完全下載。在這里,我們可能會(huì)常用 scp 和 rsync 命令進(jìn)行數(shù)據(jù)的推送或者是遠(yuǎn)程下載,但是這兩者也是有區(qū)別的。
較大的區(qū)別在于 scp 命令不支持續(xù)傳文件,而 rsync 支持續(xù)傳文件,其實(shí)如果有玩過(guò)增量備份文件的時(shí)候應(yīng)該接觸過(guò) rsync 命令。在這里,我們將整理 scp 和 rsync 命令的常見(jiàn)用法。
文章目錄
隱藏
第一、scp 命令
也不是說(shuō) scp 命令不支持續(xù)傳的時(shí)候就不好用,這個(gè)理解是錯(cuò)誤的,如果文件不是太大,其實(shí)用哪個(gè)都是一樣的。
1、推送文件到遠(yuǎn)端
scp -P port /data/wwwroot/lezaiyun.com/ username@remote:/data/wwwroot/lezaiyun.com/
這里對(duì)應(yīng)的可以設(shè)置遠(yuǎn)端服務(wù)器的端口。
2、獲取遠(yuǎn)端文件到本地
scp -P Port username@remote:/data/wwwroot/lezaiyun.com/lezaiyun.tar.gz /data/wwwroot/lezaiyun.com/
第二、rsync 命令
rsync 命令支持續(xù)傳的,所以如果網(wǎng)絡(luò)掉線,還支持重新上傳會(huì)續(xù)傳。
1、獲取遠(yuǎn)端的文件到本地
rsync -P --rsh='ssh -p Port' username@remote:/data/wwwroot/lezaiyun.com/lezaiyun.tar.gz /data/wwwroot/lezaiyun.com/
2、推送文件到遠(yuǎn)端
rsync -P --rsh='ssh -p Port' /data/wwwroot/lezaiyun.com/ root@Remote:/data/wwwroot/lezaiyun.com/
評(píng)論