从命令行备份Discourse

:bookmark: This guide covers how to back up and restore your Discourse site using command line tools, specifically designed for self-hosted environments.

:person_raising_hand: Required user level: Administrator

:information_source: You can use the below placeholders to automatically fill out the command line prompts in this guide:

Backing up

To create a backup of your Discourse site, follow these steps:

  1. Enter the container:
./launcher enter app
  1. Run the backup:
discourse backup
exit

This will print out the final filename of your backup. Download the backup and container configuration (if needed) to your local machine:

scp =USER=@=HOST=:/var/discourse/shared/standalone/backups/default/=FILENAME= .
scp =USER=@=HOST=:/var/discourse/containers/app.yml .

Restoring

To restore a Discourse backup, follow these steps:

  1. Install a Discourse site on the server you are restoring to.

If you’re testing this procedure multiple times, you can wipe the data on your test server.

Wipe Discourse data (optional)
./launcher stop app
./launcher destroy app
rm -r /var/discourse/shared/standalone/
mkdir -p /var/discourse/shared/standalone/backups/default/

  1. Upload the backup file:
scp =FILENAME= =USER=@=HOST=:/var/discourse/shared/standalone/backups/default/
  1. Enter the container and start the restore:
./launcher enter app
discourse enable_restore
discourse restore =FILENAME=

If you happen to forget what the filename was, run the “discourse restore” command by itself to get a list of available backup files.

:information_source: For a two-container setup, use ./launcher enter web_only and replace standalone with web-only in the path to backups.

For additional information about restoring Discourse backups, see Restore a backup from the command line.

Last edited by @SaraDev 2024-08-23T20:50:17Z

Check documentPerform check on document:
38 个赞

我应该在哪里运行此命令?在我的云服务器终端还是本地计算机上?
尽管两者都给了我“权限被拒绝”的错误

在您的本地计算机上。

您是否正在使用 SSH 密钥进行连接?错误与之相关。

然后命令应为:

scp -i /path_to_your_key/your_key.pem root@147.43.15.199:/var/discourse/shared/standalone/backups/default/discourse-2024-12-25-033740-v20241211222608.tar.gz .

我有一个场景,我想要将 Discourse 安装迁移到一个全新的服务器上。
我的计划是:

  1. 创建一个新的空白 Discourse 安装
  2. 备份旧的 Discourse,将备份 scp 到新服务器并恢复
  3. 将所有 S3(图片等)复制到另一个账户上的新 S3

恢复过程进行得很顺利,直到它开始查找 S3 并因没有访问权限而失败。我认为它正在尝试访问旧 Discourse 上的同一个 S3 存储桶名称,但新服务器上不存在该存储桶,我也无法创建它。

有什么推荐的解决方案吗?

我想过尝试更改旧 Discourse 上的 S3 存储桶名称(在执行备份之前),然后在恢复时,它将期望拥有新的 S3 存储桶。但我担心如果我只是将其切换到一个不存在的存储桶,旧 Discourse 会发生什么。

有一个隐藏设置可以将 s3 文件下载到备份中。

您需要在 yml 文件中配置 s3,如 为上传配置 S3 兼容对象存储提供商 中所述。

然后,当您恢复备份时,它会将上传推送到新存储桶。

1 个赞

你最终解决这个问题了吗?

您需要在环境变量中配置 s3,如为上传配置 S3 兼容对象存储提供商中所述。

如果新服务器上的 s3 设置不同,这一点尤其正确。将 s3 值放入数据库可能会导致许多问题。

但是,还原命令有一个开关,可以在各个部分之间暂停。这会有所帮助。