================================================================
【Ubuntu 雙硬碟備份至 RDISK 雲端硬碟標準作業程序 (SOP)】
================================================================
■ 備份核心策略(大小檔案分流法)
1. 小檔案 (< 1GB):用 tar 於本地打包成單一檔 -> 傳至 RDISK -> 解開建立目錄骨架。
2. 大檔案 (>= 1GB):透過 FreeFileSync 視覺化比對,直接傳輸與斷點續傳。
3. 雲端限制處理:解壓時加入 --no-same-owner --touch 避開權限與 FIFO pipe 報錯。
----------------------------------------------------------------
【第一階段:系統碟 (主硬碟 /home/steven) 備份】
----------------------------------------------------------------
步驟 1:產出大於 1GB 的大檔案排除清單
find /home/steven -type f -size +1G \
-not -path "*/data/*" \
-not -path "*/RDISK/*" \
-not -path "*/.cache/*" \
> /tmp/exclude_main_large_files.txt
步驟 2:打包小檔案(暫存至第二顆硬碟)
tar -cf /home/steven/data/home_small_files.tar \
--exclude-from=/tmp/exclude_main_large_files.txt \
--ignore-failed-read \
--warning=no-file-changed \
--exclude='/home/steven/.cache' \
--exclude='/home/steven/.local/share/Trash' \
--exclude='/home/steven/.local/share/waydroid' \
--exclude='/home/steven/snap' \
--exclude='/home/steven/data' \
--exclude='/home/steven/RDISK' \
/home/steven
步驟 3:複製到 RDISK、解開並清理壓縮包
mkdir -p /home/steven/RDISK/home_backup
rsync -avh --progress /home/steven/data/home_small_files.tar /home/steven/RDISK/
tar -xf /home/steven/RDISK/home_small_files.tar -C /home/steven/RDISK/home_backup/ --no-same-owner --touch --warning=no-timestamp
rm -f /home/steven/RDISK/home_small_files.tar
----------------------------------------------------------------
【第二階段:資料碟 (第二顆硬碟 /home/steven/data) 備份】
----------------------------------------------------------------
步驟 1:產出大於 1GB 的大檔案排除清單
find /home/steven/data -type f -size +1G \
-not -path "*/home_backup*" \
-not -path "*/lost+found*" \
> /tmp/exclude_data_large_files.txt
步驟 2:打包小檔案
tar -cf /home/steven/data/data_small_files.tar \
--exclude-from=/tmp/exclude_data_large_files.txt \
--ignore-failed-read \
--warning=no-file-changed \
--exclude='/home/steven/data/home_backup*' \
--exclude='/home/steven/data/home_small_files.tar' \
--exclude='/home/steven/data/lost+found' \
/home/steven/data
步驟 3:複製到 RDISK、解開並清理所有暫存 tar 檔
mkdir -p /home/steven/RDISK/data_backup
rsync -avh --progress /home/steven/data/data_small_files.tar /home/steven/RDISK/
tar -xf /home/steven/RDISK/data_small_files.tar -C /home/steven/RDISK/data_backup/ --no-same-owner --touch --warning=no-timestamp
rm -f /home/steven/RDISK/data_small_files.tar
rm -f /home/steven/data/data_small_files.tar
rm -f /home/steven/data/home_small_files.tar
----------------------------------------------------------------
【第三階段:大檔案同步與日常維護 (FreeFileSync)】
----------------------------------------------------------------
開啟 FreeFileSync 進行圖形化比對與同步:
1. 系統碟設定:
- 來源端(左):/home/steven
- 目標端(右):/home/steven/RDISK/home_backup/home/steven
2. 資料碟設定:
- 來源端(左):/home/steven/data
- 目標端(右):/home/steven/RDISK/data_backup/home/steven/data
3. 執行步驟:
點擊「比較 (Compare)」檢視差異 -> 點擊「同步 (Synchronize)」。
----------------------------------------------------------------
【實用監控與工具指令】
----------------------------------------------------------------
1. 精確監控 tar 背景寫入進度(每秒刷新 Byte 數):
watch -n 1 "ls -l /home/steven/data/data_small_files.tar | awk '{print \$5 \" Bytes\"}'"
2. 系統映像檔 (.img) 瘦身工具 (PiShrink):
sudo pishrink.sh -z 原映像檔.img 瘦身後映像檔.img
================================================================