Data and Recovery · Chapter 2 of 3 · 3 min

Firestore Backups and Point-in-Time Recovery

Two built-in protections, what each one covers, the exact commands to switch them on, and what they cost.

Two different protections

Firestore offers two native ways to recover data. They answer different questions, and a production site wants both.

Point-in-time recovery (PITR) Scheduled backups
Question it answers "What did the data look like at 14:32 yesterday?" "Give me the whole database as it was on Tuesday"
How far back 7 days Up to the retention you choose (up to 14 weeks)
Granularity Any minute in the window One copy per schedule (daily or weekly)
Best for A bad deploy or script that wrote wrong data A bigger loss found later, or a full restore

Before you start

Check which database you have and whether the protections are on:

gcloud firestore databases describe --database='(default)' --project=PROJECT_ID

Look for pointInTimeRecoveryEnablement in the output. Run every command in this chapter with an explicit --project; see gcloud Without Surprises for why.

Switch on point-in-time recovery

gcloud firestore databases update --database='(default)' --enable-pitr --project=PROJECT_ID

From then on, Firestore keeps the history needed to read any document as it was at any minute in the last seven days. Protection starts when you switch it on; it does not reach back before that.

To read old data, you can query the database at a past time, or export the database as it was at that time to Cloud Storage and import from there.

Schedule backups

gcloud firestore backups schedules create --database='(default)' \
  --recurrence=daily --retention=14d --project=PROJECT_ID

This takes one backup a day and keeps each for 14 days. Weekly backups with longer retention are also possible; one daily and one weekly schedule together give both recent and older restore points.

List schedules and existing backups:

gcloud firestore backups schedules list --database='(default)' --project=PROJECT_ID
gcloud firestore backups list --project=PROJECT_ID

What they cost

Both are charged by storage. PITR stores the change history; backups store full copies. For a small database the cost is small, but check the pricing page for your region before switching them on and look at the bill after the first month. A protection that is turned off because of a surprise bill protects nothing.

Exports, the portable option

Native backups live inside Firestore. An export writes the data to a Cloud Storage bucket, which you can keep longer, copy elsewhere, or import into a different project:

gcloud firestore export gs://BUCKET/firestore/$(date +%F) --project=PROJECT_ID

Use exports for long-term archives or before risky one-off migrations. Make sure the bucket is private and has its own retention policy.

What none of these protect against

A sensible setup for a small site

  1. Point-in-time recovery on.
  2. A daily backup schedule, kept 14 days.
  3. A monthly export to a private bucket before any large data change.
  4. A restore drill every quarter.

Try it yourself

Run the describe command above against your own database. If point-in-time recovery shows as disabled, the single update command is the highest-value five minutes of operations work you will do this month.