# Cannot restore backup from cli

**URL:** https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803
**Category:** Self-hosting
**Tags:** backups
**Created:** [November 28, 2023, 4:10am UTC](https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803 "2023-11-28T04:10:30Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [November 28, 2023, 4:10am UTC](https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803/1 "2023-11-28T04:10:30Z")

</div>

Hello,

I’m trying to restore a backup and I keep getting this error:

```plaintext
Starting restore: blackiron-2022-12-03-163112-v20221201035918.tar.gz
[STARTED]
'system' has started the restore!
Marking restore as running...
Making sure /var/www/discourse/tmp/restores/default/2023-11-28-040817 exists...
Copying archive to tmp directory...
Unzipping archive, this may take a while...
EXCEPTION: /var/www/discourse/lib/discourse.rb:138:in `exec': Failed to decompress archive.

gzip: stdin: unexpected end of file
tar: Unexpected EOF in archive
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now
/var/www/discourse/lib/discourse.rb:172:in `execute_command'
/var/www/discourse/lib/discourse.rb:138:in `exec'
/var/www/discourse/lib/discourse.rb:34:in `execute_command'
/var/www/discourse/lib/backup_restore/backup_file_handler.rb:78:in `decompress_archive'
/var/www/discourse/lib/backup_restore/backup_file_handler.rb:23:in `decompress'
/var/www/discourse/lib/backup_restore/restorer.rb:42:in `run'
script/discourse:149:in `restore'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/command.rb:28:in `run'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/invocation.rb:127:in `invoke_command'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor.rb:527:in `dispatch'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/thor-1.3.0/lib/thor/base.rb:584:in `start'
script/discourse:290:in `<top (required)>'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/cli/exec.rb:58:in `load'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/cli/exec.rb:58:in `kernel_load'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/cli/exec.rb:23:in `run'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/cli.rb:492:in `exec'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/cli.rb:34:in `dispatch'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/cli.rb:28:in `start'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/exe/bundle:45:in `block in <top (required)>'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.4.13/exe/bundle:33:in `<top (required)>'
/usr/local/bin/bundle:25:in `load'
/usr/local/bin/bundle:25:in `<main>'
Trying to rollback...
There was no need to rollback
Cleaning stuff up...
Removing tmp '/var/www/discourse/tmp/restores/default/2023-11-28-040817' directory...
Marking restore as finished...
Notifying 'system' of the end of the restore...
Finished!
[FAILED]
Restore done.

```

I’m not sure why it says that, the backup is unmodified from when I pulled it. Thank you.

---

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [November 28, 2023, 4:12am UTC](https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803/2 "2023-11-28T04:12:14Z")

</div>

Same error on web.

 ![image](https://global.discourse-cdn.com/meta/original/4X/b/f/e/bfe525e2501b68928047bd07226364d1ed01d468.png)

---

<div class="post-metadata">

### Author: ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)
#### Post date: [November 28, 2023, 4:31am UTC](https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803/3 "2023-11-28T04:31:35Z")

</div>

> [@darkpixlz](#):
>
> `gzip: stdin: unexpected end of file`

This is likely the critical error. Have you tried verifying the backup isn’t corrupt? I think [this would work](https://stackoverflow.com/questions/2001709/how-to-check-if-a-unix-tar-gz-file-is-a-valid-file-without-uncompressing):

```plaintext
$ gunzip -c blackiron-2022-12-03-163112-v20221201035918.tar.gz | tar -t > /dev/null

```

---

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [November 28, 2023, 4:39am UTC](https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803/4 "2023-11-28T04:39:25Z")

</div>

Same issue. I can’t get a new backup because the RAID config for the server is long gone but I need this data.

![image](https://global.discourse-cdn.com/meta/optimized/4X/6/8/b/68bd7861350c969408d3b0576ed80ad379b2e8aa_2_690x57.png)

---

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [November 28, 2023, 4:42am UTC](https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803/5 "2023-11-28T04:42:25Z")

</div>

Checked inside of the backup. Seems to be valid.

 ![image](https://global.discourse-cdn.com/meta/original/4X/d/c/4/dc4513a7fb1325892c66cc7fa7f796626b01c313.png)

---

<div class="post-metadata">

### Author: ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)
#### Post date: [November 28, 2023, 4:48am UTC](https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803/6 "2023-11-28T04:48:23Z")

</div>

Is this on the same machine that you are restoring the backup on? It’s possible the file didn’t finish transferring or otherwise got corrupted in transit.

---

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [November 28, 2023, 4:49am UTC](https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803/7 "2023-11-28T04:49:07Z")

</div>

The backup is on my Windows PC, and I am using scp:

`scp blackiron-2022-12-03-163112-v20221201035918.tar.gz root@#.#.#.#:/var/discourse/shared/standalone/backups/default`

---

<div class="post-metadata">

### Author: ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)
#### Post date: [November 28, 2023, 4:51am UTC](https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803/8 "2023-11-28T04:51:24Z")

</div>

Does the checksum match on both files? (Instructions for generating a checksum [here](https://techdocs.akamai.com/download-ctr/docs/verify-checksum).)

---

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [November 28, 2023, 4:53am UTC](https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803/9 "2023-11-28T04:53:46Z")

</div>

It’d seem like it. I’ll keep doing some digging with WinRAR but if you have any suggestions it’d be appreciated. I get the same warning there too, but I can see it in VSCode fine.

 ![image](https://global.discourse-cdn.com/meta/original/4X/6/9/f/69ff2a023f5388def58d36e71d704fae9cc0523c.png)

---

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [November 28, 2023, 4:59am UTC](https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803/10 "2023-11-28T04:59:20Z")

</div>

If this helps, `pigz` shows:

```plaintext
/blackiron-2022-12-03-163112-v20221201035918.tar.gz to <stdout> pigz: skipping: /blackiron-2022-12-03-163112-v20221201035918.tar.gz: corrupted -- incomplete deflate data

```

---

<div class="post-metadata">

### Author: ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)
#### Post date: [November 28, 2023, 5:00am UTC](https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803/11 "2023-11-28T05:00:37Z")

</div>

> [@darkpixlz](#):
>
> I can see it in VSCode fine.

I don’t have much experience there. If you can get a copy of the files, you should be able to create a new backup file to copy over.

---

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [November 28, 2023, 5:14am UTC](https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803/12 "2023-11-28T05:14:50Z")

</div>

I tried writing my own script to fix it which didn’t work.

I’m also not an expert with gzips, so not much I can do either. If anybody else knows how I can restore it with full access to the sql script and uploads then please let me know. SQL script is fine at a glance and the uploads are fine as well.

---

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [November 28, 2023, 5:28am UTC](https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803/13 "2023-11-28T05:28:23Z")

</div>

Update: I was able to successfully restore an older version of the site, by about 2 months. Still looking to get the new(er) one on.

---

<div class="post-metadata">

### Author: ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)
#### Post date: [November 28, 2023, 5:52am UTC](https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803/14 "2023-11-28T05:52:39Z")

</div>

That’s good news. I found [a suggestion](https://stackoverflow.com/a/201409) to use [The gzip Recovery Toolkit](https://www.urbanophile.com/arenn/coding/gzrt/gzrt.html), which sounds promising.

---

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [November 28, 2023, 6:05am UTC](https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803/16 "2023-11-28T06:05:38Z")

</div>

Followed this guide and moved it and got this error:

```plaintext
root@ftsweb-app:/var/www/discourse# discourse restore blackiron-2022-12-03-163112-v20221201035918.tar.gz
Starting restore: blackiron-2022-12-03-163112-v20221201035918.tar.gz
[STARTED]
'system' has started the restore!
Marking restore as running...
Making sure /var/www/discourse/tmp/restores/default/2023-11-28-060452 exists...
Copying archive to tmp directory...
EXCEPTION: /var/www/discourse/lib/discourse.rb:138:in `exec': Failed to copy archive to tmp directory.
cp: cannot open '/var/www/discourse/public/backups/default/blackiron-2022-12-03-163112-v20221201035918.tar.gz' for reading: Permission denied

```

---

<div class="post-metadata">

### Author: ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)
#### Post date: [November 28, 2023, 6:43am UTC](https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803/17 "2023-11-28T06:43:49Z")

</div>

> [@darkpixlz](#):
>
> `cp: cannot open '/var/www/discourse/public/backups/default/blackiron-2022-12-03-163112-v20221201035918.tar.gz' for reading: Permission denied`

Good chance the file is owned by another user. `ls -l /var/www/discourse/public/backups/default/blackiron-2022-12-03-163112-v20221201035918.tar.gz'` would show the problem, probably.

---

<div class="post-metadata">

### Author: ![darkpixlz](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/darkpixlz/32/549896_2.png) [@darkpixlz](https://meta.discourse.org/u/darkpixlz)
#### Post date: [November 28, 2023, 6:50am UTC](https://meta.discourse.org/t/cannot-restore-backup-from-cli/286803/18 "2023-11-28T06:50:25Z")

</div>

It says that root owns it. Do I need to make it the `discourse` user?

Edit: seems like the tool did more damage.

 ![image](https://global.discourse-cdn.com/meta/original/4X/d/0/d/d0d210e58ac19af2608660e8ecb189cbcfa1acf6.jpeg)
