Backup and Restore Firebase Firestore data
If you want to backup or restore data from firebase firestore, you have to:
1. Create a new bucket on Google Cloud Console
https://console.cloud.google.com
On “Location Type” step, You can only use United States regions options, Europe options not working for imports/exports, so I recommend using Multi-region
with US
option selected
2. Setup gcloud via Cloud Shell
https://console.cloud.google.com/?cloudshell=true
using command:
gcloud config set project YOUR_PROJECT_NAME
3.1 Export firestore data using same Cloud Shell and command:
gcloud alpha firestore export gs://YOUR_BUCKET_NAME
3.2. Import firestore data using same Cloud Shell:
Firstly, you probably want to change to another project than this, which You’ve backed up previously, don’t you?:
gcloud config set project YOUR_ANOTHER_PROJECT_NAME
Then you can import data by using this command:
gcloud alpha firestore import gs://YOUR_BUCKET_NAME/FOLDER_NAME (folder which was created inside a selected bucket during export function, always named as a date e.g.
2019-09-16T21:13:08_32030)/
If you have any errors during import, most probably there is a problem with roles for default google service account. The fastest way to add required role is by using the command below:
gsutil iam ch serviceAccount:YOUR_PROJECT_NAME@appspot.gserviceaccount.com:roles/storage.admin \
gs://YOUR_BUCKET_NAME
Tweet