Fuego

Point in Time Recovery (PITR)

big-idea

Overview

Point in Time Recovery (PITR) allows users to restore a document to a specific state at a given timestamp. This feature is particularly useful for recovering accidental modifications or deletions, ensuring data integrity and historical traceability.

Cloud Firestore PITR provides protection against accidental deletion or incorrect writes by maintaining versions of documents from past timestamps. PITR allows data recovery up to a maximum of 7 days in the past. Enabling PITR does not impact the performance of reads or writes for databases that follow best practices.

How It Works

PITR leverages a versioning system that maintains historical snapshots of a document. Users can select a specific timestamp and revert the document to its state at that moment.

PITR Window

  • After enabling PITR, Cloud Firestore starts retaining PITR data for 7 days.
  • The earliest available PITR data depends on when PITR was enabled:
    • If PITR is disabled: Data is available 1 hour before the read request.
    • If enabled within 7 days: Data is available 1 hour before PITR was enabled.
    • If enabled more than 7 days ago: Data is available 7 days before the read request.
  • A single version per minute is retained within the PITR window.
  • Reads at non-minute granularity (e.g., including milliseconds) will return an error that the read time is too old.
  • Only the latest document version within a minute is stored if multiple writes occur.
  • The earliestVersionTime field indicates the earliest readable timestamp.

PITR

Using PITR in the Interface

1. Accessing PITR

  • Navigate to the document list in the database viewer.
  • Locate the document you want to restore.
  • Open the contextual menu (right-click or use the menu that appears when selecting document).
  • Select Point in Time Recovery.

2. Selecting a Version

  • A history panel will open, displaying available snapshots.
  • Choose a specific version by selecting the corresponding timestamp.
  • Compare the current document with the selected historical version to review changes.

3. Restoring a Version

  • After selecting the desired version, click Restore version.
  • Confirm the restoration process.
  • The document will revert to its chosen state, preserving the audit log of changes.

Ways to Recover Data

  • Recover a portion of the database: Perform a stale read with a query condition or direct key lookup using a timestamp and write the results back to the live database.
  • Recover the entire database: Export the database at a specific timestamp and import it into a new database. PITR export supports all filters, including exporting all documents or specific collections.

Key Features

  • Granular recovery: Restore a document to an exact timestamp.
  • Version comparison: View differences between the current and historical versions before restoring.
  • Data integrity: Ensure that previous versions remain accessible for audit and rollback purposes.
  • Retention window: Data is stored at minute granularity for up to 7 days.

Best Practices

  • Use PITR to safeguard against accidental data loss or corruption.
  • Regularly review document history to track modifications.
  • Before restoring, compare versions to ensure no critical data is lost.
  • Ensure PITR is enabled before relying on historical recovery.
  • Use minute-granularity timestamps to read past versions successfully.