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]
# serve 监听地址 (缺省 127.0.0.1)
# address = "127.0.0.1"
# serve 监听端口 (缺省 5731)
# port = 5731

[serve.cr4]
# 必填, Cloudreve 后端地址 (含 http(s) 协议, 如 https://demo.cloudreve.org)
server_url = "https://demo.cloudreve.org"
# 缺省按协议推断 (http=80 / https=443)
# server_port = 443
# 缺省 /api/v4
# server_api_path = "/api/v4"
# admin 组名覆盖; 缺省识别 Admin / 管理员
# admin_group = "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]
# 恒定 (仅支持 sqlite3)
type = "sqlite3"
# 缺省 ./data, sync-core sqlite 落到 <path>/sync_core/datas/.sync_db.sqlite3
# path = "./data"


# ============================================================================
# [conf]
# ============================================================================
[conf]
# 全局重试次数 (仅 up/dl 子命令), 缺省 3
# retry = 3
# CLI 产物基础目录 (credential/logs/data).
# "user" = $HOME/.cr4sync; 路径串 (如 "/opt/cr4sync") = 指定目录; 缺省 (不填) = 当前目录 (./)
# 只影响 CLI 子命令; serve 忽略
# cli_base_data_dir = "user"


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


# ============================================================================
# [log]
# ============================================================================
[log]
# cr4sync (缺省, 仅 cr4sync + sync_core) / full (输出所有依赖)
# mode = "cr4sync"
# trace/debug/info/warn/error, 缺省 info
# level = "info"
# 缺省 ./logs/sync_core.log
# log_path = "./logs/sync_core.log"
# 是否在终端输出日志 (缺省 true). false = 只写文件 (ls 等高交互命令用)
# --log-level 显式指定时强制开 terminal (覆盖 false)
# write_terminal = true
# sync/up/dl 是否在终端输出 worker 日志 (缺省 false)
# worker_log_terminal = false
# serve 子命令日志 (隔离), 仅 server 使用
# server_log_path = "./logs/server.log"


# ============================================================================
# ===== 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 = ""
# 是否启用代理 (代理在 source_credential 级)
# is_proxy = false
# 代理名 (引用 [[proxy]].name, is_proxy=true 时必填)
# proxy = "my-socks5"

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

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

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

# --- 直连模式 (自备应用) ---
# 需自备阿里云盘开放平台应用, 填 client_id/secret/redirect_uri.
# client_id = "your-app-id"
# client_secret = "your-app-secret"
# redirect_uri = "https://your-callback.com"
# resource (资源盘, 缺省) / backup (备份盘)
# drive_type = "resource"
# 直连模式下 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"
# 缺省 SDK 自动推断
# endpoint = "s3.us-east-1.amazonaws.com"
# MinIO 需 true
# force_path_style = false
# 是否启用代理 (代理在 source_credential 级)
# is_proxy = false
# 代理名 (引用 [[proxy]].name)
# proxy = "my-socks5"

[sources.oss]
# 阿里云 OSS, endpoint 自动拼为 https://oss-{region}.aliyuncs.com
# 必填
access_key_id     = "LTAI5t..."
# 必填
secret_access_key = "xxxxxxxxxxxx"
# 必填
region            = "cn-hangzhou"
# 必填
bucket            = "my-oss-bucket"
# 是否启用代理 (代理在 source_credential 级)
# is_proxy = false
# 代理名 (引用 [[proxy]].name)
# 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"
# COS 缺省 true
# force_path_style = true
# 是否启用代理 (代理在 source_credential 级)
# is_proxy = false
# 代理名 (引用 [[proxy]].name)
# proxy = "my-socks5"

[sources.pikpak]
# PikPak driver, 账密直接登录 (非 OAuth), 需代理访问.
# PikPak 账号邮箱
email             = "user@pikpak.com"
# PikPak 密码
password          = "your-password"
# 已持有的 refresh_token (可选)
# refresh_token = ""
# 设备 ID, 缺省 MD5(email+password)
# device_id = ""
# 验证码 token (可选, 缺省服务端自动获取)
# captcha_token = ""
# 是否启用代理 (PikPak 国内访问需代理)
# is_proxy = true
# 代理名
# 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).
# 必填, 源端 cloudreve 地址 (不带 /api/v4)
server_url = "https://demo.cloudreve.org"
# 邮箱 (CLI 登录用; serve 模式 webui 输入)
# username = "admin@example.com"
# 密码 (CLI 登录用; serve 模式 webui 输入)
# password = "your-password"
# download/login Referer, 缺省 = server_url
# referer = "https://demo.cloudreve.org"
# User-Agent, 缺省 pikpak web UA; serve 模式前端自动填浏览器 UA
# user_agent = "Mozilla/5.0 ..."
# 是否启用代理 (代理在 source_credential 级)
# is_proxy = false
# 代理名 (引用 [[proxy]].name)
# proxy = "my-socks5"


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

# [[proxy]]
# 必填, 用户内唯一
# name = "my-socks5"
# http / https / socks5 / socks5h
# scheme = "socks5"
# 代理主机地址
# 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"
# baidu / onedrive / aliyun / s3 / oss / cos / pikpak
driver      = "baidu"
# 源端起点 (缺省 /)
root_path   = "/我的资源"
# 必填, 目标 cloudreve URI
target_path = "cloudreve://my/baidu-backup"
# 单实例并发 (缺省 1, 上限 8)
parallelism = 1
# 源端 API QPS 上限 (缺省 3)
rate_limit  = 3
# 已废弃, 请在 [sources.xxx] 配置代理; 保留字段兼容旧配置
# is_proxy = false
# 已废弃, 请在 [sources.xxx] 配置代理; 保留字段兼容旧配置
# proxy = "my-socks5"

# 再加一个不同根的实例:
# [[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]
# 缺省 ./credential/license.lic (CLI 按 cli_base_data_dir 查找, serve 按 WorkingDirectory)
# serve 和 CLI 共用同一 license 时填绝对路径 (如 /opt/cr4sync/credential/license.lic)
# path = "./credential/license.lic"

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