In short: for most projects, turn on PocketBase’s built-in scheduled backups and store them in S3. For large pb_data folders, use a sqlite3 .backup script with rsync. In every case, test a restore: a backup you have never restored is only a hope.
PocketBase keeps everything in one folder, which makes backups simple but easy to get wrong. This guide compares the three common approaches and shows how to restore each one. It follows on from our guide to deploying PocketBase to production.
Prerequisites
- A running PocketBase v0.23 or later instance, with Dashboard access as a superuser
- SSH access to the server for the script-based method
- An S3-compatible bucket if you want off-site copies (AWS S3, Cloudflare R2, Backblaze B2 and others work)
sqlite3andrsyncinstalled for the script method:sudo apt install sqlite3 rsync
What you need to back up
All of your data lives in the pb_data directory next to the executable:
data.db: the main SQLite database (collections, records, users)storage/: files uploaded to your collections, unless you store them in S3- logs and local backups
Your code and configuration matter too. Keep pb_hooks and pb_migrations in Git.
Method 1: built-in backups (recommended default)
PocketBase includes backup and restore from the Dashboard under Settings > Backups. You can create a backup on demand, schedule it with a cron expression, set how many to keep, and store it locally or in S3.
Good to know:
- A backup is a full ZIP snapshot of
pb_data, including locally stored uploads. It excludes local backups and files already stored in S3. - The application is put in read-only mode while the ZIP is generated, so schedule it at a quiet hour.
- Use a separate bucket just for backups.
A nightly schedule such as 0 3 * * * (every day at 03:00) with 7 to 14 backups kept is a sensible starting point.
Method 2: copy the folder manually
Stop PocketBase, copy pb_data, start it again:
bashsudo systemctl stop pocketbase
sudo cp -a /opt/pocketbase/pb_data /var/backups/pb_data-$(date +%F)
sudo systemctl start pocketbase
This is the most transactionally safe option, but it causes downtime. Use it before risky changes, such as an update.
Method 3: sqlite3 .backup plus rsync (large data)
A ZIP of a very large pb_data can be slow. The PocketBase documentation suggests another strategy when the folder gets big (around 2 GB or more). sqlite3 .backup copies a consistent snapshot of the database while the app keeps running, and rsync copies only the changed files.
bash#!/usr/bin/env bash
set -euo pipefail
SRC=/opt/pocketbase/pb_data
DEST=/var/backups/pocketbase
STAMP=$(date +%Y%m%d-%H%M%S)
mkdir -p "$DEST"
sqlite3 "$SRC/data.db" ".backup '$DEST/data-$STAMP.db'"
rsync -a "$SRC/storage/" "$DEST/storage/"
find "$DEST" -name 'data-*.db' -mtime +14 -delete
Save it as /usr/local/bin/pb-backup.sh, make it executable and schedule it:
bashsudo chmod +x /usr/local/bin/pb-backup.sh
echo "0 3 * * * root /usr/local/bin/pb-backup.sh" | sudo tee /etc/cron.d/pb-backup
Then copy /var/backups/pocketbase off the server with rclone or rsync to another machine or bucket.
How to restore
- From a built-in backup: open Settings > Backups and use the restore action on the backup you want. You can also download the ZIP and restore it on another server.
- From a manual copy or script: stop PocketBase, replace
data.dbandstorage/with the backed-up versions, fix ownership, start PocketBase.
bashsudo systemctl stop pocketbase
sudo cp /var/backups/pocketbase/data-YYYYMMDD-HHMMSS.db /opt/pocketbase/pb_data/data.db
sudo rsync -a /var/backups/pocketbase/storage/ /opt/pocketbase/pb_data/storage/
sudo chown -R pocketbase:pocketbase /opt/pocketbase/pb_data
sudo systemctl start pocketbase
Test your restore
Once a month, restore the latest backup on a spare machine or a local copy of PocketBase. Check that you can sign in, that records and uploaded files are there, and that the app starts without errors. Write down how long it took: that number is your real recovery time.
Backup checklist
- Scheduled automatic backups are enabled
- At least one copy is stored off the server (S3 or another machine)
- Retention is defined (for example 14 daily copies)
pb_hooksandpb_migrationsare in Git- The settings encryption key is stored in a password manager
- A restore was tested in the last 30 days
FAQ
How often should I back up PocketBase?
Daily is a reasonable default. Increase the frequency if you could not afford to lose a full day of data.
Can I back up PocketBase while it is running?
Yes. The built-in backups and the sqlite3 .backup method are designed for it. A plain file copy of data.db while the app is running is not safe.
Do backups include uploaded files?
Built-in backups include files stored locally in pb_data, but not files stored in an external S3 bucket. Protect those with versioning or replication on the bucket itself.
Next steps
Pair this with a hardened server from our PocketBase production deployment guide, and see the official going to production documentation for the latest recommendations.