Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

完整配置示例

下面是一份带全部已知字段的 cr4sync.toml,未填的行用 # 注释表明缺省值。把它放到工作目录或用 cr4sync -c /path/to/cr4sync.toml 指定。

# cr4sync 配置文件. 注释行可按需取消并填写.

# ============================================================================
# [serve] / [serve.cr4]
# ============================================================================
# - [serve]      cr4sync serve 子命令 HTTP 监听 (CLI 用户可全省)
# - [serve.cr4]  Cloudreve 后端连接 (CLI 与 server 都强依赖)

[serve]
# address = "127.0.0.1"     # serve 监听地址 (缺省 127.0.0.1)
# port    = 5731            # serve 监听端口 (缺省 5731)

[serve.cr4]
server_url      = "https://demo.cloudreve.org"  # 必填, 含 http(s) 协议
# server_port     = 443                          # 缺省按协议推断 (http=80 / https=443)
# server_api_path = "/api/v4"                    # 缺省 /api/v4
# admin_group     = "Admin"                      # admin 组名覆盖; 缺省识别 Admin / 管理员


# ============================================================================
# [credential]
# ============================================================================
# 危害提示: 此处明文保存账密有泄露风险 (配置文件常被备份 / 纳入版本控制).
#   推荐留空本段, 直接执行 `cr4sync login --mail x --passwd y` 完成一次性登录,
#   凭证仅落盘到 ./credential/token.json (已 .gitignore).
#   若在此填了 mail/passwd: token.json 不存在时仍需先执行 `cr4sync login`
#   (此时无需再带 --mail/--passwd).

[credential]
# mail   = ""
# passwd = ""


# ============================================================================
# [db]
# ============================================================================
[db]
type = "sqlite3"          # 恒定
# path = "./data"         # 缺省 ./data, sync-core sqlite 落到 <path>/sync_core/datas/.sync_db.sqlite3


# ============================================================================
# [conf]
# ============================================================================
[conf]
# retry = 3               # 全局重试次数 (仅 up/dl 子命令使用), 缺省 3


# ============================================================================
# [sync] -- cr4sync sync / SyncEngine 编排
# ============================================================================
[sync]
src           = "/home/data"   # 必填, 本地源目录, 不存在则终止
target        = "/"            # 必填, 远端目标 (/ -> cloudreve://my)
# worker        = 4              # 缺省 CPU 核数
# parallelism   = 3              # 缺省 3, 上限 512
# sync_mode     = "single"       # single (缺省) / incremental / append / two_way
# sync_conflict = "skip"         # skip (缺省, 真 no-op) / overwrite (本地覆盖远程)


# ============================================================================
# [log]
# ============================================================================
[log]
# mode                = "cr4sync"            # cr4sync (缺省, 仅 cr4sync + sync_core) / full (输出所有依赖)
# level               = "info"               # trace/debug/info/warn/error
# log_path            = "./logs/sync_core.log"
# worker_log_terminal = false                # sync/up/dl 是否在终端输出 worker 日志 (缺省 false)
# server_log_path     = "./logs/server.log"  # serve 子命令日志 (隔离), 仅 server 使用


# ============================================================================
# ===== migrate 子命令 (第三方网盘/对象存储 -> Cloudreve 单向迁移) =====
# ============================================================================
# 仅当使用 `cr4sync migrate` (alias `mgr`) 或 server 的迁移端点时需要.

[migrate]
# 预取下一 chunk 与上传重叠, 消除"下载等上传"停顿. CLI 与 server 均生效.
# auto(默认): chunk_size ≤ 100MB 自动预取; 大 chunk 不预取避免内存翻倍
# always: 强制预取   never: 永不预取
prefetch = "auto"
# 单 chunk 上传/下载失败重试次数, 默认 3, 上限 10. 指数退避 2s -> 4s -> 8s -> 16s -> 32s -> 60s (cap).
# 仅重试网络/服务端瞬时故障 + 锁冲突; 鉴权失败 / 一致性错 / 配置错不重试.
retry = 3
# cloudreve 锁冲突 (错误码 40073) 处置:
# auto(默认): 强制解锁 (DELETE /file/lock) -> 重试; 仍失败则跳过该 task (标 failed)
# skip: 直接跳过 (不解锁, 标 failed)
# force_unlock: 强制解锁 -> 重试; 仍失败则中止整个 job (其他未跑 task 不再发起)
conflict = "auto"
# 全局并发 job 上限 (server 模式), 默认 10, 上限 512; 调大需注意带宽/内存
# max_concurrent_jobs = 10
# 迁移权限申请审批模式: auto(申请即生效) / manual(管理员审批, 缺省)
# approve = "manual"
# PikPak range GET 限流间隔 (秒), 缺省 0.5. 出现 503 时可加大 (如 1.0). 仅 PikPak 生效.
# pikpak_range_optimization = 0.5

[sources.baidu]
# 三个字段缺省走内置 Alist 公开应用 (多人共享配额).
# 用户自己申请的开发者应用可在此覆盖, 独享配额.
# client_id     = ""
# client_secret = ""
# redirect_uri  = ""

# refresh_token 一次性导入. 留空走 `cr4sync login --baidu` 交互式粘贴 (推荐).
# refresh_token = ""
# is_proxy  = false                             # 是否启用代理 (代理在 source_credential 级)
# proxy     = "my-socks5"                       # 代理名 (引用 [[proxy]].name, is_proxy=true 时必填)

[sources.onedrive]
# OneDrive (Microsoft Graph) 无内置默认应用, 必须自备 Azure 应用.
# server 模式下用户在 login-session 传入, 此处为全局默认.
# client_id      = ""
# client_secret  = ""
# redirect_uri   = ""
# national_cloud = "global"       # global / china (21Vianet)
# is_proxy  = false                             # 是否启用代理 (代理在 source_credential 级)
# proxy     = "my-socks5"                       # 代理名 (引用 [[proxy]].name)

[sources.aliyun]
# 阿里云盘支持中转模式(推荐, 免注册)和直连模式(需自备开放平台应用).

# --- 中转模式 (推荐) ---
# 无需自备开放平台应用. 从扫码页拿到 refresh_token 填入即可.
# 扫码页: https://alistgo.com/zh/tool/aliyundrive/request.html
# client_id      = ""     # 留空则走中转模式
# client_secret  = ""
# redirect_uri   = ""
# oauth_token_url = "https://api.alistgo.com/alist/ali_open/token"  # 中转端点, 缺省 alist 官方中转
# refresh_token  = "your-refresh-token-from-scan-page"              # 扫码页获取的 refresh_token
# drive_type     = "resource"                                       # resource (资源盘, 缺省) / backup (备份盘)

# --- 直连模式 (自备应用) ---
# 需自备阿里云盘开放平台应用, 填 client_id/secret/redirect_uri.
# client_id      = "your-app-id"
# client_secret  = "your-app-secret"
# redirect_uri   = "https://your-callback.com"
# drive_type     = "resource"                                       # resource (资源盘, 缺省) / backup (备份盘)
# 直连模式下 oauth_token_url 和 refresh_token 忽略

[sources.s3]
# S3 兼容对象存储 (AWS S3 / MinIO 等), 无 OAuth, 静态凭证.
access_key_id     = "AKIAIOSFODNN7EXAMPLE"
secret_access_key = "wJalrXUtFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
region            = "us-east-1"
bucket            = "my-s3-bucket"
# endpoint          = "s3.us-east-1.amazonaws.com"   # 缺省 SDK 自动推断
# force_path_style  = false                           # MinIO 需 true
# is_proxy          = false                           # 是否启用代理 (代理在 source_credential 级)
# proxy             = "my-socks5"                     # 代理名 (引用 [[proxy]].name)

[sources.oss]
# 阿里云 OSS, endpoint 自动拼为 https://oss-{region}.aliyuncs.com
access_key_id     = "LTAI5t..."
secret_access_key = "xxxxxxxxxxxx"
region            = "cn-hangzhou"
bucket            = "my-oss-bucket"
# is_proxy         = false                             # 是否启用代理 (代理在 source_credential 级)
# proxy            = "my-socks5"

[sources.cos]
# 腾讯云 COS, endpoint 自动拼为 https://cos.{region}.myqcloud.com
# bucket 必须含 APPID: <bucketname>-<APPID>
access_key_id     = "AKID..."
secret_access_key = "xxxxxxxxxxxx"
region            = "ap-guangzhou"
bucket            = "my-bucket-1250000000"
# force_path_style  = true                            # COS 缺省 true
# is_proxy          = false                           # 是否启用代理 (代理在 source_credential 级)
# proxy             = "my-socks5"

[sources.pikpak]
# PikPak driver, 账密直接登录 (非 OAuth), 需代理访问.
email             = "user@pikpak.com"                  # PikPak 账号邮箱
password          = "your-password"                    # PikPak 密码
# refresh_token    = ""                                # 已持有的 refresh_token (可选)
# device_id        = ""                                # 设备 ID, 缺省 MD5(email+password)
# captcha_token    = ""                                # 验证码 token (可选, 缺省服务端自动获取)
# is_proxy         = true                              # 是否启用代理 (PikPak 国内访问需代理)
# proxy            = "my-socks5"                       # 代理名

[sources.cloudreve]
# Cloudreve 源 driver (远端 cloudreve 实例作为迁移源). 复用 sync-core ApiClient + AuthClient.
# CLI 登录: cr4sync login --cloudreve (探测验证码, 开启则报错"cli 不支持, 用 serve 模式").
# serve 模式: webui 登录复用 CaptchaWidget (去二维码, 支持验证码/2FA).
# token 存 credential/sources/cloudreve.json (CLI) 或 source_credential 表 (server).
server_url = "https://demo.cloudreve.org"               # 必填, 源端 cloudreve 地址 (不带 /api/v4)
# username  = "admin@example.com"                       # 邮箱 (CLI 登录用; serve 模式 webui 输入)
# password  = "your-password"                           # 密码 (CLI 登录用; serve 模式 webui 输入)
# referer   = "https://demo.cloudreve.org"              # download/login Referer, 缺省 = server_url
# user_agent = "Mozilla/5.0 ..."                        # User-Agent, 缺省 pikpak web UA; serve 模式前端自动填浏览器 UA
# is_proxy  = false
# proxy     = "my-socks5"


# ============================================================================
# ===== [[proxy]] 代理配置 (数组段, 可多个) =====
# ============================================================================
# 通用代理, 为第三方网盘 driver 访问提供代理出站能力.
# 代理在 source_credential 级 (driver 登录时绑定), 通过 [sources.xxx] 的 is_proxy + proxy 引用.

# [[proxy]]
# name     = "my-socks5"                    # 必填, 用户内唯一
# scheme   = "socks5"                       # http / https / socks5 / socks5h
# host     = "192.168.1.100"                # 代理主机地址
# port     = 1080                           # 代理端口
# username = "user1"                        # 代理认证用户名 (可选)
# password = "pass123"                      # 代理认证密码 (可选)

# [[proxy]]
# name     = "corp-http"
# scheme   = "http"
# host     = "proxy.corp.com"
# port     = 3128


# 一个 [[storage]] 段 = 一个独立的迁移任务实例.
# 可以重复出现多次, 各自用不同的 name 区分, `cr4sync mgr -s <name>` 选择.

[[storage]]
name        = "main-baidu"                      # 必填, 全局唯一
driver      = "baidu"                           # baidu / onedrive / aliyun / s3 / oss / cos / pikpak
root_path   = "/我的资源"                       # 源端起点 (缺省 /)
target_path = "cloudreve://my/baidu-backup"    # 必填, 目标 cloudreve URI
parallelism = 1                                 # 单实例并发 (缺省 1, 上限 8)
rate_limit  = 3                                 # 源端 API QPS 上限 (缺省 3)
# is_proxy  = false                             # 已废弃, 请在 [sources.xxx] 配置代理; 保留字段兼容旧配置
# proxy     = "my-socks5"                       # 已废弃, 请在 [sources.xxx] 配置代理; 保留字段兼容旧配置

# 再加一个不同根的实例:
# [[storage]]
# name        = "music"
# driver      = "baidu"
# root_path   = "/音乐"
# target_path = "cloudreve://my/music-backup"

# S3 / OSS / COS storage 示例:
# [[storage]]
# name        = "main-s3"
# driver      = "s3"
# root_path   = "/"
# target_path = "cloudreve://my/s3-backup"

# [[storage]]
# name        = "main-oss"
# driver      = "oss"
# root_path   = "/"
# target_path = "cloudreve://my/oss-backup"

# [[storage]]
# name        = "main-cos"
# driver      = "cos"
# root_path   = "/"
# target_path = "cloudreve://my/cos-backup"

# OneDrive / 阿里云盘 storage 示例:
# [[storage]]
# name        = "main-onedrive"
# driver      = "onedrive"
# root_path   = "/Documents"
# target_path = "cloudreve://my/onedrive-backup"

# [[storage]]
# name        = "main-aliyun"
# driver      = "aliyun"
# root_path   = "/文档"
# target_path = "cloudreve://my/aliyun-backup"
# [license]
# path = "./credential/license.lic"   # license 文件路径 (缺省 ./credential/license.lic)

server 模式下 [[storage]] 段会被忽略——server 的 storage 改由 POST /api/v4/cr4sync/source/:driver/storage 端点(driver ∈ baidu/onedrive/aliyun/s3/oss/cos/pikpak)写入 server.dbstorage 表,每用户独立。CLI 仍以 [[storage]] 段为准。