Rclone 是一个强大的命令行程序,用于管理和同步文件到各种云存储服务。本文将详细介绍如何安装和配置Rclone,以便将文件同步到Cloudflare R2存储服务。
sudo apt install rclone
rclone version
在配置Rclone之前,需要先在Cloudflare R2管理界面创建API令牌,并获取必要的访问密钥和端点信息。
创建API令牌:
保存API令牌信息:
access_key_id
和secret_access_key
,这些信息在创建完成后只会显示一次。获取存储桶的端点:
endpoint = https://3f33d3f3g3cx33fds3f31f.r2.cloudflarestorage.com/
编辑Rclone配置文件:
编辑.config/rclone/rclone.conf
配置文件
在Windows上路径为C:\Users\<YourUsername>\.config\rclone\rclone.conf
添加配置项:
在配置文件中添加以下内容,并将相应的access_key_id
、secret_access_key
和endpoint
替换为你的实际值:
[r2]
type = s3
provider = Cloudflare
access_key_id = <your_access_key_id>
secret_access_key = <your_secret_access_key>
endpoint = <your_endpoint>
示例:
[r2]
type = s3
provider = Cloudflare
access_key_id = a61111d64a7cec3594rrrr46931995a39
secret_access_key = 967180217f1ea1e777274b079c5821136a29112f2786f8b32547356b00de563
endpoint = https://3f33d3f3g3cx33fds3f31f.r2.cloudflarestorage.com/
配置完成后,可以使用Rclone命令将文件同步到指定的Cloudflare R2存储桶。以下是一些常用命令:
同步本地文件到R2存储桶: (bucket_name是存储桶名字)
rclone sync /path/to/local/folder r2:<bucket_name>/path/in/r2
示例:
rclone sync /home/user/documents r2:mybucket/documents
从R2存储桶同步文件到本地:
rclone sync r2:<bucket_name>/path/in/r2 /path/to/local/folder
示例:
rclone sync r2:mybucket/documents /home/user/documents
列出R2存储桶中的文件:
rclone ls r2:<bucket_name>/path/in/r2
示例:
rclone ls r2:mybucket/documents
创建存储桶:
mybucket
的存储桶。获取并保存API令牌和endpoint:
access_key_id
:a61111d64a7cec359467c66931995a39secret_access_key
:967180217f1ea1e21c5f49b079c5821136a29112f2786f8b32547356b00de563endpoint
:https://3f33d3f3g3cx33fds3f31f.r2.cloudflarestorage.com/配置Rclone:
编辑.config/rclone/rclone.conf
文件,添加以下内容:
[r2]
type = s3
provider = Cloudflare
access_key_id = a61111d64a7cec359467c66931995a39
secret_access_key = 967180217f1ea1e21c5f49b079c5821136a29112f2786f8b32547356b00de563
endpoint = https://3f33d3f3g3cx33fds3f31f.r2.cloudflarestorage.com/
同步文件:
将本地文件同步到mybucket
存储桶:
rclone sync /home/user/documents r2:mybucket/documents
从mybucket
存储桶同步文件到本地:
rclone sync r2:mybucket/documents /home/user/documents
列出mybucket
存储桶中的文件:
rclone ls r2:mybucket/documents