How to backup database only (without uploads) from console?

Is there a way to backup database only from console?

./launcher enter app
discourse backup

fails while trying to include uploads:

...
Unpausing sidekiq...
Finalizing backup...
Creating archive: mysite-2020-02-24-183504-v20200203061927.tar.gz
Making sure archive does not already exist...
Creating empty archive...
Archiving data dump...
Archiving uploads...
EXCEPTION: lib/discourse.rb:57:in `exec': Failed to archive uploads.
tar: /var/www/discourse/public/backups/default/mysite-2020-02-24-183504-v20200203061927.tar: Wrote only 2048 of 10240 bytes
...
6 Likes

Not sure… @gerhard or @vinothkannans any ideas?

3 Likes

Yes, you can take db only backup from rails console with below commands.

./launcher enter app
rails c
> BackupRestore::Backuper.new(Discourse.system_user.id, with_uploads: false)
3 Likes

Hmm, this didn’t produce the backup file. Manual backup works as expected though.

Are there any logs I should examine?

Command output:

[1] pry(main)> BackupRestore::Backuper.new(Discourse.system_user.id, with_uploads: false)
=> #<BackupRestore::Backuper:0x0000562961f73998
 @archive_basename="/var/www/discourse/public/backups/default/mysite-2020-02-25-140934-v20200203061927",
 @archive_directory="/var/www/discourse/public/backups/default",
 @backup_filename="mysite-2020-02-25-140934-v20200203061927.sql.gz",
 @client_id=nil,
 @current_db="default",
 @dump_filename="/var/www/discourse/tmp/backups/default/2020-02-25-140934/dump.sql.gz",
 @filename_override=nil,
 @logs=[],
 @publish_to_message_bus=false,
 @readonly_mode_was_enabled=true,
 @store=#<BackupRestore::LocalBackupStore:0x0000562961f74938 @base_directory="/var/www/discourse/public/backups/default">,
 @success=false,
 @timestamp="2020-02-25-140934",
 @tmp_directory="/var/www/discourse/tmp/backups/default/2020-02-25-140934",
 @user=
  #<User:0x0000562961f70c48
   id: -1,
   username: "system",
   created_at: Wed, 16 Jul 2014 08:22:15 UTC +00:00,
   updated_at: Mon, 24 Feb 2020 23:41:26 UTC +00:00,
   name: "system",
   seen_notification_id: 0,
   last_posted_at: Thu, 13 Feb 2020 05:29:57 UTC +00:00,
   password_hash: [FILTERED],
   salt: "5a5b04e52bc687549aeb1fc8c7537af6",
   active: true,
   username_lower: "system",
   last_seen_at: nil,
   admin: true,
   last_emailed_at: nil,
   trust_level: 4,
   approved: true,
   approved_by_id: nil,
   approved_at: nil,
   previous_visit_at: nil,
   suspended_at: nil,
   suspended_till: nil,
   date_of_birth: nil,
   views: 0,
   flag_level: 0,
   ip_address: nil,
   moderator: true,
   title: nil,
   uploaded_avatar_id: 1,
   locale: nil,
   primary_group_id: nil,
   registration_ip_address: nil,
   staged: false,
   first_seen_at: nil,
   silenced_till: nil,
   group_locked_trust_level: nil,
   manual_locked_trust_level: 4,
   secure_identifier: nil>,
 @user_id=-1,
 @with_uploads=false>
1 Like

Ah, I forgot to add .run in the end. It should be BackupRestore::Backuper.new(Discourse.system_user.id, with_uploads: false).run

13 Likes

I got interested in the subject and read a lot of threads. My conclusion is that it is even safe to restore copies straight from the console to avoid bugs - generally how to do it correctly ?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.