smol projects

restoring pocketbase from a backup

23.07.2023 2 min read

I’ve been playing with PocketBase for a bit, and I’m enjoying it so far. Because it’s self-hosted, it’s pretty great for development:

  • Requests are really fast
  • I can make as many API calls as I want

I’ve been storing a bunch of stuff in there: scraped data, some files, and a few database collections for one of my projects. And as someone who is storing his entire life in one database, I don’t think I can be faulted for being a tad bit paranoid when it comes to backups. (OK, so it’s not really my entire life, and the stakes are low, but I really don’t want to lose my data). I wanted to make absolutely sure I could restore my DB, if something went wrong.

So I looked into restoring Pocketbase from a backup. Here are the steps:

  1. You cannot simply move the folders file-for-file into the directories specified in the docker-compose.yml file and import collections from json. Your collections will be imported, but there won’t be any associations with your .db file. Effectively, this does nothing.
  2. In the admin console, you will first need to create a backup from “Initialize new backup”. Some options:
    • “Enable auto backups” - runs a cron job, but I’m not sure how reliable this is. I had a file called “@autopb_backup_bla_bla_bla” so presumably it works; but I remember turning this on a few days back so I should really have more than one copy. (As I was writing this, I saw the cron job run. _But maybe don’t depend on this)
    • Store backups in S3 storage - this works
  3. After you have a backup (either by manually creating it or from the cron job), you will need to move this folder into /pb_data/backups. This is the location specified in the docker-compose.yml file. It should look like /pb_data/backups/your_backup.zip
  4. Click on the refresh icon next to “Backup and restore your PocketBase data”
  5. If everything worked correctly, it should load the backup file into the list. Click on restore from backup on the right
  6. Proceed with the confirmation step by typing the backup directory name into the form input

And that should be it, assuming nothing went wrong along the way 🙃

Built with Astro and Tailwind 🚀