====== rsync 筆記 ======
rsync 是一個拿來備份相當好用的東西~~
拿來同步Server上的資料也很好用。
如果目的端的資料一樣,他就不會再重新Sync,
速度很快~~
這裡簡單說明記錄一下。
使用方式:
rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST
rsync [OPTION]... [USER@]HOST:SRC [DEST]
rsync [OPTION]... SRC [SRC]... DEST
rsync [OPTION]... [USER@]HOST::SRC [DEST]
rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST
rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]
rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST
我常用的大概就下面這個
rsync -rltvp --delete -e "ssh -p 1688 -l root" /home/user/chingwei/www/ xx.xx.xx.xx:/home/www/backup/www/
rsync -av --delete /home/eddie /home/Backup
rsync --verbose --log-file="/var/log/rsync_temp.log" --archive --delete --exclude=.recycle --exclude=._.DS_Store --exclude=.DS_Store "rsync://root@xxx.domain.com:/PPP_Service" "/srv/dev-disk-by-label-raid5/BackupStorage/Backup/Backup/temp/"
參數說明,網路上的中文說明好像都這份~~所以也不知道真正的出處在那。
-h , --help 顯示rsync求助資訊.
--version 顯示rsync版本.
-v , --verbose 複雜的輸出訊息.
-q , --quiet 安靜模式,幾乎沒有訊息產生.常用在以cron執行rsync.
-I, --ignore-times 通常rsync為了加快速度會忽略同樣檔案大小且同樣存取時間點的檔案.可以透過此參數關閉此快速檢查.
--size-only rsync只檢查檔案大小是否改變,不管時間存取點是否改變.通常用在mirror,且對方時間不太正確時.
-c, --checksum 在傳送之前透過128bit的md4檢查碼來檢查所有要傳送的檔案.(會拖慢速度.)
-a, --archive archive mode 權限保存模式,相當於 -rlptgoD 參數.
很快速的保存幾乎所有的權限設定,除了硬式連結(透過-H設定).
-r, --recursive 複製所有下層的資料(遞迴)
-R, --relative 使用相對路徑.
如:
rsync foo/bar/foo.c remote:/tmp/ 在遠端產生/tmp/foo.c檔案
rsync -R foo/bar/foo.c remote:/tmp/ 在遠端產生/tmp/foo/bar/foo.c 檔案
-R, --no-relative 不使用相對路徑.
-b, --backup 目的地端先前已經存在的檔案在傳輸或刪除前會被備份.
--backup-dir=DIR 設定備份的資料夾.
--suffix=SUFFIX 指定備份的檔案名稱字尾形式(預設為~).
-K, --keep-dirlinks 接收方將連結到資料夾的檔案視為資料夾處理
-l, --links 複製所有的連結
-H, --hard-links 保留硬式連結
-p, --perms 保留檔案權限
-o, --owner 保留檔案擁有者(root only)
-g, --group 保留檔案群組
-D, --devices 保留device資訊(root only)
-t, --times 保留時間點
-n, --dry-run 不實際執行傳送,只顯示將會有的傳輸動作
-S, --sparse 嘗試去處理稀疏的檔案,讓這些檔案在目的端佔去較少的磁碟空間.
-W, --whole-file 複製所有的檔案,不額外作檢查.
--no-whole-file 關閉 --whole-file 參數
-x, --one-file-system 不要跨越檔案系統分界(只在一個檔案系統處理)
-B, --block-size=SIZE 強制透過rsync程式去比對修復block-sizeforce
-e --rsh=COMMAND 定義所使用的remote shell
--rsync-path=PATH 定義rsync在遠端機器存放資料的路徑
--existing 只比對更新目的端已經存在的檔案
--ignore-existing 忽略目的端已經存在的檔案(也就是不更新)
--delete 刪除傳送端已經不存在,而目的端存在的檔案
--delete-excluded 除了把傳送端已經不存在,而目的端存在的檔案刪除之外,也刪除 --exclude 參數所包含的檔案.
--delete-after rsync預設會在檔案傳送前進行相關刪除動作確保接收端有足夠的檔案空間,但可以透過 --delete-after 讓刪除動作在檔案傳送後再行刪除.
--ignore-errors 忽略任何錯誤既使是I/O error 也進行 --delete 刪除動作.
--max-delete=NUM 定義rsync不要刪除超過 NUM 個檔案.
--partial rsync若遇到傳輸過程中斷時,會把那些已經傳輸的檔案刪除.在某種狀況下保留那些部分傳送的檔案是令人高興的.你可以透過 --partial 參數達到這個目的.
--partial-dir=DIR 在 --partial 參數啟動時,你還可以定義rsync把那些部分傳送的檔案寫入定義的資料夾,而非直接寫入目的端.需要注意的是,此資料夾不應該被其他使用者可以寫入.(如:/tmp)
--force 當目的端資料夾被傳送端非資料夾名稱覆蓋時,強制rsync刪除資料夾,即使該資料夾不是空的.
--numeric-ids 不將傳送端檔案的uid及gid值,與目的端的使用者/群組進行配對.若傳送端並沒有uid及gid的對應名稱(如:原帳號群組被刪除的遺留檔案),或目的端沒有相對應的帳號/群組,保留數字型態的uid/gid
--timeout=TIMEOUT 設定 I/O 逾時的時間(秒). 超過這個秒數而沒有資料傳送,rsync將會結束.預設為0,也就是沒有定義逾時時間.
-T, --temp-dir=DIR 定義rsync在接收端產生暫時性的複製檔案時使用資料夾暫存.預設是直接在接收端資料夾直接產生暫存檔案.
--compare-dest=DIR 定義rsync在目的端建立資料夾來比對傳送過來的檔案.
--link-dest=DIR 與 --compare-dest 相同,但同時會針對無法改變的檔案建立硬式連結.
-z, --compress 壓縮模式,當資料在傳送到目的端進行檔案壓縮.
-P -P參數和 --partial --progress 相同.只是為了把參數簡單化.
-C, --cvs-exclude 排除那些通常不希望傳送的檔案.定義的方式與CVS傳送相同:
RCS SCCS CVS CVS.adm RCSLOG cvslog.* tags TAGS .make .state .nse_depinfo *~ #* .#* ,* _$* *$ *.old *.bak *.BAK *.orig *.rej .del-* *.a *.olb *.o *.obj *.so *.exe *.Z *.elc *.ln core .svn/ 符合以上條件的都會被忽略而不傳送.
--exclude=PATTER 符合PATTERN(規則表示式)樣式的檔案不進行傳送
--exclude-from=FILE 和--exclude參數相同,不過是把不進行傳送的檔案事先寫入某一檔案.執行時,透過此參數讓rsync讀取.(; #開頭的行列或空白行會被rsync忽略)
--include=PATTERN 定義rsync不要排除符合pattern樣式的檔案.
--include-from=FILE 和--include參數相同,只不過把要包含的檔案寫到某一檔案.
--files-from=FILE 把要傳送的檔案名稱都精確的寫入某一檔案,讓rsync讀取.
如: rsync -a --files-from=/tmp/foo /usr remote:/backup
-0 --from0 定義檔案所要讀取的檔案是null字元結尾.
--version 顯示版本訊息.
--daemon 定義rsync以daemon型態執行.
--no-detach 當以daemon型態執行時,不要進行分裂且變成背景程序.
--address=ADDRESS 定義所要連結(bind)的ip位址或是host名稱(daemon限定)
--config=FILE 定義所要讀取的設定檔rsyncd.conf位置(daemon限定) 預設值為 /usr/local/etc/rsyncd.conf
--port=PORT 定義rsyncd(daemon)要執行的port(預設為tcp 873)
--blocking-io 使用blocking I/O連結遠端的shell,如rsh , remsh
--no-blocking-io 使用non-blocking連結遠端的shell,如ssh (預設值)
--stats 顯示檔案傳送時的資訊狀態
--progress 顯示傳送的進度.(給檔案傳送時,怕無聊的人用的..)
--log-format=FORMAT 定義log的格式(在rsyncd.conf設定)
--password-file=FILE 從檔案讀取與遠端rsync伺服器連結的密碼
--bwlimit=KBPS 定義傳輸頻寬的大小(KBytes/秒)
--write-batch=FILE 把紀錄資料寫入一個檔案(給其他相同環境且相同需求的機器使用)
--read-batch=FILE 透過讀取紀錄檔案來進行傳輸.(檔案由 --write-batch 參數產生)
--checksum-seed=NUM 定義檔案 checksum-seed 的大小(byte)
-4 --ipv4 使用IPv4協定
-6 --ipv6 使用IPv6協定
===== LOG Format =====
The "%i" escape has a cryptic output that is 11 letters long. The general format is like the string YXcstpoguax, where Y is replaced by the type of update being done, X is replaced by the file-type, and the other letters represent attributes that may be output if they are being modified.
log format "%i" 將輸出一個 11 個字母長的輸出\\
一般格式類似於字符串 YXcstpoguax,其中\\
Y 替換為正在完成的更新類型\\
X 替換為文件類型\\
其他字母表示如果它們被修改可能輸出的屬性\\
Y:\\
< means that a file is being transferred to the remote host (sent).
> means that a file is being transferred to the local host (received).
c means that a local change/creation is occurring for the item (such as the creation of a directory or the changing of a symlink, etc.).
h means that the item is a hard link to another item (requires --hard-links).
. means that the item is not being updated (though it might have attributes that are being modified).
* means that the rest of the itemized-output area contains a message (e.g. "deleting").
X:\\
f for a file
d for a directory
L for a symlink
D for a device
S for a special file (e.g. named sockets and fifos).
Decoding your example log file from the question:\\
https://stackoverflow.com/questions/4493525/what-does-f-mean-in-rsync-logs\\
**>f.st......**
> - the item is received
f - it is a regular file
s - the file size is different
t - the time stamp is different
**.d..t......**
. - the item is not being updated (though it might have attributes
that are being modified)
d - it is a directory
t - the time stamp is different
**>f+++++++++**
> - the item is received
f - a regular file
+++++++++ - this is a newly created item
The relevant part of the [[https://download.samba.org/pub/rsync/rsync.1#opt--itemize-changes|rsync man page]]: