使用 rclone 同步到 Dropbox (2025)

管理员和版主:请随意将此主题移至其他位置或根据需要进行编辑。

这是我安装 rclone 并设置好将 Discourse 备份到 Dropbox 的详细分步说明。对于 Google Drive 用户,我认为其中大部分步骤也适用。

我遵循了 Christoph (@tophee) 在此处的原始说明:

由于我完全不是专家,这些说明对我来说似乎非常有限,最终我会失败,所以我得到了 ChatGPT 的帮助,现在一切都正常工作了!我一步一步地记录了所有内容,供那些可能不像我一样是高级用户,并且在过程中需要额外帮助的人使用。

:one: 远程安装 rclone 并准备 Dropbox

SSH 到您的服务器:

ssh root@xxx.xxx.xxx.xxx

在您的服务器上:

root@ServerNameHere:~#

安装 rclone

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

如果成功,运行:

sudo rclone config

当它显示:

2025/08/13 11:29:31 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
No remotes found, make a new one?
n) New remote
s) Set configuration password
q) Quit config
n/s/q> 

…输入 n。按 Enter

当出现:

Enter name for new remote.
name> 

给它起一个名字,例如 dropbox_backup。按 Enter

它会显示一个红色和绿色的列表(对我来说是这样),其中一个选项是 Dropbox。每个选项都有一个关联的数字。我的选项是:

14 / Dropbox
   \ (dropbox)

在底部,显示“Storage>”的地方,添加 Dropbox 的数字。所以,在我的例子中,我输入了 Storage>14。按 Enter

它会显示:

Option client_id.
OAuth Client Id.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_id> 

只需按 Enter 留空。当显示以下内容时,也执行相同操作:

Option client_secret.
OAuth Client Secret.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_secret> 

当显示:

Edit advanced config?
y) Yes
n) No (default)
y/n> 

输入 n 并按 Enter

当显示:

Use web browser to automatically authenticate rclone with remote?
 * Say Y if the machine running rclone has a web browser you can use
 * Say N if running rclone on a (remote) machine without web browser access
If not sure try Y. If Y failed, try N.

y) Yes (default)
n) No
y/n> 

输入 n 并按 Enter

当显示:

Option config_token.
For this to work, you will need rclone available on a machine that has
a web browser available.
For more help and alternate methods see: https://rclone.org/remote_setup/
Execute the following on the machine with the web browser (same rclone
version recommended):

        rclone authorize "dropbox"
Then paste the result.
Enter a value.
config_token> 

:stop_sign: 停止!

:two: 本地安装 rclone 并授权 Dropbox

在您的计算机上安装 rclone。在我的例子中,我在 Mac 上打开了一个新的终端窗口,以便安装 rclone 不会干扰之前的进程,因为我需要在获取 Dropbox 令牌后继续。

我首先通过运行以下命令检查我的 Mac 上是否已安装:

rclone version

我没有安装,所以必须安装。在我的特定情况下,我使用的是 MacPorts,因为 Homebrew 在 Catalina 上工作不佳;请选择您偏好的选项。

Homebrew 命令:

brew install rclone

MacPorts 命令:

sudo port install rclone

安装完成后,在同一个窗口中运行:

rclone authorize "dropbox"

这个 dropbox 名称与我们之前选择的 dropbox_backup 名称无关

运行该命令后,浏览器将打开授权窗口。
如果未打开,请将此 URL 粘贴到您的浏览器中:http://127.0.0.1:53682/auth(根据这些说明)。

登录 Dropbox。点击“允许”按钮。如果一切顺利,您将看到消息:

Success!
All done. Please go back to rclone.

关闭该窗口。

:three: 完成 Dropbox 设置

返回终端,它将显示一个长令牌(它会非常长,我这里只缩短了):

{"access_token":"sl.u.AF5VJTs.................ZvNhniOToyQG","token_type":"bearer","refresh_token":"jygyhExsHRgAAAAAAAAAAfeHd8D0l5jzLvuiZ1onH2nXP2YeC2ycrbm5eQ5Y3uc6","expiry":"2025-08-13T16:58:41.072138+01:00","expires_in":14400}

复制从开头的 { 到结尾的 } 的所有内容,包括大括号本身,然后粘贴到另一个窗口中:

Option config_token.
For this to work, you will need rclone available on a machine that has
a web browser available.
For more help and alternate methods see: https://rclone.org/remote_setup/
Execute the following on the machine with the web browser (same rclone
version recommended):

        rclone authorize "dropbox"
Then paste the result.
Enter a value.
config_token> PASTE_TOKEN_HERE

Enter

如果一切成功,您将看到类似以下内容:

Configuration complete.
Options:
- type: dropbox
- token: {"access_token":"sl.u.AF5VJTs7..........ToyQG","token_type":"bearer","refresh_token":"jygyhExsHRgAAAAAAAAAAfeHd8D0l5jzLvuiZ1onH2nXP2YeC2ycrbm5eQ5Y3uc6","expiry":"2025-08-13T16:58:41.072138+01:00","expires_in":14400}
Keep this "dropbox_backup" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> 

选择 y 来保留它。这将把远程服务器保存为 dropbox_backup,您就可以在 rclone 命令中使用它了。按 Enter

它会显示:

Current remotes:

Name                 Type
====                 ====
dropbox_backup       dropbox

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 退出配置。您的 dropbox_backup 远程现在已准备好使用。按 Enter

root@ 提示符下,运行 rclone lsd dropbox_backup:
这将列出 Dropbox 中的所有顶级目录,以确认连接正常。

:four: 备份

:keyboard: 手动备份

要手动备份,假设您有一个典型的设置(而不是双容器设置),请运行:

sudo rclone copy /var/discourse/shared/standalone/backups/default --exclude tmp/ dropbox_backup:backups
  • /var/discourse/shared/standalone/backups/default → 服务器上的源文件夹(我确认此路径在典型设置中是准确的——不是双容器设置——至少截至 2025 年 8 月)。
  • --exclude tmp/ → 跳过临时文件。
  • dropbox_backup:backups → 远程名称 (dropbox_backup) 和 Dropbox 中的文件夹 (backups)。

这将把所有备份文件(不包括 tmp/)上传到您的 Dropbox 中,到一个名为 backups 的文件夹,使用我们之前选择的名称:dropbox_backup

如果您想要一个包含空格的文件夹,例如 Discourse Backups,请运行以下命令:

sudo rclone copy /var/discourse/shared/standalone/backups/default --exclude tmp/ "dropbox_backup:Discourse Backups"

如果一切顺利,您现在将在 Dropbox 中看到一个 Discourse Backups 文件夹(或您选择的任何名称),其中包含所有备份文件。

既然您已经进行到这一步,请关闭终端中的第二个窗口,即用于在您的计算机上安装 rclone 的窗口,以避免将来混淆。

:alarm_clock: Cron 作业

现在,让我们创建一个 cron 作业来自动化此过程:

crontab -e

您将看到:

no crontab for root - using an empty one
Select an editor.  To change later, run select-editor again.
  1. /bin/nano        <---- easiest
  2. /usr/bin/vim.basic
  3. /usr/bin/vim.tiny
  4. /bin/ed

Choose 1-4 [1]: 

选择 1。按 Enter

您将看到类似以下内容:

# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command

在所有这些内容的末尾,添加 cron 作业。要每天下午 6 点复制备份,请添加以下内容:

0 18 * * * rclone copy /var/discourse/shared/standalone/backups/default --exclude tmp/ "dropbox_backup:Discourse Backups"

因此,您的“列表”将以以下内容结束:

(INITIAL TEXT HERE)

# m h  dom mon dow   command

0 18 * * * rclone copy /var/discourse/shared/standalone/backups/default --exclude tmp/ "dropbox_backup:Discourse Backups"

Ctrl+X。在窗口底部,它会询问是否保存。按 Y 然后按 Enter

您已完成!

您可以根据需要更频繁地运行 cron 作业,因为只有新文件会被复制。

请注意,copy 选项将不断向您的 Dropbox 添加更多备份,即使服务器上的备份已被删除。如果您只想保留服务器上保留的那些备份,请使用 sync 而不是 copy

5 个赞

谢谢,这非常有帮助。我现在已经连接了 rclone 和 Dropbox,如何将 Dropbox 连接到我的 Plex?

有时我想,在那些教程的示例中,是否应该使用 sync 命令而不是 copy(考虑到 Use rclone to sync backups to Dropbox or Google Drive copy 命令作为另一个选项提及,因为我不知道为什么有人会选择使用 copy 而不是 sync,除非他们有无限的空间 :thinking:

对我所做的一切,我都喜欢保留更多的备份,以防万一,至少保留一段时间。保留多个副本能让我安心。只有一个副本会让我紧张 :wink: