跳到正文
快速上手

VPS、Docker 与密钥环

在无桌面环境的 Linux 服务器与非 root Docker 容器中部署 rship,涵盖路径隔离、跨主机凭据包迁移与系统密钥环管理。

rship 不依赖桌面环境,也不强求运行 D-Bus 密钥环,在几美元一台的入门 VPS、CI 构建机或精简容器里都能直接跑稳。

配置与状态路径隔离#

所有 rship 子命令都支持 --config 和 --state-dir(也可用环境变量 RSHIP_CONFIG、RSHIP_STATE_DIR),方便按任务隔离配置,或统一挂载到容器卷里:

bash
# 查看本机默认的 config.toml、状态库和令牌存放路径
rship config path

# 为单次任务显式指定独立的配置和状态目录
rship --config /srv/rship/config.toml --state-dir /srv/rship/state ls gdrive:

Linux 下默认遵循 XDG 目录规范,配置文件位于 ~/.config/rship/config.toml,OAuth 令牌保存在 ~/.local/share/rship/tokens/<remote>.json。

把桌面端授权迁移到远程 VPS#

没有浏览器、也没有系统密钥环的远程服务器不用折腾 OAuth 回调:先在本地电脑完成授权,再把自包含的凭据包导过去就行。rship auth export 会自动把 keyring:// 引用的密钥取出来一起打包,远端执行 rship auth import 后会直接写成 0600 权限的本地文件:

bash
# 1. 在本地电脑导出凭据包(自动解析 keyring:// 密钥)
rship auth export gdrive -o gdrive.bundle

# 2. 通过 SSH 传到 VPS,导入后顺手删掉临时文件
scp gdrive.bundle user@vps:~/
ssh user@vps 'rship auth import --input ~/gdrive.bundle && rm -f ~/gdrive.bundle'

# 3. 确认配置路径并测试连通性
ssh user@vps 'rship config path && rship config test gdrive'

Docker 与 Docker Compose#

把 config.toml 和 state/(里面存放 tokens/ 与 SQLite WAL 状态库)放在宿主机目录(比如 /srv/rship),再挂载进容器即可:

yaml
services:
  rship-worker:
    image: alpine:latest
    environment:
      - RSHIP_CONFIG=/rship/config.toml
      - RSHIP_STATE_DIR=/rship/state
    volumes:
      - /srv/rship:/rship
      # 可选:直接挂载静态链接的 Linux musl 二进制(零运行时依赖)
      - /usr/local/bin/rship:/usr/local/bin/rship:ro
    command: ["rship", "sync", "/data", "gdrive:backups", "--adaptive", "--max-delete", "100"]

桌面端使用系统密钥环#

在带桌面环境的系统(Windows、macOS,以及开启了 Secret Service 的 Linux)上,可以把 config.toml 里的明文密钥统一迁入系统密钥环:

bash
# 把 client secret、S3 密钥、SFTP 密码和加密库口令统一迁入 keyring://rship/...
rship auth keyring-migrate

# 确认配置文件里的明文已替换成 keyring:// 引用
rship config show

生产环境常见用法#

1. 夜间加密定时备份(Cron / Systemd)#

用 flock -n 防止上一次任务还没跑完就重叠触发,再配合 --max-delete 避免源目录异常挂空导致误删:

bash
flock -n /tmp/rship-nightly.lock \
  rship sync /srv/data vault:nightly --adaptive --max-buffer-mem 16M --max-delete 100

2. 不落本地磁盘的云间直迁#

借助有界 BufferPool 在内存中流式中转,无需把归档先下载到 VPS 磁盘就能跨云拷贝:

bash
rship copy gdrive:archive r2:archive --adaptive --max-buffer-mem 16M

3. 数据库导出后直接流式写入加密库#

把 pg_dump 压缩后的标准输出直接灌进客户端加密库,省去本地临时备份文件:

bash
pg_dump prod | zstd -T0 | rship rcat vault:db/prod-$(date +%F).sql.zst