跳到正文

将 S4 对象存储与 Rclone 结合使用

Rclone 是命令行同步工具,支持 Windows、macOS 和 Linux,适合批量上传、备份、跨云迁移和挂载。

前置条件

安装

winget install Rclone.Rclone
brew install rclone
curl https://rclone.org/install.sh | sudo bash

Windows 的命令请在 PowerShell 里运行,示例里的 D:\ 换成自己的目录。

macOS 上用 Homebrew 安装的版本不能挂载,需要 挂载 时请从 Rclone 官网 下载。

配置

运行 rclone config file 查看配置文件位置,写入以下内容:

rclone.conf
[s4]
type = s3
provider = Other
env_auth = false
access_key_id = 你的 AccessKey
secret_access_key = 你的 SecretKey
endpoint = https://s3.bitiful.net
region = cn-east-1
list_version = 2
no_check_bucket = true
配置项说明
endpoint、region固定为上面的值
list_version = 2使用 ListObjectsV2
no_check_bucket = true上传前不检查、不创建桶。子账户没有建桶权限,必须设置

或者用一条命令创建:

PowerShell
rclone.exe config create s4 s3 provider=Other env_auth=false access_key_id="你的 AccessKey" secret_access_key="你的 SecretKey" endpoint=https://s3.bitiful.net region=cn-east-1 list_version=2 no_check_bucket=true
rclone config create s4 s3 provider=Other env_auth=false access_key_id="你的 AccessKey" secret_access_key="你的 SecretKey" endpoint=https://s3.bitiful.net region=cn-east-1 list_version=2 no_check_bucket=true
rclone config create s4 s3 provider=Other env_auth=false access_key_id="你的 AccessKey" secret_access_key="你的 SecretKey" endpoint=https://s3.bitiful.net region=cn-east-1 list_version=2 no_check_bucket=true

验证配置,列出桶里的内容:

PowerShell
rclone.exe lsf s4:my-bucket
rclone lsf s4:my-bucket
rclone lsf s4:my-bucket

配置文件里的密钥没有加密。多人使用的机器上,用 rclone config 设置配置密码,或改用环境变量 RCLONE_CONFIG_S4_ACCESS_KEY_ID、RCLONE_CONFIG_S4_SECRET_ACCESS_KEY。

上传与下载

PowerShell
# 上传单个文件到目录
rclone.exe copy D:\logo.png s4:my-bucket/images/

# 上传目录,显示进度
rclone.exe copy D:\documents s4:my-bucket/documents -P

# 指定浏览器缓存时间
rclone.exe copy D:\assets s4:my-bucket/assets --header-upload "Cache-Control: max-age=31536000"

# 备份数据库并上传
mysqldump.exe mydb --result-file=D:\backup\mydb.sql
rclone.exe copy D:\backup\mydb.sql s4:my-bucket/backup/

# 下载
rclone.exe copy s4:my-bucket/images/logo.png D:\
# 上传单个文件到目录
rclone copy ./logo.png s4:my-bucket/images/

# 上传目录,显示进度
rclone copy ./documents s4:my-bucket/documents -P

# 指定浏览器缓存时间
rclone copy ./assets s4:my-bucket/assets --header-upload "Cache-Control: max-age=31536000"

# 把命令输出直接写成对象
mysqldump mydb | gzip | rclone rcat s4:my-bucket/backup/mydb.sql.gz

# 下载
rclone copy s4:my-bucket/images/logo.png ./
# 上传单个文件到目录
rclone copy ./logo.png s4:my-bucket/images/

# 上传目录,显示进度
rclone copy ./documents s4:my-bucket/documents -P

# 指定浏览器缓存时间
rclone copy ./assets s4:my-bucket/assets --header-upload "Cache-Control: max-age=31536000"

# 把命令输出直接写成对象
mysqldump mydb | gzip | rclone rcat s4:my-bucket/backup/mydb.sql.gz

# 下载
rclone copy s4:my-bucket/images/logo.png ./

copy 只传新增和有变化的文件,可以反复执行。

查看与管理

PowerShell
rclone.exe lsf s4:my-bucket/images               # 列出文件名
rclone.exe lsl s4:my-bucket/images               # 列出大小和时间
rclone.exe tree s4:my-bucket/images              # 树状显示
rclone.exe size s4:my-bucket/documents           # 统计数量与容量
rclone.exe cat s4:my-bucket/notes/todo.txt       # 查看内容

rclone.exe moveto s4:my-bucket/a.txt s4:my-bucket/b.txt   # 改名
rclone.exe delete s4:my-bucket/tmp --min-age 30d          # 删除 30 天前的文件
rclone.exe purge s4:my-bucket/tmp                         # 删除整个目录,无法恢复

rclone.exe link s4:my-bucket/images/logo.png --expire 1h  # 临时下载链接,最长 7 天
rclone lsf s4:my-bucket/images               # 列出文件名
rclone lsl s4:my-bucket/images               # 列出大小和时间
rclone tree s4:my-bucket/images              # 树状显示
rclone size s4:my-bucket/documents           # 统计数量与容量
rclone cat s4:my-bucket/notes/todo.txt       # 查看内容

rclone moveto s4:my-bucket/a.txt s4:my-bucket/b.txt   # 改名
rclone delete s4:my-bucket/tmp --min-age 30d          # 删除 30 天前的文件
rclone purge s4:my-bucket/tmp                         # 删除整个目录,无法恢复

rclone link s4:my-bucket/images/logo.png --expire 1h  # 临时下载链接,最长 7 天
rclone lsf s4:my-bucket/images               # 列出文件名
rclone lsl s4:my-bucket/images               # 列出大小和时间
rclone tree s4:my-bucket/images              # 树状显示
rclone size s4:my-bucket/documents           # 统计数量与容量
rclone cat s4:my-bucket/notes/todo.txt       # 查看内容

rclone moveto s4:my-bucket/a.txt s4:my-bucket/b.txt   # 改名
rclone delete s4:my-bucket/tmp --min-age 30d          # 删除 30 天前的文件
rclone purge s4:my-bucket/tmp                         # 删除整个目录,无法恢复

rclone link s4:my-bucket/images/logo.png --expire 1h  # 临时下载链接,最长 7 天

moveto 会先复制再删除。大文件请用 S4 的 原生移动。

同步

PowerShell
# 先预演,不做任何改动
rclone.exe sync D:\site s4:my-bucket/site --dry-run

# 让目标与源完全一致,会删除目标里多余的文件
rclone.exe sync D:\site s4:my-bucket/site -P
# 先预演,不做任何改动
rclone sync ./site s4:my-bucket/site --dry-run

# 让目标与源完全一致,会删除目标里多余的文件
rclone sync ./site s4:my-bucket/site -P
# 先预演,不做任何改动
rclone sync ./site s4:my-bucket/site --dry-run

# 让目标与源完全一致,会删除目标里多余的文件
rclone sync ./site s4:my-bucket/site -P

sync 会删除目标中源没有的文件,S4 没有回收站。不确定时用 copy,或先加 --dry-run。

给删除和覆盖的文件留一份备份:

PowerShell
rclone.exe sync D:\site s4:my-bucket/site --backup-dir s4:my-bucket/site-old/2026-11-25
rclone sync ./site s4:my-bucket/site --backup-dir s4:my-bucket/site-old/2026-11-25
rclone sync ./site s4:my-bucket/site --backup-dir s4:my-bucket/site-old/2026-11-25

排除部分文件:

PowerShell
rclone.exe sync D:\project s4:my-bucket/project --exclude "node_modules/**" --exclude "*.tmp"
rclone sync ./project s4:my-bucket/project --exclude "node_modules/**" --exclude "*.tmp"
rclone sync ./project s4:my-bucket/project --exclude "node_modules/**" --exclude "*.tmp"

定时备份

每天 3 点增量备份。上一次还没结束时,不要重复启动。

用 任务计划程序 新建任务:触发器选 每天 3:00,操作选 启动程序,程序填 rclone.exe 的完整路径(用 where.exe rclone 查看),参数填:

copy D:\data s4:my-bucket/backup --log-file=D:\rclone-backup.log --log-level INFO

在任务的 设置 里,如果此任务已经运行 选 请勿启动新实例。

crontab -e
0 3 * * * /opt/homebrew/bin/rclone copy /Users/用户名/data s4:my-bucket/backup --log-file=/Users/用户名/rclone-backup.log --log-level INFO

Rclone 的路径用 which rclone 查看。备份文稿、桌面等目录,需要在系统设置里给 cron 完全磁盘访问权限。

crontab -e
0 3 * * * /usr/bin/rclone copy /data s4:my-bucket/backup --log-file=/var/log/rclone-backup.log --log-level INFO

可以用 flock 包一层,避免重复启动。

校验

PowerShell
# 比对大小和校验值
rclone.exe check D:\documents s4:my-bucket/documents

# 下载内容逐字节比对,会产生下载流量
rclone.exe check D:\documents s4:my-bucket/documents --download
# 比对大小和校验值
rclone check ./documents s4:my-bucket/documents

# 下载内容逐字节比对,会产生下载流量
rclone check ./documents s4:my-bucket/documents --download
# 比对大小和校验值
rclone check ./documents s4:my-bucket/documents

# 下载内容逐字节比对,会产生下载流量
rclone check ./documents s4:my-bucket/documents --download

大量文件与大文件

PowerShell
# 大量小文件:提高并发
rclone.exe copy D:\data s4:my-bucket/data -P --transfers 32 --checkers 32 --fast-list

# 大文件:加大分片和单文件并发
rclone.exe copy D:\video.mp4 s4:my-bucket/videos/ -P --s3-chunk-size 64M --s3-upload-concurrency 8
# 大量小文件:提高并发
rclone copy ./data s4:my-bucket/data -P --transfers 32 --checkers 32 --fast-list

# 大文件:加大分片和单文件并发
rclone copy ./video.mp4 s4:my-bucket/videos/ -P --s3-chunk-size 64M --s3-upload-concurrency 8
# 大量小文件:提高并发
rclone copy ./data s4:my-bucket/data -P --transfers 32 --checkers 32 --fast-list

# 大文件:加大分片和单文件并发
rclone copy ./video.mp4 s4:my-bucket/videos/ -P --s3-chunk-size 64M --s3-upload-concurrency 8

内存占用约为 --transfers × --s3-upload-concurrency × --s3-chunk-size。并发过高会触发 QPS 限制,出现 429 时降低 --transfers,或加 --tpslimit 100。

中断的分片上传会占用空间,清理 24 小时以前的:

PowerShell
rclone.exe backend list-multipart-uploads s4:my-bucket
rclone.exe cleanup s4:my-bucket
rclone backend list-multipart-uploads s4:my-bucket
rclone cleanup s4:my-bucket
rclone backend list-multipart-uploads s4:my-bucket
rclone cleanup s4:my-bucket

从其他云迁移

在配置文件里再加一个源,例如阿里云 OSS:

[oss]
type = s3
provider = Alibaba
access_key_id = 源的 AccessKey
secret_access_key = 源的 SecretKey
endpoint = oss-cn-hangzhou.aliyuncs.com

然后直接在两个云之间复制,完成后校验:

PowerShell
rclone.exe copy oss:old-bucket s4:my-bucket -P --transfers 16
rclone.exe check oss:old-bucket s4:my-bucket --size-only
rclone copy oss:old-bucket s4:my-bucket -P --transfers 16
rclone check oss:old-bucket s4:my-bucket --size-only
rclone copy oss:old-bucket s4:my-bucket -P --transfers 16
rclone check oss:old-bucket s4:my-bucket --size-only

数据会经过运行 Rclone 的机器,源站可能收取外网流量费。文件多时建议在云服务器上运行。想不停业务迁移,可以配合 镜像回源。

客户端加密

上传前在本地加密文件名和内容,S4 上只保存密文:

PowerShell
rclone.exe config create s4crypt crypt remote=s4:my-bucket/encrypted password=$(rclone.exe obscure "你的加密密码")
rclone.exe copy D:\private s4crypt:
rclone.exe lsf s4crypt:
rclone config create s4crypt crypt remote=s4:my-bucket/encrypted password=$(rclone obscure "你的加密密码")
rclone copy ./private s4crypt:
rclone lsf s4crypt:
rclone config create s4crypt crypt remote=s4:my-bucket/encrypted password=$(rclone obscure "你的加密密码")
rclone copy ./private s4crypt:
rclone lsf s4crypt:

直接看 s4:my-bucket/encrypted,文件名和内容都是乱码。

密码丢失后数据无法恢复。加密后的文件不能在控制台预览,也不能使用图片处理和 CDN 直接访问。

挂载为本地目录

Linux 需要安装 fuse3,macOS 需要 macFUSE,Windows 需要 WinFsp。

rclone.exe mount s4:my-bucket S: --vfs-cache-mode full --vfs-cache-max-size 10G --vfs-cache-max-age 24h --vfs-read-chunk-size 16M --vfs-read-chunk-size-limit 256M --dir-cache-time 1m

程序在前台运行,不要关闭窗口。卸载时在窗口按 Ctrl+C。

mkdir -p ~/s4
rclone mount s4:my-bucket ~/s4 \
  --daemon \
  --vfs-cache-mode full \
  --vfs-cache-max-size 10G \
  --vfs-cache-max-age 24h \
  --vfs-read-chunk-size 16M \
  --vfs-read-chunk-size-limit 256M \
  --dir-cache-time 1m \
  --log-file ~/rclone.log

卸载:

umount ~/s4
mkdir -p ~/s4
rclone mount s4:my-bucket ~/s4 \
  --daemon \
  --vfs-cache-mode full \
  --vfs-cache-max-size 10G \
  --vfs-cache-max-age 24h \
  --vfs-read-chunk-size 16M \
  --vfs-read-chunk-size-limit 256M \
  --dir-cache-time 1m \
  --log-file ~/rclone.log

卸载:

fusermount3 -u ~/s4

挂载适合浏览和顺序读写,不适合数据库等需要随机写、文件锁的程序。写入先进入本地缓存,再后台上传,关机前请确认上传完成。缤纷云官方的挂载工具见 Bitifs。

提供 WebDAV 服务

让只支持 WebDAV 的软件(笔记、影音、NAS 同步等)使用 S4:

PowerShell
rclone.exe serve webdav s4:my-bucket --addr 127.0.0.1:8080 --user demo --pass 你的密码 --vfs-cache-mode writes
rclone serve webdav s4:my-bucket --addr 127.0.0.1:8080 --user demo --pass 你的密码 --vfs-cache-mode writes
rclone serve webdav s4:my-bucket --addr 127.0.0.1:8080 --user demo --pass 你的密码 --vfs-cache-mode writes

对外提供服务时,请放在 HTTPS 反向代理后面。

常见问题

403 AccessDenied

检查子账户授权。只授权了目录时,路径要写到授权目录,例如 s4:my-bucket/images,不要操作桶根目录。

上传时报没有权限创建桶

配置里缺少 no_check_bucket = true。

修改时间变了,内容没变,为什么还有请求

Rclone 会更新对象里保存的修改时间,不会重新上传内容。不需要保留修改时间时,加 --checksum 按大小和校验值比较,或用 --size-only 只比较大小,也可以加 --no-update-modtime。

rclone about 报不支持

对象存储没有总容量的概念。查看已用容量用 rclone size,或在控制台的 用量统计 查看。

下载速度不高

单个连接有默认限速,见 约束限制。用 --multi-thread-streams 多线程下载,或用 CDN 分发。

相关阅读

  1. 官方 Rclone 文档
  2. Ugediao: Debian 服务器通过 rclone 挂载缤纷云