[rclone] 告别本地单点故障:思源笔记远程备份终极方案

缘起

由于思源没有远程备份,只有远程同步,因此同步数据的安全就显得尤为重要了。所以,之前写了一篇 [js] 简单实现 webdav 实时备份重要文件(密钥安全再无忧) 通过 webdav 实现了对密钥等重要文件的备份。

但,光有同步还是远远不够的,鸡蛋不能放到一个篮子里。根据 321 备份原则,至少有两个介质,一份异地,因此远程备份就是不二的选择。

但,遗憾的是,思源并没有自带远程备份功能,因此,这里选择 rclone 这个老牌的远程备份工具来实现。

rclone 简介

Rclone 是一款极为强大的命令行工具,主要用于不同云存储服务之间的文件同步、备份和迁移。它支持众多云存储提供商,如 S3、WebDAV、FTP、Google Drive、OneDrive、Dropbox 等近 70 种存储厂商。

优点:成熟稳定,支持增量备份,支持 Windows,Linux,Mac 等系统。

缺点:仅支持 pc,docker,不支持手机和浏览器。

如何使用

1 首先去官网安装命令 https://rclone.org/downloads/

2 配置远程存储信息,这里以 s3 为例说明(根据 👈 处的说明操作即可)

配置完成后,配置文件默认会存放到用户配置目录 rclone/rclone.conf 中。

wish@Wilsons-Mac rclone $ rclone config
Current remotes:

Name                 Type
====                 ====
infinicloud          webdav

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> n    👈 这里选择创建新存储

Enter name for new remote.
name> qiniu    👈 创建新存储名

Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.
 1 / 1Fichier
   \ (fichier)
 2 / Akamai NetStorage
   \ (netstorage)
 3 / Alias for an existing remote
   \ (alias)
 4 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, ArvanCloud, Ceph, ChinaMobile, Cloudflare, DigitalOcean, Dreamhost, Exaba, FlashBlade, GCS, HuaweiOBS, IBMCOS, IDrive, IONOS, LyveCloud, Leviia, Liara, Linode, Magalu, Mega, Minio, Netease, Outscale, OVHcloud, Petabox, RackCorp, Rclone, Scaleway, SeaweedFS, Selectel, StackPath, Storj, Synology, TencentCOS, Wasabi, Qiniu, Zata and others
   \ (s3)
 5 / Backblaze B2
   \ (b2)
 6 / Better checksums for other remotes
   \ (hasher)
 7 / Box
   \ (box)
 8 / Cache a remote
   \ (cache)
 9 / Citrix Sharefile
   \ (sharefile)
10 / Cloudinary
   \ (cloudinary)
11 / Combine several remotes into one
   \ (combine)
12 / Compress a remote
   \ (compress)
13 / DOI datasets
   \ (doi)
14 / Dropbox
   \ (dropbox)
15 / Encrypt/Decrypt a remote
   \ (crypt)
16 / Enterprise File Fabric
   \ (filefabric)
17 / FTP
   \ (ftp)
18 / FileLu Cloud Storage
   \ (filelu)
19 / Files.com
   \ (filescom)
20 / Gofile
   \ (gofile)
21 / Google Cloud Storage (this is not Google Drive)
   \ (google cloud storage)
22 / Google Drive
   \ (drive)
23 / Google Photos
   \ (google photos)
24 / HTTP
   \ (http)
25 / Hadoop distributed file system
   \ (hdfs)
26 / HiDrive
   \ (hidrive)
27 / ImageKit.io
   \ (imagekit)
28 / In memory object storage system.
   \ (memory)
29 / Internet Archive
   \ (internetarchive)
30 / Jottacloud
   \ (jottacloud)
31 / Koofr, Digi Storage and other Koofr-compatible storage providers
   \ (koofr)
32 / Linkbox
   \ (linkbox)
33 / Local Disk
   \ (local)
34 / Mail.ru Cloud
   \ (mailru)
35 / Mega
   \ (mega)
36 / Microsoft Azure Blob Storage
   \ (azureblob)
37 / Microsoft Azure Files
   \ (azurefiles)
38 / Microsoft OneDrive
   \ (onedrive)
39 / OpenDrive
   \ (opendrive)
40 / OpenStack Swift (Rackspace Cloud Files, Blomp Cloud Storage, Memset Memstore, OVH)
   \ (swift)
41 / Oracle Cloud Infrastructure Object Storage
   \ (oracleobjectstorage)
42 / Pcloud
   \ (pcloud)
43 / PikPak
   \ (pikpak)
44 / Pixeldrain Filesystem
   \ (pixeldrain)
45 / Proton Drive
   \ (protondrive)
46 / Put.io
   \ (putio)
47 / QingCloud Object Storage
   \ (qingstor)
48 / Quatrix by Maytech
   \ (quatrix)
49 / SMB / CIFS
   \ (smb)
50 / SSH/SFTP
   \ (sftp)
51 / Sia Decentralized Cloud
   \ (sia)
52 / Storj Decentralized Cloud Storage
   \ (storj)
53 / Sugarsync
   \ (sugarsync)
54 / Transparently chunk/split large files
   \ (chunker)
55 / Uloz.to
   \ (ulozto)
56 / Union merges the contents of several upstream fs
   \ (union)
57 / Uptobox
   \ (uptobox)
58 / WebDAV
   \ (webdav)
59 / Yandex Disk
   \ (yandex)
60 / Zoho
   \ (zoho)
61 / iCloud Drive
   \ (iclouddrive)
62 / premiumize.me
   \ (premiumizeme)
63 / seafile
   \ (seafile)
Storage> s3    👈 选择s3

Option provider.
Choose your S3 provider.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
 1 / Amazon Web Services (AWS) S3
   \ (AWS)
 2 / Alibaba Cloud Object Storage System (OSS) formerly Aliyun
   \ (Alibaba)
 3 / Arvan Cloud Object Storage (AOS)
   \ (ArvanCloud)
 4 / Ceph Object Storage
   \ (Ceph)
 5 / China Mobile Ecloud Elastic Object Storage (EOS)
   \ (ChinaMobile)
 6 / Cloudflare R2 Storage
   \ (Cloudflare)
 7 / DigitalOcean Spaces
   \ (DigitalOcean)
 8 / Dreamhost DreamObjects
   \ (Dreamhost)
 9 / Exaba Object Storage
   \ (Exaba)
10 / Pure Storage FlashBlade Object Storage
   \ (FlashBlade)
11 / Google Cloud Storage
   \ (GCS)
12 / Huawei Object Storage Service
   \ (HuaweiOBS)
13 / IBM COS S3
   \ (IBMCOS)
14 / IDrive e2
   \ (IDrive)
15 / IONOS Cloud
   \ (IONOS)
16 / Seagate Lyve Cloud
   \ (LyveCloud)
17 / Leviia Object Storage
   \ (Leviia)
18 / Liara Object Storage
   \ (Liara)
19 / Linode Object Storage
   \ (Linode)
20 / Magalu Object Storage
   \ (Magalu)
21 / MEGA S4 Object Storage
   \ (Mega)
22 / Minio Object Storage
   \ (Minio)
23 / Netease Object Storage (NOS)
   \ (Netease)
24 / OUTSCALE Object Storage (OOS)
   \ (Outscale)
25 / OVHcloud Object Storage
   \ (OVHcloud)
26 / Petabox Object Storage
   \ (Petabox)
27 / RackCorp Object Storage
   \ (RackCorp)
28 / Rclone S3 Server
   \ (Rclone)
29 / Scaleway Object Storage
   \ (Scaleway)
30 / SeaweedFS S3
   \ (SeaweedFS)
31 / Selectel Object Storage
   \ (Selectel)
32 / StackPath Object Storage
   \ (StackPath)
33 / Storj (S3 Compatible Gateway)
   \ (Storj)
34 / Synology C2 Object Storage
   \ (Synology)
35 / Tencent Cloud Object Storage (COS)
   \ (TencentCOS)
36 / Wasabi Object Storage
   \ (Wasabi)
37 / Qiniu Object Storage (Kodo)
   \ (Qiniu)
38 / Zata (S3 compatible Gateway)
   \ (Zata)
39 / Any other S3 compatible provider
   \ (Other)
provider> 37    👈 选择七牛云

Option env_auth.
Get AWS credentials from runtime (environment variables or EC2/ECS meta data if no env vars).
Only applies if access_key_id and secret_access_key is blank.
Choose a number from below, or type in your own boolean value (true or false).
Press Enter for the default (false).
 1 / Enter AWS credentials in the next step.
   \ (false)
 2 / Get AWS credentials from the environment (env vars or IAM).
   \ (true)
env_auth> true    👈 选择创建新秘钥配置

Option access_key_id.
AWS Access Key ID.
Leave blank for anonymous access or runtime credentials.
Enter a value. Press Enter to leave empty.
access_key_id> jK9mXQnLwvR+bY7gkpVsuEfzUDmPLgbVRNFPAdhy    👈 输入秘钥id,这里是我让AI随机生成的,你不要尝试,没用的

Option secret_access_key.
AWS Secret Access Key (password).
Leave blank for anonymous access or runtime credentials.
Enter a value. Press Enter to leave empty.
secret_access_key> GWeY0bYKVQ11UeZaVOH3_XINy-ovqHRkKbKqvGXg    👈 输入key,这里是我让AI随机生成的,你不要尝试,没用的

Option region.
Region to connect to.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
   / The default endpoint - a good choice if you are unsure.
 1 | East China Region 1.
   | Needs location constraint cn-east-1.
   \ (cn-east-1)
   / East China Region 2.
 2 | Needs location constraint cn-east-2.
   \ (cn-east-2)
   / North China Region 1.
 3 | Needs location constraint cn-north-1.
   \ (cn-north-1)
   / South China Region 1.
 4 | Needs location constraint cn-south-1.
   \ (cn-south-1)
   / North America Region.
 5 | Needs location constraint us-north-1.
   \ (us-north-1)
   / Southeast Asia Region 1.
 6 | Needs location constraint ap-southeast-1.
   \ (ap-southeast-1)
   / Northeast Asia Region 1.
 7 | Needs location constraint ap-northeast-1.
   \ (ap-northeast-1)
region> 1    👈 选择区域,根据自己情况选择,因为我的桶是华东浙江,所以我选1

Option endpoint.
Endpoint for Qiniu Object Storage.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
 1 / East China Endpoint 1
   \ (s3-cn-east-1.qiniucs.com)
 2 / East China Endpoint 2
   \ (s3-cn-east-2.qiniucs.com)
 3 / North China Endpoint 1
   \ (s3-cn-north-1.qiniucs.com)
 4 / South China Endpoint 1
   \ (s3-cn-south-1.qiniucs.com)
 5 / North America Endpoint 1
   \ (s3-us-north-1.qiniucs.com)
 6 / Southeast Asia Endpoint 1
   \ (s3-ap-southeast-1.qiniucs.com)
 7 / Northeast Asia Endpoint 1
   \ (s3-ap-northeast-1.qiniucs.com)
endpoint> 1    👈 选择区域,根据自己情况选择,因为我的桶是华东浙江,所以我选1,注意这里选项是s3-xxxxx,而七牛云可能是s3.xxx其实这两个域名是一样的,都能正确定位

Option location_constraint.
Location constraint - must be set to match the Region.
Used when creating buckets only.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
 1 / East China Region 1
   \ (cn-east-1)
 2 / East China Region 2
   \ (cn-east-2)
 3 / North China Region 1
   \ (cn-north-1)
 4 / South China Region 1
   \ (cn-south-1)
 5 / North America Region 1
   \ (us-north-1)
 6 / Southeast Asia Region 1
   \ (ap-southeast-1)
 7 / Northeast Asia Region 1
   \ (ap-northeast-1)
location_constraint> 1    👈 选择区域,根据自己情况选择,因为我的桶是华东浙江,所以我选1

Option acl.
Canned ACL used when creating buckets and storing or copying objects.
This ACL is used for creating objects and if bucket_acl isn't set, for creating buckets too.
For more info visit https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl
Note that this ACL is applied when server-side copying objects as S3
doesn't copy the ACL from the source but rather writes a fresh one.
If the acl is an empty string then no X-Amz-Acl: header is added and
the default (private) will be used.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
   / Owner gets FULL_CONTROL.
 1 | No one else has access rights (default).
   \ (private)
   / Owner gets FULL_CONTROL.
 2 | The AllUsers group gets READ access.
   \ (public-read)
   / Owner gets FULL_CONTROL.
 3 | The AllUsers group gets READ and WRITE access.
   | Granting this on a bucket is generally not recommended.
   \ (public-read-write)
   / Owner gets FULL_CONTROL.
 4 | The AuthenticatedUsers group gets READ access.
   \ (authenticated-read)
   / Object owner gets FULL_CONTROL.
 5 | Bucket owner gets READ access.
   | If you specify this canned ACL when creating a bucket, Amazon S3 ignores it.
   \ (bucket-owner-read)
   / Both the object owner and the bucket owner get FULL_CONTROL over the object.
 6 | If you specify this canned ACL when creating a bucket, Amazon S3 ignores it.
   \ (bucket-owner-full-control)
acl> 1    👈 选择桶权限,根据自己情况选择,因为我是私有桶,我选1

Option storage_class.
The storage class to use when storing new objects in Qiniu.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
 1 / Standard storage class
   \ (STANDARD)
 2 / Infrequent access storage mode
   \ (LINE)
 3 / Archive storage mode
   \ (GLACIER)
 4 / Deep archive storage mode
   \ (DEEP_ARCHIVE)
storage_class> 1    👈 选择桶存储类型,一般选1即可,标准存储,其他是低频访问等

Edit advanced config?
y) Yes
n) No (default)
y/n> n    👈 选择1即可

Configuration complete.
Options:
- type: s3
- provider: Qiniu
- env_auth: true
- access_key_id: jK9mXQnLwvR+bY7gkpVsuEfzUDmPLgbVRNFPAdhy
- secret_access_key: GWeY0bYKVQ11UeZaVOH3_XINy-ovqHRkKbKqvGXg
- region: cn-east-1
- endpoint: s3-cn-east-1.qiniucs.com
- location_constraint: cn-east-1
- acl: private
- storage_class: STANDARD
Keep this "qiniu" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y    👈 确认后选择y即可,同理,上面的密钥也是ai随机生成的,不要尝试,不可能有效,浪费时间

Current remotes:

Name                 Type
====                 ====
infinicloud          webdav
qiniu                s3

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q    👈 配置完成了,选择q退出即可

3 定时执行任务,这里以 mac shell 命令为例说明,Windows 或 linux 可以让 ai 帮忙转换

#!/usr/bin/env bash

# 0 * * * * /bin/bash /Users/wish/bin/siyuan_backup.sh >/dev/null 2>&1 &
# nohup bash /Users/wish/bin/siyuan_backup.sh >/dev/null 2>&1 &

# 定义发送通知函数(macOS 原生通知)
function send_notification {
    local msg="$1"
    osascript -e "display notification \"$msg\" with title \"思源笔记备份提醒\""
}

# --- 开始备份 ---
echo "🚀 开始备份思源笔记数据..."

/usr/local/bin/rclone \
  --config /Users/wish/.config/rclone/rclone.conf \
  copy "/Users/wish/_data/思源笔记/data" "qiniu:siyuan-note-backups" \
  --create-empty-src-dirs \
  --exclude='.DS_Store' \
  --exclude='.git/' \
  --exclude='*/log/*' \
  --exclude='*/.history/*' \
  --exclude='trash/' \
  --exclude='plugins/' \
  --exclude='widgets/' \
  --progress \
  --stats 5s \
  --transfers 16 \
  --checkers 32 \
  --s3-upload-concurrency 10 \
  --s3-chunk-size 64M \
  --multi-thread-streams 4 \
  --multi-thread-cutoff 64M

COPY_EXIT_CODE=$?

if [ $COPY_EXIT_CODE -ne 0 ]; then
    send_notification "❌ 备份命令执行失败!退出码: $COPY_EXIT_CODE"
    exit 1
fi

# --- 检查备份是否成功 ---
echo "🔍 正在检查备份一致性..."

/usr/local/bin/rclone \
  --config /Users/wish/.config/rclone/rclone.conf \
  check "/Users/wish/_data/思源笔记/data" "qiniu:siyuan-note-backups" \
  --exclude='.DS_Store' \
  --exclude='.git/' \
  --exclude='*/log/*' \
  --exclude='*/.history/*' \
  --exclude='trash/' \
  --exclude='plugins/' \
  --exclude='widgets/' \
  --checksum \
  --one-way

CHECK_EXIT_CODE=$?

if [ $CHECK_EXIT_CODE -eq 0 ]; then
    echo "✅ 备份成功且内容一致。"
    #send_notification "✅ 备份成功!所有文件均已完整同步。"
elif [ $CHECK_EXIT_CODE -eq 1 ]; then
    echo "⚠️ 发现未备份或不一致的文件!"
    send_notification "⚠️ 发现未备份或不一致的文件!请检查日志。"
else
    echo "❌ 检查过程出错!退出码: $CHECK_EXIT_CODE"
    send_notification "❌ 检查过程出错!退出码: $CHECK_EXIT_CODE"
fi

注意:这里/Users/wish/是我的 home 目录,一般默认 rclone 的配置文件是在这里(根据自己的实际情况修改),定时任务里最好指定配置文件全路径,以防找不到配置文件而失效。

qiniu:siyuan-note-backups 这里 qiniu 就是上文配置时的云存储名,siyuan-note-backups 是在七牛云的桶名,如果想备份到指定目录可以加上子目录即可,比如 qiniu:siyuan-note-backups/mybackups

--exclude= 是排除目录或文件,这里重点排除了 plugins 和 widgets,插件目录最大,备份这个意义不大。

注意:

第一次执行可能会耗时较长,根据文件大小和数量决定,以后就是增量备份了,速度很快。

rclone copy 和 rclone sync 的区别是:

rclone copy 只新增和修改,不删除。

rclone sync 严格与本地保持同步,会删除本地没有的文件。

可以实时备份吗?

不支持,不过,可以配合 fswatch 实现实时备份。

支持备份到本地目录吗?

支持,比如 rclone copy /path/to/source /path/to/destination

本地备份也可以用 rsync 比如 rsync -avz "$src_dir" "$backup_idr" --exclude='.DS_Store' --exclude='.git' --exclude='media/.git'

为什么不用 Git?

git 实现备份也可以,但由于 git 会记录历史,会增加本地磁盘占用,因此我选择了 rclone。

如果 rclone 想保存历史,也可以用 rclone copy "/path/data" "/path/data_backup_$(date +%Y-%m-%d)"

可以对备份文件加密上传吗?

可以,但比较麻烦,建议直接备份思源的 repo 目录,但前提是记得自己的秘钥,建议配合 [js] 简单实现 webdav 实时备份重要文件(密钥安全再无忧) 使用。

如果想自行加密,可参考下面 AI 的回答,自行尝试。

因为我不需要加密所以没有研究,我一般会把重要文本加密存储,重要证件等图片放到网盘保险箱,所以笔记中的未加密信息一般不是特别重要,尚无使用场景。

Qwen3 的回答

是的,rclone 可以对备份文件进行加密,这是它最强大的功能之一。您可以将 InfiniCLOUD 或七牛云这类云存储服务视为一个“不信任的环境”,而 rclone 的加密功能则确保您的数据在上传前就已变成无法识别的密文。

这完美契合了您对数据安全的需求,也与 InfiniCLOUD 所强调的 High Performance & Security 理念相辅相成。


✅ 一、rclone 如何实现加密?

rclone 使用其内置的 crypt 类型来创建一个“加密虚拟层”。

工作流程如下:

  1. 您有一个原始的远程存储(如 qiniu:my-bucket)。
  2. 您创建一个新的 crypt 远程,指向这个原始远程。
  3. 当您向 crypt 远程写入文件时:
    • rclone 在本地使用 AES-256 加密 将文件内容加密。
    • 文件名也会被加密(可选)。
    • 然后将加密后的乱码文件上传到原始远程(如七牛云)。
  4. 当您从 crypt 远程读取文件时:
    • rclone 下载加密文件。
    • 在本地用密码解密。
    • 呈现给您原始的文件名和内容。

整个过程对用户透明,就像操作一个普通的加密磁盘。


🔧 二、如何配置加密?(步骤详解)

第一步:创建原始远程

假设您已经配置好一个名为 qiniu 的远程,指向您的七牛云存储空间。

第二步:创建加密远程

运行:

rclone config
  1. 输入 n 创建新 remote。
  2. 命名,例如 qiniu_encrypted
  3. 存储类型选择:crypt
  4. 提示 Remote to encrypt 时,输入:qiniu:siyuan-note-backups (即您的目标路径)
  5. 设置密码(Password):输入一个强密码,用于加密文件内容。
  6. 设置密码确认(Password confirm):再次输入。
  7. 设置文件名加密密码(Encryption password for file names):建议输入一个不同的密码,或按回车让 rclone 自动生成。
  8. 保存退出。

现在您就有了一个加密的 remote qiniu_encrypted


📦 三、如何使用加密备份?

只需将之前的命令中的目标从 qiniu 改为 qiniu_encrypted

rclone copy "/Users/wish/_data/思源笔记/data" "qiniu_encrypted:sy_backup_$(date +%Y-%m-%d)" \
  --progress \
  --transfers=10 \
  --checkers=20

执行后,您可以在七牛云控制台看到,所有文件都变成了类似 gjhsadgjhsgd.trunc 的乱码,完全无法识别。


🔐 四、如何解密和恢复文件?

解密过程同样简单,且必须在安装了 rclone 并知道密码的设备上进行

方法一:通过 rclone 命令下载并自动解密

# 将加密备份中的文件复制回本地,并自动解密
rclone copy "qiniu_encrypted:sy_backup_2025-04-05" "/Users/wish/RestoredData" \
  --progress

方法二:挂载为加密磁盘(像访问 U 盘一样)

# 挂载加密的远程
rclone mount qiniu_encrypted: ~/mnt/decrypted_siyuan --daemon

# 此时访问 ~/mnt/decrypted_siyuan 目录,看到的就是原始的明文文件
ls ~/mnt/decrypted_siyuan

方法三:在另一台设备上恢复

只要在这台新设备上:

  1. 安装 rclone
  2. 使用相同的配置(rclone config 重新创建 crypt 远程,输入相同的密码)。
  3. 即可通过 rclone copymount 访问您的所有数据。

🌟 结合 InfiniCLOUD 的优势

场景 rclone crypt 的价值
DISASTER PREPAREDNESS 即使您的七牛云/Bucket 被泄露,没有密码也无法读取任何数据。
Huge Capacity (Up to 10TB) 加密不影响容量,您可以放心存储备份。
Fast Speed (Up to 200Mbps) AES-256 加密在现代 CPU 上性能损耗极低,几乎不影响传输速度。

⚠️ 重要提醒

  1. 密码就是一切:一旦丢失密码,没有任何方法可以恢复数据,包括 rclone 开发者。
  2. 备份配置文件:将 ~/.config/rclone/rclone.conf 备份到安全的地方,因为它包含了加密配置。
  3. 不要忘记密码提示:在配置时,可以设置一个密码提示(但不能太明显)。

✅ 总结

rclone 不仅可以加密备份,而且是目前最成熟、最灵活的解决方案。

通过 crypt 功能,您能构建一个真正意义上的“私人保险库”:

  • 数据在离开您电脑的那一刻起就是加密的。
  • 云端服务商(即使是 InfiniCLOUD 或七牛云)也只能看到一堆无意义的二进制块。
  • 只有您持有钥匙(密码),才能打开这个保险库。

这正是数字时代下,对抗风险、守护记忆的终极方式。

chatGPT5 的回答

可以的 —— rclone 支持对上传的备份进行透明加密(crypt remote),加密后文件在云端存的是密文/混淆的文件名与内容,只有用正确的 rclone crypt 配置(包含口令)才能读回明文。下面把使用方法、示例命令、解密/恢复和注意事项都列清楚,方便你马上操作。


1) 加密的两种方式(概念)

  • 内容加密(强制):文件内容一定被加密(需要口令)。
  • 文件名加密(可选):文件名也可以被加密(变成长串),或者用 obfuscate(旧版)或 off(不加密文件名)保留可读名。
    两者都由 crypt remote 的配置决定。

2) 推荐流程(交互式配置,最安全)

  1. 运行交互式配置:
rclone config

按提示:

  • n 新建 remote,给个名字,例如 qiniu-crypt
  • 选择类型(type): crypt
  • remote 填写要包裹的后端,例如:qiniu:siyuan-note-backups (这是你已有的七牛 remote)
  • filename_encryptionstandard(推荐) / obfuscate / off
  • password 输入用于加密数据的强口令(务必记住)
  • password2 可空或填写用于文件名加密的第二个口令(有助于更强的安全性)
  • 保存退出

交互式会把配置写入 ~/.config/rclone/rclone.conf(不同平台路径不同,rclone config file 可查看)。


3) 非交互式快速创建(示例)

注意:把明文 password 写进命令会出现在 shell 历史中,不推荐在共享机器上这样做。

rclone config create qiniu-crypt crypt \
  remote=qiniu:siyuan-note-backups \
  filename_encryption=standard \
  password=$(rclone obscure '你的强密码') \
  password2=$(rclone obscure '你的第二个密码')

这里用 rclone obscure 把口令变成配置里“模糊化”字符串,避免把纯文本口令写进配置。


4) 上传(加密后)示例命令

把本地目录上传到加密 remote(rclone 会在上传时加密内容与(按配置)文件名):

rclone copy "/Users/wish/_data/思源笔记/data" qiniu-crypt: \
  --create-empty-src-dirs \
  --exclude '.DS_Store' \
  --exclude '.git/' \
  --exclude '*/log/*' \
  --exclude 'trash/' \
  -P \
  --transfers 16 --checkers 32

上传后在七牛控制台看到的是密文文件名(或被混淆的文件名),内容也不可读。


5) 解密 / 恢复(透明)

解密是透明的 —— 只要你在本地有正确的 qiniu-crypt 配置(即相同的密码),使用 rclone 向本地拷贝或列目录就会自动解密:

  • 列出(会显示明文名称):
rclone ls qiniu-crypt:
  • 下载并解密到本地:
rclone copy qiniu-crypt: "/path/to/restore" -P
  • 挂载(实时访问解密后的文件):
rclone mount qiniu-crypt: ~/mnt/siyuan --vfs-cache-mode writes
# Mac/Windows 使用前请确认 rclone mount 支持与 FUSE 设置

只要 rclone 能读取到正确的密码,所有操作都是透明的:远端存的是密文,本地通过 crypt remote 看到明文。


6) 如果口令丢失怎么办?

  • 非常重要:如果忘记或丢失 crypt 的密码(尤其是用于数据加密的 password),文件内容将无法恢复。同理,如果丢失用于文件名解密的 password2,文件名无法还原(内容可能仍可因主密码存在而可解密,或视具体设置而定)。
  • 所以:务必把密码备份到安全地方(密码管理器、离线纸质备份等)。

7) 配置示例(rclone.conf 片段)

(示例,别把真实密钥贴到公共地方)

[qiniu]
type = qiniu
access_key = <你的ak>
secret_key = <你的sk>
bucket = siyuan-note-backups
# ...其他 qiniu 配置

[qiniu-crypt]
type = crypt
remote = qiniu:siyuan-note-backups
filename_encryption = standard
password = <obscured-password-string>
password2 = <obscured-password2-string>

使用 rclone obscure 'mypassword' 得到 <obscured-password-string>,比直接写明文更安全。


8) 额外小贴士

  • 如果只是想保护内容但保留能读的文件名,可设置 filename_encryption = off(注意:文件名会泄露,但内容仍加密)。
  • 在自动化脚本中使用 rclone,避免把明文密码放在脚本里,优选 rclone obscure 或环境变量或交互式配置文件。
  • 对于大量小文件,依然建议把文件先打包(tar/zip)再加密上传(减少 API 请求、提高上传效率),但视你的恢复需求决定是否可接受打包恢复步骤。
  • 想要验证远端加密是否成功:上传后用 rclone lsremote qiniu:(原 qiniu remote)查看,应该看不到原始文件名(如果 filename_encryption != off)。

免责声明

本文所提供的代码仅是 demo 或仍处于实验阶段,仅供学习与参考之用。
请在充分测试、确认无误后再谨慎使用,仅建议作为参考或备用的作用,切勿直接用于生产环境
如因使用本文所述方法造成任何问题,本人不承担任何责任。

如你有任何疑问或优化建议,欢迎留言交流,共同进步!

  • 思源笔记

    思源笔记是一款隐私优先的个人知识管理系统,支持完全离线使用,同时也支持端到端加密同步。

    融合块、大纲和双向链接,重构你的思维。

    28447 引用 • 119791 回帖
  • Rclone
    2 引用 • 9 回帖
  • 数据备份
    5 引用 • 11 回帖
  • Shell

    Shell 脚本与 Windows/Dos 下的批处理相似,也就是用各类命令预先放入到一个文件中,方便一次性执行的一个程序文件,主要是方便管理员进行设置或者管理用的。但是它比 Windows 下的批处理更强大,比用其他编程程序编辑的程序效率更高,因为它使用了 Linux/Unix 下的命令。

    126 引用 • 83 回帖 • 2 关注
3 操作
wilsons 在 2025-10-05 13:43:05 更新了该帖
wilsons 在 2025-09-23 12:29:43 更新了该帖
wilsons 在 2025-09-11 16:27:25 更新了该帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...
  • muxue 1

    建议直接拿 rclone 备份思源的 s3 存储桶,比如从七牛云备份到阿里云去(前提是你很明确且清晰地记住了你的加密密钥,且能确保这个密钥一定是对的)

    1 回复
  • 其他回帖
  • siyuan100861186 1

    我个人感觉最好不要自动生成同步密钥,使用自定义的有意义字符串进行散列生成密钥最好,只要记得初始化密钥的字符串就能知道密钥,有意义的字符串更好记忆。

    1 回复
  • vincents

    不错呀,思源正缺少这样好用的备份工具,感谢分享!

  • wilsons

    子夜
    光标在深海游弋
    rclone 的羽翼划破星空
    将思源的星群 跃迁至
    量子海的彼岸

    字节在虚空起舞
    像远古的符咒
    每一次传输都是
    与熵增的永恒较量

    备份 像一个镜中世界
    为每个比特注入魂魄
    让数据在寂灭前
    学会自我繁衍

    当浩劫来临
    镜像之城自云端升起
    所有逝去的记忆
    在光脉中重获心跳

    此刻 我是守护
    也是被守护
    在 0 和 1 的海洋里
    互为彼此

  • 查看全部回帖
wilsons
正式入驻知乎了,以后新贴主要在这里。 欢迎大家订阅关注! 你的关注对我是莫大鼓励,也能让我持续产出优质内容,我们一起成长 🙏 点这里立即关注:https://www.zhihu.com/people/wilsonses