Is there any way to restore your site from backup in the terminal?


(Ankhamax) #1

I did a backup of my site before I upgraded to the latest version of the discourse however I can’t even access my site any more even though the upgrade appears to be successful as no error is displayed. Is there anyway that I can restore my site from the backup that I created earlier from terminal app as I can’t access the site?

  1. Is it possible?

  2. If yes, where do discourse save or store the backups that I executed from the admin panel?

  3. Is there any guide on how to restore the site from backup?

Thanks


(Régis Hanol) #2

Yes.

They’re stored in public/backups/default/.

Just run the following command (in the discourse directory)

script/discourse restore <filename.of.the.backup.tar.gz>

How to restore backup tar.gz file from console command?
Restoring Discourse from another server
Move your Discourse Instance to a Different Server
How to backup Docker discourse from command-line before rebuilding broken Discourse?
Command line restore for web only container can't load thor
Which command line method is advised for restoring a Discourse forum?
(Ankhamax) #3

Thank you. :slight_smile:


(Benjamin lupton) #4

I got this:

root@bevry-discourse-forum-app:/var/www/discourse# script/discourse restore public/backups/default/bevry-s-discourse-2016-06-30-203044.tar.gz
/usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- thor (LoadError)
	from /usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from script/discourse:3:in `<main>'

root@bevry-discourse-forum-app:/var/www/discourse# ./script/discourse 
/usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- thor (LoadError)
	from /usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from ./script/discourse:3:in `<main>'

Solved by Crash when remapping domain name


(Benjamin lupton) #5

Okay, now I get this:

root@bevry-discourse-forum-app:/var/www/discourse# script/discourse restore public/backups/default/bevry-s-discourse-2016-06-30-203044.tar.gz
URGENT: FATAL:  Peer authentication failed for user "discourse"
 Failed to initialize site default
Starting restore: public/backups/default/bevry-s-discourse-2016-06-30-203044.tar.gz
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize': FATAL:  Peer authentication failed for user "discourse" (PG::ConnectionBad)
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
	from /usr/local/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
	from /usr/local/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:87:in `connection'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/attributes.rb:93:in `columns'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/attributes.rb:98:in `columns_hash'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/core.rb:173:in `block in find_by'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/core.rb:173:in `each'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/core.rb:173:in `all?'
	from /var/www/discourse/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/core.rb:173:in `find_by'
	from /var/www/discourse/lib/discourse.rb:268:in `system_user'
	from script/discourse:66:in `restore'
	from /usr/local/lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
	from /usr/local/lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
	from /usr/local/lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
	from /usr/local/lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
	from script/discourse:216:in `<main>'

(Benjamin lupton) #6

Okay, installing thor via Is there any way to restore your site from backup in the terminal? solved my original issue Uploading backup but it doesn’t show up so didn’t need the command line way of doing it.


(Jay Pfaffman) #7

This seems like a handy thing to be able to do since if you screw up configuring SSO you can’t get back into your site. I spent a week one day trying to get SSO configured, and now that it is configured correctly it seems that my account on the SSO (which I don’t control) is gone, so I can’t get in.

So, script/discourse restore fails because thor isn’t installed.

gem install thor fixes that, but then I’m still denied because:

URGENT: FATAL:  Peer authentication failed for user "discourse"

Solving my immediate problem, I suppose I could turn off SSO from the Rails console. . .

edit: to disable SSO from the rails console:

cd /var/discourse
./launcher enter app
rails c
SiteSetting.enable_sso=false
exit
exit

(Felix Freiberger) #8

There’s a way to log in: Visit /users/admin-login, which can be used to log in via email :slight_smile:


WP Discourse plugin installation and setup
(Ranuka Perera) #9

It worked for me by first getting into the app

./launcher enter app

then

discourse enable_restore
discourse restore <filename.of.the.backup.tar.gz>
discourse disable_restore

Using the script/discourse didn’t work


JSON::ParserError on Jobs::VersionCheck
Which command line method is advised for restoring a Discourse forum?
(Eric Keller) #10

restoring from a app.yml and an external tar.gz file was mixing up some of the items I found along this thread:

TARBALL_PATH=$(ls local/backups/-*.tar.gz | tail -n 1)
TARBALL_NAME=$(basename ${TARBALL_PATH})
cat ${TARBALL_PATH} | docker exec -i app sh -c "cat - > /var/www/discourse/public/backups/default/${TARBALL_NAME}"
docker exec -i app sh -x << EOF
discourse enable_restore
discourse restore ${TARBALL_NAME}
discourse disable_restore
EOF

I had several pitfalls:

  1. the tarball to restore has to be placed exactly in /var/www/discourse/public/backups/default/
  2. the /var/www/discourse/script/discourse restore tarball-name did not work due to some single sign-on known issue
  3. the version of thor installed by gem install thor was too recent and then incompatible with the rest.
  4. finally one of the tarball I tried to restore from did not contain the “meta.json” file…

Hope this helps other in their restore journey.


(Jay Pfaffman) #11

Rather than try to restore from app.yml it’s much easier to just ./launcher enter app and restore it from the command line.


(Eric Keller) #12

The goal was to automate it without any entering container with the launcher.
Imagine your instance got lost for any reason. The only files you stored in git was your containers/app.yml and luckily you have a daily tarball backup.


(Dmitry Demenchuk) #13

You can also do it directly to Postgres:

dropdb dbname
createdb dbname
gunzip -c filename.gz | psql dbname