Work with point-in-time recovery (PITR)

This page describes how to use point-in-time recovery (PITR) to retain and recover data in Firestore in Datastore mode.

To understand PITR concepts, see Point-in-time recovery.

Permissions

To get the permissions that you need to manage PITR settings, ask your administrator to grant you the Cloud Datastore Owner (roles/datastore.owner) IAM role on the project whose PITR settings you want to enable. For more information about granting roles, see Manage access to projects, folders, and organizations.

This predefined role contains the permissions required to manage PITR settings. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to manage PITR settings:

  • To enable PITR when creating a database: datastore.databases.create
  • To update PITR settings on existing database: datastore.databases.update,datastore.databases.list
  • To perform reads from PITR data: datastore.databases.get,datastore.entities.get,datastore.entities.list,datastore.namespaces.get,datastore.namespaces.list,datastore.statistics.get,datastore.statistics.list
  • To export PITR data: datastore.databases.export
  • To import PITR data: datastore.databases.import

You might also be able to get these permissions with custom roles or other predefined roles.

Before you begin

Note the following points before you start using PITR:

  • You can't start reading from seven days in the past immediately after you enable PITR.
  • If you want to enable PITR when you create a database, you must use the gcloud firestore databases create command. Enabling PITR while creating a database using the Google Cloud console is not supported.
  • Datastore mode starts retaining versions from the point forward after enabling PITR.
  • You cannot read PITR data in the PITR window after you disable PITR.
  • If you re-enable PITR immediately after disabling it, the past PITR data is no longer available. Any PITR data created before disabling PITR will be deleted after the PITR expiration date.
  • If you accidentally deleted data in the last hour and PITR is disabled, you can restore your data by enabling PITR within one hour of deletion.
  • Any read performed on expired PITR data fails.

Enable PITR

Before using PITR, enable billing for your Google Cloud project. Only Google Cloud projects with billing enabled can use the PITR feature.

To enable PITR for your database:

Console

  1. In the Google Cloud console, go to the Databases page.

    Go to Databases

  2. Select the required database from the list of databases.

  3. In the navigation menu, click Disaster Recovery.

  4. Click Edit to edit the settings.

  5. Select the Enable point-in-time recovery checkbox, and then click Save.

Enabling PITR would incur storage costs. See Pricing for more information.

To disable PITR, clear the Enable point-in-time recovery checkbox from the Disaster Recovery page in the Google Cloud console.

gcloud

Enable PITR during database creation with the gcloud firestore databases create command as follows:

gcloud firestore databases create\
  --location=LOCATION\
  [--database=DATABASE_ID; default="(default)"]\
  [--type=TYPE; default="firestore-native"]\
  --enable-pitr

Replace the values as follows:

  • LOCATION - location where you want to create your database.
  • DATABASE_ID - set to the database ID or (default).
  • TYPE - set to datastore-mode.