Finding a deleted document's copy and reading earlier times work in the Free edition. Putting a document back is a change, so it needs Pro.
Which way to use
| How it was deleted | Use |
|---|---|
| In Firetool, one document or a few | The audit log's copy |
| In Firetool, by a bulk change, import, copy, move or migration | Undo the whole job |
| Outside Firetool (your app, a script, another tool), in the last hour | Read it as it was |
| Outside Firetool, up to 7 days ago, with point-in-time recovery on | Read it as it was |
| Anything older | A backup |
From the audit log
Before Firetool deletes a document, it saves a copy in the audit log (unless the policy says to keep no copies).
- Open Tools, Audit log and find the delete. Search by the collection's path or the document ID.
- Click the entry. Entries with a saved copy are marked restorable.
- Choose Restore, then confirm. The document is written back as it was before the delete.
Restoring is a change itself: it follows your role and the project's rules and goes into the audit log.
Undo the whole job
When many documents went in one job, put them all back at once:
- Open Tools → Tasks and choose Undo… on the finished job. Or open any of the job's entries in Tools → Audit log and choose Undo this operation….
- Read the preview: documents put back (deleted or changed by the job), documents it created that are removed, and any that can't be undone. Nothing has changed yet.
- Choose Undo. Changes made to those documents after the job are replaced too, so look at the preview first.
More in Undo an operation.
Read it as it was
Firestore can read data as it was at an earlier time: the last hour on every database, and up to 7 days back when point-in-time recovery is turned on for it. This finds documents deleted by anything, not only Firetool.
- Open the collection the document was in.
- Choose Now in the query bar (Show as of…) and pick a time before the delete. The table shows the collection as it was then.
- Tick the document and choose Put these back… (also in Actions ▾ and the command palette).
- Choose Preview: it lists the document as not there now. Choose Put back.
Each document read at an earlier time is one Firestore read. To turn on point-in-time recovery for a database, open Firestore backups in the project's Services page (Pro).
From a backup
For anything older, you need a Firetool backup made before the delete.
- Right-click the database (or its project) and choose Restore a backup…, then pick the backup file.
- Choose Choose documents…, then paste the document's path (one a line), or tick its collection.
- Choose Preview…, then Preview, and Put back. Only documents that aren't there now, or differ, are written.
Details in Backup and restore. Google's own managed backups are restored to a new database from Firestore backups in the Services page.
Be ready next time
- Keep Keep restorable copies of on Automatic (the default) in Tools, Policy and roles: on production, every change keeps a copy.
- Turn on point-in-time recovery for production databases: 7 days of earlier times instead of one hour.
- Back up regularly: backups from the app, or
firetool backuprun by your system's scheduler. - Mark production projects, so deletes ask for the project ID first: roles and production safety.
Questions
Does Firestore have a recycle bin or undo?
No. A deleted document is gone from Firestore. It can only come back from a copy: Firetool's audit log, an earlier time while Firestore still keeps it, or a backup.
Can I restore a document deleted in the Firebase console?
Yes, if it was deleted within the last hour, or within 7 days with point-in-time recovery on: read the collection as it was and put the document back. Otherwise you need a backup.
Are subcollections restored too?
Deleting a document doesn't delete its subcollections in Firestore, so they're usually still there. A backup restore of a collection path brings back everything under it.
Related
- Work on production Firestore data safely: everything that stops and reverses mistakes.
- Known versions: earlier versions of a document that still exists.
- Backup and restore: backups with users, rules and indexes.