# Command line database only backup

**URL:** https://meta.discourse.org/t/command-line-database-only-backup/153232
**Category:** Support
**Tags:** backups
**Created:** [May 29, 2020, 1:53pm UTC](https://meta.discourse.org/t/command-line-database-only-backup/153232 "2020-05-29T13:53:15Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [May 29, 2020, 1:53pm UTC](https://meta.discourse.org/t/command-line-database-only-backup/153232/1 "2020-05-29T13:53:15Z")

</div>

`discourse backup` creates a backup with uploads, regardless of the site setting that controls that. Is there a way to do a database only backup from the command line? It would be handy to be able do this for a number of reasons.

---

<div class="post-metadata">

### Author: ![md-misko](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/md-misko/32/126315_2.png) [@md-misko](https://meta.discourse.org/u/md-misko)
#### Post date: [May 29, 2020, 2:02pm UTC](https://meta.discourse.org/t/command-line-database-only-backup/153232/2 "2020-05-29T14:02:08Z")

</div>

> [@How to backup database only (without uploads) from console?](https://meta.discourse.org/t/how-to-backup-database-only-without-uploads-from-console/142504):
>
> 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-18350…

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [May 29, 2020, 3:00pm UTC](https://meta.discourse.org/t/command-line-database-only-backup/153232/3 "2020-05-29T15:00:09Z")

</div>

Thanks! I read enough here that I think I know and remember everything that’s been posted and sometimes forget to search. 🤷‍♂️

I marked your post as the solution, but here’s the one-liner:

```
/var/discourse/launcher run app "echo 'BackupRestore::Backuper.new(Discourse.system_user.id, with_uploads: false).run' | rails c"

```

---

<div class="post-metadata">

### Author: ![Isambard](https://avatars.discourse-cdn.com/v4/letter/i/858c86/32.png) [@Isambard](https://meta.discourse.org/u/Isambard)
#### Post date: [November 29, 2024, 8:06pm UTC](https://meta.discourse.org/t/command-line-database-only-backup/153232/4 "2024-11-29T20:06:56Z")

</div>

Just a note to self for future reference:

```bash
# enter docker container, or ./launcher enter <dockername>
docker exec -it <dockername> bash
# don't forget to specify database for multisite when running rails console
RAILS_DB=db_name rails c
# review command:
BackupRestore::Backuper.new(Discourse.system_user.id, with_uploads: false) 
# then run backup command
BackupRestore::Backuper.new(Discourse.system_user.id, with_uploads: false).run

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [December 29, 2024, 8:07pm UTC](https://meta.discourse.org/t/command-line-database-only-backup/153232/5 "2024-12-29T20:07:27Z")

</div>

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