使用命令行手动备份和恢复

你好,

我有一个损坏的 Discourse 论坛,我想将其迁移到另一台服务器。我在以下文件夹中有一个备份:

$ ls /var/discourse/shared/standalone/backups/default
$ forum-2019-05-06-033420-v20180920042415.tar

在我的新服务器上,我尝试加载备份,但失败了:

$ ./launcher enter app
$ discourse enable_restore
$ gzip public/backups/default/forum-2019-05-06-033420-v20180920042415.tar
$ discourse restore forum-2019-05-06-033420-v20180920042415.tar.gz
Starting restore: forum-2019-05-06-033420-v20180920042415.tar.gz
[STARTED]
'system' has started the restore!
Marking restore as running...
Making sure /var/www/discourse/tmp/restores/default/2019-05-08-180427 exists...
Copying archive to tmp directory...
Unzipping archive, this may take a while...
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now
No metadata file to extract.
Validating metadata...
  Current version: 20190508135348
  Restored version: 20180920042415
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now
Extracting dump file...
EXCEPTION: /var/www/discourse/lib/backup_restore/restorer.rb:264:in `block in extract_dump': Failed to extract dump file.
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now
/var/www/discourse/lib/discourse.rb:29:in `execute_command'
/var/www/discourse/lib/backup_restore/restorer.rb:264:in `block in extract_dump'
/usr/local/lib/ruby/2.6.0/fileutils.rb:128:in `chdir'
/usr/local/lib/ruby/2.6.0/fileutils.rb:128:in `cd'
/var/www/discourse/lib/backup_restore/restorer.rb:263:in `extract_dump'
/var/www/discourse/lib/backup_restore/restorer.rb:58:in `run'
script/discourse:141:in `restore'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
script/discourse:282:in `<top (required)>'
/usr/local/lib/ruby/2.6.0/bundler/cli/exec.rb:74:in `load'
/usr/local/lib/ruby/2.6.0/bundler/cli/exec.rb:74:in `kernel_load'
/usr/local/lib/ruby/2.6.0/bundler/cli/exec.rb:28:in `run'
/usr/local/lib/ruby/2.6.0/bundler/cli.rb:463:in `exec'
/usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/usr/local/lib/ruby/2.6.0/bundler/cli.rb:27:in `dispatch'
/usr/local/lib/ruby/2.6.0/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/usr/local/lib/ruby/2.6.0/bundler/cli.rb:18:in `start'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-1.17.2/exe/bundle:30:in `block in <top (required)>'
/usr/local/lib/ruby/2.6.0/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-1.17.2/exe/bundle:22:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
Trying to rollback...
There was no need to rollback
Cleaning stuff up...
Removing tmp '/var/www/discourse/tmp/restores/default/2019-05-08-180427' directory...
Unpausing sidekiq...
Marking restore as finished...
Notifying 'system' of the end of the restore...
Finished!
[FAILED]

我不知道为什么,但来自之前论坛的备份已损坏,我无法再访问 UI,只能通过命令行操作。

我如何手动将数据库和文件从之前的 Discourse 迁移到新的 Discourse?

该 tar 备份包含以下内容:

It looks like the backup file has been damaged. Maybe something happened to the file during the transfer to the new server. How did you transfer the file between your servers? Try comparing the checksums of the file on both servers. Are they the same?

You should do what @gerhard said.

Also, if you can access the command line on the old server you can

cd /var/discourse
./launcher enter app
discourse backup

to create a new backup.

You could also rsync the uploads and do an SQL-only backup.

The problem is that the old Discourse is broken. The docker version was to old and the ubuntu was to old too. When rebuilding is was not possible to launch the discourse again. So I cannot do automatic backup only manually.

I try to copy the standalone folder to the new discourse instance and also the app.yml file and rebuild the app but all I have is this page:

Any idea how can I rebuild the discourse with the previous data ?

I’d try rsyncing the whole /var/discourse folder to the new machine (delete the current one on the new machine first and destroy the current docker image).

EDIT: you could be somewhat selective like not copying logs, but simple is simple.

nice, thx :slight_smile: