f Postgres rsync 備份失敗的除錯 ~ 迪貝之家

Pages

Postgres rsync 備份失敗的除錯

 

因為這是從8.x的版本升級到9.2
那時候還沒有pg_basebackup
只有用rsync來進行差異備份
所以就沿用到了現在
出現error
只好進行debug囉~~
+ rsync -av --delete --exclude=/scmdb/Initial/pg_xlog --exclude=/scmdb/Initial/dbserver_logs /scmdb/Initial/ /BACKUP/main_sync
+ exitIfFail
+ '[' 24 -ne 0 ']' - 因為shell return code $? 不是0, 所以被認為rsync有錯誤,把備份程式該跑的流程給中斷掉了
+ '[' started ']'
+ psql -ec 'SELECT pg_stop_backup();'
SELECT pg_stop_backup();
pg_stop_backup
----------------
A992/46718F80
(1 row)
+ exit 0 <- 退出shell
去調看rsync的man page 裡頭對exit code 24的描述,底下是相應的man page 擷圖

rsync exit code

再對照rsync 的錯誤記錄檔最後一行的內容
rsync warning: some files vanished before they could be transferred (code 24) at main.c(892) [sender=2.6.8]
表示rsync在進行中,有檔案不見了
再去找記錄檔的內容,發現如下
file has vanished: "/scmdb/Initial/data/pg_xlog/000000010000A99200000026"
file has vanished: "/scmdb/Initial/data/pg_xlog/000000010000A99200000027"
file has vanished: "/scmdb/Initial/data/pg_xlog/000000010000A99200000028"
file has vanished: "/scmdb/Initial/data/pg_xlog/000000010000A99200000029"
file has vanished: "/scmdb/Initial/data/pg_xlog/000000010000A9920000002A"
file has vanished: "/scmdb/Initial/data/pg_xlog/000000010000A9920000002B"
file has vanished: "/scmdb/Initial/data/pg_xlog/000000010000A9920000002C"
file has vanished: "/scmdb/Initial/data/pg_xlog/000000010000A9920000002D"
這些檔案是Postgres的online交易記錄檔
Checkpoint等作業完成後,系統會自行清掉或者recycle使用,用以釋放空間
正常來說, rsync 寫script的時候,應該會把該目錄排除掉
因此對照了這封mail第一行rsync 指令 exclude 的開關
--exclude=/scmdb/Initial/pg_xlog
路徑中少了data
就是這樣

####2020/08/25#############
嘿....又接到備份失敗
查了一下rsync的記錄
file has vanished: "/scmdb/Initial/data/pg_xlog/000000010000AADE000000C7"
file has vanished: "/scmdb/Initial/data/pg_xlog/000000010000AADE000000C8"
file has vanished: "/scmdb/Initial/data/pg_xlog/000000010000AADE000000C9"
又是它 ???
奇怪了~~ 我上次不是修改了exclude的參數嗎 ?
只好再去問谷大哥啦~~
原來rsync --exclude 只認relative path
哈....還真是....
請看....
rsync exclude
這是人家的Po文
還是尊重一下人家敲文的心血
How To Use Rsync To Exclude Files And Directories In Data Transfer