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

Not sure… @gerhard or @vinothkannans any ideas?


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

./launcher enter app
rails c
>, with_uploads: false)

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)>, with_uploads: false)
=> #<BackupRestore::Backuper:0x0000562961f73998
 @store=#<BackupRestore::LocalBackupStore:0x0000562961f74938 @base_directory="/var/www/discourse/public/backups/default">,
   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>,
1 Like

Ah, I forgot to add .run in the end. It should be, with_uploads: false).run


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.