差異處
這裏顯示兩個版本的差異處。
兩邊的前次修訂版 前次修改 下次修改 | 前次修改 | ||
tech:rclone [2019/03/01 00:18] – [設定 rclone 對 Google Drive 的 config] jonathan_tsai | tech:rclone [2025/03/17 13:12] (目前版本) – [設定每天 2:00 執行一次] jonathan | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== 使用 rclone 同步 Google Drive 檔案 ====== | ||
+ | |||
+ | 因為愈來愈多檔案存放在 Google Drive, 所以要考慮一個自動的機制將檔案同步回自己的電腦主機內. | ||
+ | |||
+ | ===== 安裝方式 ===== | ||
+ | ==== Alpine 3 ==== | ||
+ | * 安裝環境 : Alpine Linux 3.18 | ||
+ | * 設定 cifs 掛上 NAS 目錄 : [[alpine_cifs]] | ||
+ | * <cli> | ||
+ | apk add rclone | ||
+ | rclone version | ||
+ | </ | ||
+ | * ++看結果|< | ||
+ | pve-alpine3: | ||
+ | rclone v1.62.2-DEV | ||
+ | - os/version: alpine 3.18.6 (64 bit) | ||
+ | - os/kernel: 6.1.84-0-lts (x86_64) | ||
+ | - os/type: linux | ||
+ | - os/arch: amd64 | ||
+ | - go/version: go1.20.11 | ||
+ | - go/linking: static | ||
+ | - go/tags: none | ||
+ | </ | ||
+ | |||
+ | ==== CentOS 7 ==== | ||
+ | * 安裝環境 : CentOS Linux release 7.7.1908 (Core) | ||
+ | * 安裝相關套件 <code sh> | ||
+ | yum install curl unzip man-db | ||
+ | </ | ||
+ | * 開始安裝 rclone <code sh> | ||
+ | curl https:// | ||
+ | </ | ||
+ | * 安裝成功後可以下以下指令確認版本 <code sh> | ||
+ | rclone version | ||
+ | </ | ||
+ | * ++看結果|< | ||
+ | [root@ct-cloudsync ~]# rclone version | ||
+ | rclone v1.50.1 | ||
+ | - os/arch: linux/amd64 | ||
+ | - go version: go1.13.4 | ||
+ | </ | ||
+ | |||
+ | ===== 設定 rclone 對 Google Drive / Photos Library API 的 config ===== | ||
+ | * 依據 rclone 的說明, 如果使用量大, | ||
+ | * 申請 Google API oAuth 的方式 : | ||
+ | - 連上 Google Developer Console - https:// | ||
+ | - 選擇一個專案 (第一次使用請先建立專案) ++看畫面|{{: | ||
+ | - 啟用 Google Drive API++看畫面|{{: | ||
+ | - 啟用 Photos Library API++看畫面|{{: | ||
+ | - 建立 oAuth 憑證++看畫面|{{: | ||
+ | * 進行 rclone config 的建立 <code sh> | ||
+ | - n) New Remote (建立一個新的遠端連結定義) | ||
+ | - name> (設定這個遠端連結定義名稱) Exp. JonathanGooglePhotos | ||
+ | - Storage> (選擇 Cloud Storage 類型) | ||
+ | - 如果是 Google Drive 就要選 -> **15 Google Drive** | ||
+ | - 如果是要同步 Google 相簿 就要選 -> **16 Google Photos** | ||
+ | - client_id> | ||
+ | - client_secret> | ||
+ | - scope> (如果想雙向同步就選可讀寫 1, 若指向備份回本地端就選唯讀 2) | ||
+ | - root_folder_id> | ||
+ | - service_account_file> | ||
+ | - Edit advanced config? (y/n) n | ||
+ | - Remote config Use auto config? (y/n) n <- 因為直接在 Linux Console 無法本機端有瀏覽器, | ||
+ | - 將出現的網址 https:// | ||
+ | - 登入 Google 帳號 | ||
+ | - 允許 rclone 的授權 | ||
+ | - 將產生的授權碼複製下來 Exp. 4/ | ||
+ | - Enter verification code> (輸入瀏覽器產生的授權碼) | ||
+ | - Configure this as a team drive? (y/n) (個人的 Drive 就選 n) | ||
+ | - y/e/d> (如果呈現的設定都沒問題就選 y) | ||
+ | - q (離開 config 選單) | ||
+ | |||
+ | ===== 使用 rclone 讀取 Google Drive 的語法 ===== | ||
+ | * 列出所有檔案 <code sh> | ||
+ | * 只列出目錄 <code sh> | ||
+ | * 將所有檔案複製回本機 / | ||
+ | |||
+ | |||
+ | ===== 設定每天 2:00 執行一次 ===== | ||
+ | * 設定到 crontab <code sh> vi / | ||
+ | : | ||
+ | 0 2 * * * root rclone copy --max-age 48h --no-traverse -v JonathanGooglePhotos:/ | ||
+ | </ | ||
+ | * 重新啟動 crond <code sh> | ||
+ | |||
+ | |||
+ | < | ||
+ | * 如果要設定可以自動寄出 log 內容, 可先參考 [[tech: | ||
+ | * 將 / | ||
+ | : | ||
+ | 0 2 * * * root rclone copy --max-age 48h --no-traverse -v JonathanGooglePhotos:/ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <note tip> | ||
+ | * 如果要改用 webhook 方式進行通知(Exp. Discord, Teams...) | ||
+ | - 先安裝 bash, jq 與 curl Exp. <cli> | ||
+ | apk add bash jq curl | ||
+ | </ | ||
+ | - 下載 [[https:// | ||
+ | curl -o / | ||
+ | chmod a+x / | ||
+ | </ | ||
+ | - 將 crontab 內容改成< | ||
+ | : | ||
+ | 0 2 * * * root rclone copy --max-age 48h --no-traverse -v JonathanGooglePhotos:/ | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | ===== 更新 rclone 方式 ===== | ||
+ | * 其實和開始安裝 rclone 的語法相同< | ||
+ | curl https:// | ||
+ | </ | ||
+ | * 更新後的結果< | ||
+ | Processing manual pages under / | ||
+ | Purging old database entries in / | ||
+ | Processing manual pages under / | ||
+ | Purging old database entries in / | ||
+ | Processing manual pages under / | ||
+ | Purging old database entries in / | ||
+ | Processing manual pages under / | ||
+ | 0 man subdirectories contained newer manual pages. | ||
+ | 0 manual pages were added. | ||
+ | 0 stray cats were added. | ||
+ | 0 old database entries were purged. | ||
+ | |||
+ | rclone v1.54.0 has successfully installed. | ||
+ | Now run " | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== 參考網址 ===== | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | |||
+ | {{tag> | ||