rsync 排除檔案和檔案夾參數詳解

來源:互聯網
上載者:User


假設最開始的命令是這樣的
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.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.