目錄表

使用 RClone(Docker) 設定同步 Google Photo/Drive 回本地

安裝程序

  1. 下載 docker-compose.yml 相關檔案

    wget https://raw.githubusercontent.com/tryweb/docker-compose/refs/heads/main/rclone/docker-compose.yml
    wget https://raw.githubusercontent.com/tryweb/docker-compose/refs/heads/main/rclone/.env.example
    wget https://raw.githubusercontent.com/tryweb/docker-compose/refs/heads/main/rclone/root_crontab
    mv .env.example .env

    docker-compose.yml
    services:
      rclone-webui:
        image: rclone/rclone
        container_name: rclone-webui
        ports:
          - "5572:5572"
        environment:
          - RCLONE_RC_USER=${RCLONE_RC_USER}
          - RCLONE_RC_PASS=${RCLONE_RC_PASS}
        volumes:
          - ./rclone-config:/config/rclone
          #- /nas_Photos:/nas_Photos
        command: rcd --rc-web-gui --rc-addr 0.0.0.0:5572
     
      rclone-cron:
        image: ghcr.io/tryweb/docker-compose/rclone-cron:latest
        container_name: rclone-cron
        environment:
          - TZ=Asia/Taipei
          - TITLE=${TITLE}
          - WEBHOOK_URL=${WEBHOOK_URL}      
        volumes:
          - ./rclone-config:/root/.config/rclone
          - ./root_crontab:/etc/crontabs/root
          - ./cron-logs:/var/log/cron
          #- /nas_Photos:/nas_Photos
     

    https://raw.githubusercontent.com/tryweb/docker-compose/refs/heads/main/rclone/docker-compose.yml

    1. 請在 volumes 加上要備份到本地端的目錄 Exp. /nas_Photos:/nas_Photos
    2. 在 rclone-webui 與 rclone-cron 兩個服務容器都要加
  2. 編輯 .env 檔案
    .env
    RCLONE_RC_USER=admin
    RCLONE_RC_PASS="MyPass_111"
    TITLE="RClone sync Google..."
    WEBHOOK_URL="https://discord.com/api/webhooks/1312345678901234568/WxFhpsy-hqwertyuiopasdfghjklpzxcvbnm123LNJ0kYFnC"
     

    https://raw.githubusercontent.com/tryweb/docker-compose/refs/heads/main/rclone/.env.example

    1. 請修改 Web 登入的帳號(RCLONE_RC_USER)與密碼(RCLONE_RC_PASS)
    2. 請修改 Discord 通知時的 Title
    3. 請修改 Discord 通知的 WebHook URL (請到 Discord 的通知頻道產生)
  3. 啟動 docker compose

    docker compose pull
    docker compose up -d

  4. 登入 Web UI Exp. http://192.168.11.243:5572/
    1. 成功登入後畫面
    2. 到 config 進行新增 Google Photo / Drive 的設定

    3. 儲存後應該就可以看到類似以下的 config 清單
    4. 也可以到主機端看產生的 rclone.conf

      # cat rclone-config/rclone.conf
      [EverplastGoogle]
      type = drive
      client_id = 5100000070-hrhklfhjdfhsd1rfhs1.apps.googleusercontent.com
      client_secret = rTYxxxxxxxxxxxxxxxxxxxxd
      scope = drive.readonly
      token = {"access_token":"ya29.a0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxUeD449TBTsJIv9htJ6Q0178","token_type":"Bearer","refresh_token":"1//0eUHhK-CxxxxxxxxxxxxxxxxSNwF-W5CU","expiry":"2025-04-21T19:39:59.759797588+08:00"}
      root_folder_id = 0BxxxxxxxxxY-aFxxxxxxxxxxeVk
      
      [JonathanGooglePhotos]
      type = google photos
      client_id = 51xxxxxx70-hrxxxxxxxxxxxx1rfhs1.apps.googleusercontent.com
      client_secret = rTYxxxxxxxxxxxxxxxxxxxxxd
      read_only = true
      token = {"access_token":"ya29.a0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxQV-sS3xxxxxxxxxxxxxt3qsUjQwfitN7YMjLnBPw0178","token_type":"Bearer","refresh_token":"1//0efrxxxxxxxxL9IrJY0_EQNxxxxxxxxxxxxxxxxxxx3nd_2aTElCiZNxxxxxxmyxAfY","expiry":"2025-04-21T19:13:59.96375334+08:00"}
      
      [NAS145WorkDir]
      type = ftp
      host = 192.168.11.145
      pass = flxxxxxx6-QDxxxxxxxxxx5tp_nTxxxxxg
      user = jonathan
      
      #

  5. 編輯 root_crontab 檔案
    root_crontab
    # rclone-job
    SHELL=/bin/sh
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
     
    * * * * * date >> /var/log/cron/test.log 2>&1 && send_logs_to_discord.sh TITLE="RClone Cron Test..." LOG_FILE="/var/log/cron/test.log"
    #20 17 * * * rclone copy --max-age 48h --no-traverse -v GooglePhotos:/media/by-year/ /nas_Photos/GooglePhotos/ > /var/log/cron/GooglePhotos.log 2>&1 && send_logs_to_discord.sh TITLE="RClone sync Google Photos..." LOG_FILE="/var/log/cron/GooglePhotos.log"
     
     
     

    https://raw.githubusercontent.com/tryweb/docker-compose/refs/heads/main/rclone/root_crontab

    1. 預設每分鐘會跑測試通知一次, 確認 cron-job 是否正確運作, 如果沒問題就可以將這測試項目加上 # 關閉
      :
      #* * * * * date >> /var/log/cron/test.log 2>&1 && send_logs_to_discord.sh TITLE="RClone Cron Test..." LOG_FILE="/var/log/cron/test.log"
      :
    2. 加上實際需要執行 rclone 的項目 Exp. 每天 17:20 執行一次 JonathanGooglePhotos 項目, 將最近 48 小時內新增的相片同步回 /nas_Photos/GooglePhotos/ 內, 並將結果用 RClone sync Google Photos… 當標題以 Discord 進行通知
      :
      20 17 * * * rclone copy --max-age 48h --no-traverse -v JonathanGooglePhotos:/media/by-year/ /nas_Photos/GooglePhotos/ > /var/log/cron/GooglePhotos.log 2>&1 && send_logs_to_discord.sh TITLE="RClone sync Google Photos..." LOG_FILE="/var/log/cron/GooglePhotos.log"
    3. 修改完成後, 必須重起 rclone-cron 服務才會生效

      docker compose restart rclone-cron
      # docker compose restart rclone-cron
      [+] Restarting 1/1
       ✔ Container rclone-cron  Started
      #

參考網址