Blaze plan users can set up their Firebase Realtime Database for automatic backups, a self-service feature that enables daily backups of your Database application data and Security Rules in JSON format to a Cloud Storage bucket.
Setup
In the Firebase console, navigate to Databases & Storage > Realtime Database.
In the Backups tab, use the in-console workflow to set up your automated backups.
To save on storage costs, we enable Gzip compression by default, and you can choose to enable a 30-day lifecycle policy on your bucket to have backups older than 30 days automatically deleted.
You can view the status and backup activity directly in the Firebase console where you can also start a manual backup. This can be useful for taking specific timed snapshots or as a safety action before you perform any code changes.
Once set up, a new Cloud Storage bucket will be created for you with the WRITER permission for Firebase. You should not store data in this bucket you are not comfortable with Firebase having access to. Firebase will have no additional access to your other Cloud Storage buckets or any other areas of Google Cloud.
Restoring from backups
To restore your Firebase from a backup, first download the file from Cloud Storage to your local disk. This can be done by clicking the filename within the backup activity section or from the Cloud Storage bucket interface. If the file is Gzip compressed, first decompress the file.
You have two options for how to import your data:
Option 1: Use the Firebase console.
Navigate to the Databases & Storage > Realtime Database > Data tab.
Click Import JSON, and select your application data JSON file.
Option 2: Issue a CURL request from your command line.
Retrieve a secret from Firebase, which you can get from the Databases & Storage > Realtime Database > Settings tab.
Enter the following into your terminal, replacing the
DATABASE_NAMEandSECRETfields with your own values:curl 'https://<DATABASE_NAME>.firebaseio.com/.json?auth=<SECRET>&print=silent' -X PUT -d @<DATABASE_NAME>.json
If you are having trouble restoring a backup from a very large database, reach out to Firebase Support.
Scheduling
Your Database backup is assigned to a specific hour each day that ensures even load and highest availability for all backup customers. This scheduled backup will occur regardless of if you do any manual backups throughout the day.
File naming
Files transferred to your Cloud Storage bucket will be timestamped (ISO 8601 standard) and use the following naming conventions:
- Database data:
YYYY-MM-DDTHH:MM:SSZ_<DATABASE_NAME>_data.json - Database rules:
YYYY-MM-DDTHH:MM:SSZ_<DATABASE_NAME>_rules.json
If Gzip
is enabled, a .gz suffix will be appended to the filenames. You can
easily find the backups from a specific date or time using Cloud Storage
prefix searching.
Gzip compression
By default, we compress your backup files using Gzip compression to save on storage costs and decrease transfer times. The compressed filesize varies depending on the data characteristics of your Database, but typical Databases may shrink to ⅓ their original size, saving you on storage costs and decreasing the upload time for your backups.
To decompress your Gzipped JSON files, issue a command line command using the
gunzip binary which is shipped by default for OS-X and most Linux
distributions.
gunzip <DATABASE_NAME>.json.gz # Will unzip to <DATABASE_NAME>.json
Storage 30 day lifecycle
We offer an easy to use configuration switch that enables a default 30 day object lifecycle policy for your Cloud Storage bucket. When enabled, files in your bucket will be automatically deleted after 30 days. This helps to reduce unwanted old backups, saving you on storage costs, and keeping your bucket directory clean. If you place other files into your Automated Backups bucket, they will also be deleted with the same policy.
Costs
The backups feature can be enabled for projects on the Blaze plan for no additional cost. However, you will be charged at the standard rates for the backup files placed in your Cloud Storage bucket. You can enable Gzip Compression and Storage 30 day Lifecycle to reduce your storage costs.