pb_data directory (excluding the backups folder itself) packaged as a zip archive.
Understanding backups
Backups in PocketBase:- Create a complete snapshot of your
pb_datadirectory - Are executed within a database transaction (writes are temporarily blocked)
- Include the database and all local storage files
- Exclude the
backups/,.pb_temp/, and autocert cache directories - Can be stored locally or on S3-compatible storage
Storage requirements
To safely perform backups, ensure you have:- Free disk space: At least 2x the size of your
pb_datadirectory - Sufficient I/O: Backups run in a transaction and temporarily block writes
Backup creation uses SQLite’s
PRAGMA wal_checkpoint(TRUNCATE) to ensure database consistency.Creating backups manually
Via admin UI
- Navigate to Settings → Backups in the admin dashboard
- Click Create backup
- Enter a backup name (optional, auto-generated if empty)
- Click Create
pb_backup_myapp_20240303120000.zip.
Via API
Create a backup programmatically using the API:Backup names must match the pattern:
^[a-z0-9_-]+\.zip$Programmatically in Go
If you’re extending PocketBase with Go, you can create backups programmatically:CreateBackup method from core/base_backup.go:44:
- Blocks if another backup/restore is in progress (checked via
StoreKeyActiveBackup) - Triggers
OnBackupCreatehooks for customization - Auto-generates name if not provided
- Runs in a transaction to ensure data consistency
- Automatically excludes backup directory and temp files
Automated backups
Configure automatic backups using a cron expression:Via admin UI
- Go to Settings → Backups
- Enter a cron expression (e.g.,
0 2 * * *for daily at 2 AM) - Set Max backups to keep (e.g.,
7for one week) - Click Save
Cron expression format
PocketBase uses standard cron syntax:| Expression | Description |
|---|---|
0 2 * * * | Daily at 2:00 AM |
0 */6 * * * | Every 6 hours |
0 0 * * 0 | Weekly on Sunday at midnight |
0 3 1 * * | Monthly on the 1st at 3:00 AM |
Automatic cleanup
WhencronMaxKeep is set, PocketBase automatically removes old backups:
Auto-generated backups are prefixed with
@auto_pb_backup_ to distinguish them from manual backups.S3 storage for backups
Store backups on S3-compatible storage for off-site redundancy:Configuration
S3-compatible providers
PocketBase works with any S3-compatible storage:- AWS S3: Standard S3 service
- Backblaze B2: Set
endpointtos3.us-west-000.backblazeb2.com - DigitalOcean Spaces: Set
endpointtonyc3.digitaloceanspaces.com - MinIO: Self-hosted S3-compatible storage
- Wasabi: Cost-effective cloud storage
Some providers require
forcePathStyle: true for proper URL formatting.Listing backups
Via admin UI
View all backups in Settings → Backups.Via API
Downloading backups
Via admin UI
- Go to Settings → Backups
- Click the download icon next to the backup
- Authorize with your superuser credentials
Via API
Backup downloads require a file token:Restoring backups
Prerequisites
- Free disk space: At least 2x the backup size
- Unix-based operating system
- Superuser access
Restore process
The restore process (fromcore/base_backup.go:149-295):
Download and extract
PocketBase downloads the backup (from S3 if configured) and extracts it to a temporary directory inside
pb_data/.pb_temp/.Move current data
Moves the current
pb_data content (excluding backups and temp) to a temporary location: pb_data/.pb_temp/old_pb_data_*.Via admin UI
- Go to Settings → Backups
- Click the restore icon next to the backup
- Confirm the restore operation
- PocketBase will restart automatically
Via API
Programmatically in Go
Error recovery
If restore fails, PocketBase attempts to revert changes:Deleting backups
Via admin UI
- Go to Settings → Backups
- Click the delete icon
- Confirm deletion
Via API
You cannot delete a backup that’s currently being created or restored.
Backup hooks
Customize backup behavior using hooks in your Go application:Best practices
Test restore procedures regularly
Test restore procedures regularly
Schedule quarterly restore tests to verify backup integrity:
- Download a recent backup
- Restore to a test environment
- Verify data completeness
- Test critical application functions
- Document any issues
Implement 3-2-1 backup strategy
Implement 3-2-1 backup strategy
Maintain multiple backup copies:
- 3 total copies of your data
- 2 different storage types (e.g., local + S3)
- 1 off-site copy
Monitor backup size and duration
Monitor backup size and duration
Track backup metrics:Alert on anomalies like sudden size increases or long backup times.
Secure backup access
Secure backup access
- Store S3 credentials securely (use environment variables)
- Enable S3 bucket versioning for additional protection
- Restrict backup API access to superusers only
- Encrypt backups at rest and in transit
Plan for disaster recovery
Plan for disaster recovery
Document your recovery procedures:
- Where backups are stored
- How to access backups during an outage
- Step-by-step restoration process
- Contact information for team members
- Estimated recovery time objective (RTO)
Troubleshooting
Backup creation fails
Error: “Try again later - another backup/restore process has already been started” Solution: Wait for the current backup/restore to complete, or restart PocketBase if the process is stuck.Insufficient disk space
Error: “Failed to create backup” with I/O errors Solution: Free up disk space. You need at least 2x yourpb_data directory size.
S3 connection errors
Error: “Failed to load backups filesystem” Solutions:- Verify S3 credentials are correct
- Check bucket name and region
- Ensure
forcePathStylematches your provider’s requirements - Verify network connectivity to S3 endpoint
Restore fails on Windows
Error: “Restore is not supported on Windows” Solution: Restore manually:- Stop PocketBase
- Extract backup zip
- Replace
pb_datacontents - Start PocketBase
Next steps
Going to production
Learn production deployment best practices
Migrations
Manage database schema changes