假設最開始的命令是這樣的
rsync -e 'ssh -p 30000' -avl --delete --stats --progress demo@123.45.67.890:/home/demo /backup/
一、排除單獨的檔案夾和檔案
要排除sources檔案夾,我們可以添加 '--exclude' 選項:
--exclude 'sources'
命令是這樣的:
rsync -e 'ssh -p 30000' -avl --delete --stats --progress --exclude 'sources' demo@123.45.67.890:/home/demo /backup/
要排除 "public_html" 檔案夾下的 "database.txt" 檔案:
--exclude 'public_html/database.txt'
命令是這樣的:
rsync -e 'ssh -p 30000' -avl --delete --stats --progress --exclude 'sources' --exclude 'public_html/database.txt' demo@123.45.67.890:/home/demo /backup/
二、使用 '--exclude-from' 排除多個檔案夾和檔案
建立檔案:
/home/backup/exclude.txt
在裡面定義要排除的檔案夾和檔案
sources
public_html/database.*
downloads/test/*
使用指令:
--exclude-from '/home/backup/exclude.txt'
最後的命令如下:
rsync -e 'ssh -p 30000' -avl --delete --stats --progress --exclude-from '/home/backup/exclude.txt' demo@123.45.67.890:/home/demo /backup/
Rsync的其他幾個常見參數
1
-z –compress compress file data during the transfer
--compress-level=NUM explicitly set compression level
--skip-compress=LIST skip compressing files with suffix in LIST
壓縮傳輸,如果網路頻寬不夠,那麼應該壓縮以後傳輸,消耗的當然是機器資源,但是如果內網傳輸的話,檔案數量不是很多的話,這個參數不必要的。
2
--password-file=FILE
前面說過了,只有遠端機器是rsync伺服器,才能用這個參數
如果你以為個FILE寫的是ssh 登陸的密碼,那就大錯特錯了,不少人犯了這個錯誤。
3
–stats: Adds a little more output regarding the file transfer status.
4
–progress: shows the progress of each file transfer. Can be useful to know if you have large files being backup up.