Database recovery guide

Firestore backup and restore guide

Firestore backups are managed exports written to a Google Cloud Storage bucket with gcloud firestore export. You restore them with gcloud firestore import, ideally into a separate scratch project first to prove the export is complete.

Updated by the SenalOps team

How Firestore backups work

Firestore has no dump file you download. A managed export writes your documents to a folder in Cloud Storage, along with an overall export metadata file that describes the export. An import reads that folder back into a Firestore database.

Google Cloud also offers scheduled Firestore backups managed inside the project. Exports remain the portable option, because the files live in a bucket you control.

Step by step

  1. Create a bucket for exports

    Use a dedicated bucket in the same location as your database, with retention rules that match how long you need to keep backups.

    gcloud storage buckets create gs://company-firestore-backups --location=us-central1
  2. Grant export permissions

    The account that runs exports needs the Cloud Datastore Import Export Admin role. The Firestore service agent must be able to write to the bucket, which it can by default when the bucket is in the same project.

    gcloud projects add-iam-policy-binding my-project \
      --member="serviceAccount:[email protected]" \
      --role="roles/datastore.importExportAdmin"
  3. Run an export

    Export into a dated folder so each backup is easy to find. Add --collection-ids to export only specific collections.

    gcloud firestore export gs://company-firestore-backups/2026-09-24
  4. Confirm the export metadata exists

    A finished export folder contains a file ending in .overall_export_metadata. If it is missing, the export did not complete.

    gcloud storage ls gs://company-firestore-backups/2026-09-24/
  5. Test the restore in a scratch project

    Import into a separate Firebase project that can be overwritten. Its Firestore service agent needs read access to the bucket. Then count documents in critical collections.

    gcloud firestore import gs://company-firestore-backups/2026-09-24 --project=my-scratch-project

Things to know before you rely on exports

A few Firestore behaviors surprise teams during their first restore:

  • An export is not guaranteed to be an exact point in time snapshot; writes during the export may or may not be included
  • An import adds and overwrites documents but does not delete documents that are missing from the export
  • Exports and imports are billed as document reads and writes
  • Security rules and indexes are not part of the export, so keep them in source control

Counting documents after an import

Use a count aggregation query from the Admin SDK against the scratch project, for example db.collection("orders").count().get(), and compare the result with production for your most important collections.

How Senal Recover automates this

  • Senal Recover runs managed Firestore exports to your Cloud Storage prefix on a schedule, using a service account configuration that is encrypted as a tenant credential.
  • Every export manifest is inspected before it becomes a restore candidate, and on the Business plan tier two validation imports the export into your own scratch Firebase project.
  • Restores are limited to organization owners, require a recent sign in, and are recorded in the audit log.

FAQ

Firestore backup and restore guide: questions

How do I back up Firestore?

Run gcloud firestore export with a Cloud Storage bucket as the destination. The export writes your documents and an overall export metadata file to that bucket, and you can schedule it to run automatically.

Does a Firestore import delete existing documents?

No. An import writes the documents from the export and overwrites documents with the same IDs, but documents that exist in the database and not in the export stay in place.

Which permissions do Firestore exports need?

The account starting the export needs the Cloud Datastore Import Export Admin role, and the Firestore service agent needs access to the Cloud Storage bucket used for the export.