How do you backup and restore Firestore data?
Answer
Firestore backup and restore options: (1) Managed Backups (generally available since 2024) — Firestore supports automated daily backups retained for 7 days in the same region. Configure via Firebase console or gcloud: gcloud firestore backups schedules create --database="(default)" --recurrence=daily --retention=1w. Restore: gcloud firestore databases restore --source-backup=backup-name --destination-database=restored-db; (2) Point-in-time recovery (PITR) — read data as it was up to 7 days in the past using the readTime parameter. Useful for recovering from accidental deletes: await getDocs(query(collection(db, "users")), { readTime: Timestamp.fromDate(oneDayAgo) }); (3) Export to Cloud Storage — gcloud firestore export gs://my-bucket/backups/$(date +%Y%m%d) exports all data to Cloud Storage as Avro files. Automatable with Cloud Scheduler + Cloud Functions; (4) BigQuery export — stream Firestore data to BigQuery for analytical backups via the Firestore → BigQuery extension; (5) Custom backup scripts — read all documents via Admin SDK and serialize to JSON/CSV; suitable for small databases. Test restore procedures regularly — backup without tested restore is not a backup.
Previous
How do you implement multi-tenant architecture with Firebase?
Next
What is Firebase Extensions and how do you use them?
More Firebase / Firestore Questions
View all →- Advanced How do you design a scalable data model in Firestore?
- Advanced How do you handle Firestore rate limits and quota exhaustion?
- Advanced How do you implement distributed counters in Firestore?
- Advanced How do you migrate from Firebase Realtime Database to Firestore?
- Advanced What are the performance optimization techniques for Firestore queries?