Fixing Discourse Restore dump.sql.gz Errors For Mismatched tar/gz files
Zipping your tars or tar-ing your zips? January 24, 2024 Discourse
Got a quick one for you today. I’ve encountered a thing in the past where, when OSX/macOS downloads an archive file, it will automatically extract it or do weird things with the download such that the downloaded file doesn’t actually match what you downloaded from a server. Debugging this is a bit of a pain, and what to do varies on a case-by-case basis of what service you’re downloading from and what you’re trying to do with your downloaded file.
My recent similar pain comes from trying to restore the Afterschool forums after migrating them from Discourse’s hosted model to self-hosting on a Digital Ocean droplet. The forum setup via their instructions was mostly painless (I’m using Mailgun + Namecheap), but when I got around to resorting the backup itself I started to run into issues.
Firstly, I saw that the downloaded file I had downloaded from their backup service wasn’t a valid backup file when trying to backup from the web restore UI. The backup file was a tarball,
afterschool-2023-11-16-213656-v20231111201253.tar, so I was like…? Why wouldn’t that work?
I searched around a bit and saw that apparently the backup wants a gzip file, so I tried:
- Just appending
.gzto the file name
- Unzipping the tarball folder, then rezipping the unpacked folder with
Neither of these worked. I’d try to upload the backup file to Discourse and get the following error:
EXCEPTION: No such file or directory @ rb_check_realpath_internal - /var/www/discourse/tmp/restores/default/2024-01-24-153141/dump.sql.gz
But looking in the folder that dump file was definitely there:
Thinking about what I know about zip files and what little I know about tar files, I started to wonder if the archive was unzipping itself as a folder instead of unzipping the contents into the target folder. So I thought — maybe the tarball itself needs to be gzipped?
So I ran this:
gzip < afterschool-2023-11-16-213656-v20231111201253.tar > afterschool_backup.gz
And uploaded the file to the forums for restore. Earlier in this process I started getting frustrated with backup management in the web console, as it would silently fail, not report logs, get stuck, etc., so I switched to trying to backup in the console. Here’s the instructions for it, but the jist is:
./launcher enter app
discourse restore your-site-2006-01-02-150405-v20200101150405.tar.gz
discourse restore afterschool_backup.gz
But the program failed because “EXCEPTION: Migration version is missing from the filename”. Turns out we got some string file versioning in the filename! I existed the container and went to the backups folder:
Then changed the file name to just append what the original file version name was:
mv afterschool_backup.gz afterschool_backup-213656-v20231111201253.gz
Went back into the container, ran the restore command and BAM! It worked!
TLDR: If your Discourse restore is failing and you’re on macOS/OSX, try directly gzipping your tarball then uploading that!
DateJanuary 24, 2024
PreviouslySo You Wanna Package Some Native Libs Into A NuGet Package Into the depths of csproj and NuGet package management
subscribe to my newsletter to get posts delivered directly to your inbox