从命令行恢复备份

:bookmark: 本指南介绍了如何在不使用 Discourse Web UI 的情况下,通过命令行恢复 Discourse 备份。
:person_raising_hand: 所需用户级别:管理员
:wrench: 需要控制台访问权限

以下是在不启动 Discourse Web UI 的情况下,通过命令行恢复 Discourse 备份的方法。这在您迁移服务器时非常有用。

先决条件

在开始之前,请确保完成以下步骤:

  1. 从源 Discourse 实例下载最新的备份文件。
  2. 通过运行 ./discourse-setup 或复制您现有的 app.yml 来引导目标 Discourse 实例。
  3. 确保目标 Discourse 实例是最新版本。如有必要,请更新它。

传输备份

  1. SSH 进入目标服务器,或在目标服务器上创建备份文件夹:

mkdir -p /var/discourse/shared/standalone/backups/default

  1. 将您的备份文件上传到目标服务器。

scp /path/to/backup/backup.tar.gz root@192.168.1.1:/var/discourse/shared/standalone/backups/default

请务必替换您正在使用的路径、文件名和服务器名称——但您确实希望备份文件最终位于:

/var/discourse/shared/standalone/backups/default

:mega: 您也可以从 Google Drive、Dropbox、OneDrive 等流行的网络存储站点上传和下载您的 Discourse 备份文件——您需要根据您首选的网络存储提供商查找特定的命令行说明。

:warning: 请勿更改备份的文件名! Discourse 将备份文件名视为元数据,因此如果您更改文件名,恢复将无法正常工作。请保留原始文件名。

/path/to/backup/discourse-xyz.tar.gz 替换为您备份文件的本地路径,将 \u003cserver_ip_address\u003e 替换为目标服务器的 IP 地址。

:bulb: 如果使用 Nginx 作为反向代理(https://meta.discourse.org/t/running-other-websites-on-the-same-machine-as-discourse/17247),请确保容器可以读取所有备份路径,并且 Nginx 可以读取 .sock 文件。

恢复备份

  1. 访问您的目标服务器并导航到 Discourse 文件夹:
cd /var/discourse
  1. 进入 Discourse Docker 应用容器:
./launcher enter app
  1. 启用恢复功能:
discourse enable_restore
  1. 恢复备份文件:
discourse restore sitename-2019-02-03-042252-v20190130013015.tar.gz

:bulb: 提示: 如果您在运行 discourse restore 时不提供文件名,它将列出所有可用的备份文件。

:warning: 如果您站点的 backup_location 设置配置为使用 S3,但您手动将备份文件上传到本地文件系统,则需要指定 --location local

discourse restore --location local sitename-2019-02-03-042252-v20190130013015.tar.gz

类似地,使用 --location s3 可以直接从 S3 备份恢复,而无需先下载它。

  1. 退出 Discourse Docker 应用容器:
exit

重新构建

恢复备份后,您可以选择重新构建目标实例以确保所有设置和配置都已正确应用。

:mega: 现在是更新 /var/discourse/containers/app.yml 以配置完整 HTTPS、附加插件或 CDN 配置的好时机。比较两个实例的 app.yml 配置以确保一致!

cd /var/discourse
./launcher rebuild app

启用电子邮件

恢复备份后,将禁用非员工用户的外发邮件。您不希望您的测试服务器、新服务器或因其他原因恢复了备份的服务器开始向您的用户发送电子邮件!将 disable_emails 站点设置更改为“no”以重新启用电子邮件。

:tada: 就这样。您的 Discourse 服务器已成功恢复。

78 个赞
Move your Discourse Instance to a Different Server
Any other way to take backup and restore?
How easy is it to move to another server?
HELP! My Discourse just deleted everything?
Restore backup is broken
How to migrate Discourse from one server to another with the same DNS name
Best Practices for Backups
Problem upgrading Discourse
Upgrading v2.2.0.beta4 forum with unknown local changes
Set up file and image uploads to S3
Quick question about site backups
My install broke after updating, how can I fix it?
Is there any way to restore your site from backup in the terminal?
Migrating Discourse from one DigitalOcean droplet to another without downtime
Restore backup right away after installing Discourse
Unable to migrate to S3, therefore unable to restore from backup
Restore Failure - S3 (compatible) backup
"EXCEPTION: psql failed: DETAIL: Key (post_id)=(36946) is duplicated."
Migrate from another forum to Discourse
My install is 16,359 commits behind! Advice?
Trying to recover an installation
Migration failed: relation "user_required_fields_versions" already exists
How can I manually verify via the CLI and bypass the Congratulations, you installed Discourse! screen?
Configuring automatic backups
Migrating to a new server that has a new DB and new S3 buckets for backup and uploads
Intended path to migrate S3 to local
Problem when updating Discourse Forum
Failed to restore from the backup
Steps involved to downgrade from 2GB to 1GB on DO?
Forum offline: Restore is not working through web
Forum offline: Restore is not working through web
Testing Restore - not working
Entire site is a blank page after upgrade
"discourse: command not found" when trying to restore a backup from the command line
Stuck with 500 error after weird bugs and a rebuild
Plesk server migration
"Key is stored in legacy trusted.gpg keyring" warning
"Key is stored in legacy trusted.gpg keyring" warning
Discourse broken after moving servers
Stuck and lost updating forum, problems with PG migration
How to manually migrate s3 files to local?
Index_users_on_username_lower error during database restore: import failed
How can I get the current version information from my backup?
Backup Prod -> Snap -> Build Test -> Change Address
How to properly package discourse as an image
2FA with OTP broken after restoring from Backup
I'm trying to migrate an old discourse by creating a new discourse, but I'm having trouble
Recover from filesystem backup: can't rebuild nor start
Error: Can't notify admin while restoring backup during a migration to a fresh install
MKJ's Opinionated Discourse Deployment Configuration
Migrate from AWS to Digital Ocean with 2 containers, spaces and 2 CDNs
Cannot restore database: sql key is duplicated
Finding UI generated backup and restoring site
Backup discourse from the command line
Migration to a Self-Hosted solution from Kubernetes
How to download the backup file without SMTP function?
Redis Problems? (Forum broken after upgrade)
Can't upload backup
Can't upload backup
Can't upload backup
Rate limiter issues when uploading a backup file / can't disable rate limiter
Help restoring - system hung at midnight
Help restoring - system hung at midnight
Uploads missing after restore
My install is 16,359 commits behind! Advice?
Issues Rebuilding After Upgrade to Ubuntu 22.04