This page describes how to use the Cloud Firestore scheduled backups feature. Use backups to protect your data from application-level data corruption or from accidental data deletion.
Backups let you configure backup schedules to take daily or weekly backups of the specified database. You can then use these backups to restore data to a new database.
About backups
A backup is a consistent copy of the database at a point in time. The backup contains all data and index configurations at that point in time. A backup does not contain database time to live policies. A backup resides in the same location as the source database.
Backups have a configurable retention period and are stored until the retention period expires or until you delete the backup. Deleting the source database does not automatically delete related backups.
Cloud Firestore stores metadata related to backups and backup schedules related to a database. Cloud Firestore retains this metadata until all backups for the database expire or are deleted.
Creating or retaining backups does not affect the performance of reads or writes in your live database.
Costs
When you use backups, you're charged for the following:
- The amount of storage used by each backup.
- For a restore operation, you're charged based on the size of the backup.
For more details and exact rates, see the Pricing page.
Before you begin
This feature requires the Blaze pricing plan.Required roles
To get the permissions that you need to manage backups and backup schedules, ask your administrator to grant you one or more of the following Identity and Access Management roles:
roles/datastore.owner
: Full access to the Cloud Firestore databaseThe following roles are also available but not visible in the Google Cloud console. Use the Google Cloud CLI to assign these roles:
roles/datastore.backupsAdmin
: Read and write access to backupsroles/datastore.backupsViewer
: Read access to backupsroles/datastore.backupSchedulesAdmin
: Read and write access to backup schedulesroles/datastore.backupSchedulesViewer
: Read access to backup schedulesroles/datastore.restoreAdmin
: Permissions to initiate restore operations
Create and manage backup schedules
The examples below demonstrate how to set up a backup schedule. For each database, you can configure up to one daily backup schedule and up to one weekly backup schedule. You cannot configure multiple weekly backups schedules for different days of the week.
You cannot configure the exact time of day of the backup. Backups are taken at different times each day. For weekly backup schedules, you can configure the day of the week to take a backup.
Create a backup schedule
Use one of the following tools to create a backup schedule.
Create a daily backup schedule
Google Cloud console
In the Google Cloud console, go to the Databases page.
- In the list of databases, find the row for the database. In the Scheduled backups column click either View backups or Edit settings, depending on whether a backup schedule exists.
- Click Edit to edit disaster recovery settings.
- Select the Daily checkbox, set the retention period, and then click Save.
gcloud
To create a backup schedule for a database, use thegcloud firestore backups schedules create
command.
To create a daily backup schedule, set the --recurrence
flag to daily
:
gcloud firestore backups schedules create \ --database='DATABASE_ID' \ --recurrence=daily \ --retention=RETENTION_PERIOD
Replace the following:
- DATABASE_ID: The ID of the database to back up. Set to
'(default)'
for the default database. - RETENTION_PERIOD: Set this to a value up to 14 weeks (
14w
).
Firebase CLI
To create a backup schedule for a database, use the or thefirebase firestore:databases:backups:schedules
command.
To create a daily backup schedule, set the --recurrence
flag to DAILY
:
firebase firestore:backups:schedules:create \ --database 'DATABASE_ID' \ --recurrence 'DAILY' \ --retention RETENTION_PERIOD
Replace the following:
- DATABASE_ID: The ID of the database to back up. Set to
'(default)'
for the default database. - RETENTION_PERIOD: Set this to a value up to 14 weeks (
14w
).
Terraform
To create a daily backup schedule, create agoogle_firestore_backup_schedule
resource.
resource "google_firestore_backup_schedule" "daily-backup" { project = PROJECT_ID database = DATABASE_ID retention = RETENTION_PERIOD_SECONDS daily_recurrence {} }
Replace the following:
- PROJECT_ID: The ID of the project.
- DATABASE_ID: The ID of the database to back up. Set to
'(default)'
for the default database.
You can also use a resource reference to a
Terraform resource of type - RETENTION_PERIOD_SECONDS: Set this to a value in seconds, followed by "s". The maximum value is
8467200s
(14 weeks).
google_firestore_database
.
Create a weekly backup schedule
Google Cloud console
In the Google Cloud console, go to the Databases page.
- In the list of databases, find the row for the database. In the Scheduled backups column click either View backups or Edit settings, depending on whether a backup schedule exists.
- Click Edit to edit disaster recovery settings.
- Select the Weekly checkbox, select a backup day, set the retention period, and then click Save.
gcloud
To create a weekly backup schedule, set the--recurrence
flag to weekly
:
gcloud firestore backups schedules create \ --database='DATABASE_ID' \ --recurrence=weekly \ --retention=RETENTION_PERIOD \ --day-of-week=DAY
- DATABASE_ID: The ID of the database to back up. Set to
'(default)'
for the default database. - RETENTION_PERIOD: Set this to a value up to 14 weeks (
14w
). - DAY: The day of the week to take the backup. Set to
one of the following:
SUN
for SundayMON
for MondayTUE
for TuesdayWED
for WednesdayTHU
for ThursdayFRI
for FridaySAT
for Saturday
Firebase CLI
To create a weekly backup schedule, set the--recurrence
flag to WEEKLY
:
firebase firestore:backups:schedules:create \ --database 'DATABASE_ID' \ --recurrence 'WEEKLY' \ --retention RETENTION_PERIOD --day-of-week DAY
- DATABASE_ID: The ID of the database to back up. Set to
'(default)'
for the default database. - RETENTION_PERIOD: Set this to a value up to 14 weeks (
14w
). - DAY: The day of the week to take the backup. Set to
one of the following:
SUNDAY
for SundayMONDAY
for MondayTUESDAY
for TuesdayWEDNESDAY
for WednesdayTHURSDAY
for ThursdayFRIDAY
for FridaySATURDAY
for Saturday
Terraform
To create a weekly backup schedule, create agoogle_firestore_backup_schedule
resource.
resource "google_firestore_backup_schedule" "weekly-backup" { project = PROJECT_ID database = DATABASE_ID retention = RETENTION_PERIOD_SECONDS weekly_recurrence { day = DAY } }
Replace the following:
- PROJECT_ID: The ID of the project.
- DATABASE_ID: The ID of the database to back up. Set to
'(default)'
for the default database.
You can also use a resource reference to a
Terraform resource of type - RETENTION_PERIOD_SECONDS: Set this to a value in seconds, followed by "s". The maximum value is
8467200s
(14 weeks). - DAY: The day of the week to take the backup. Set to
one of the following:
SUNDAY
for SundayMONDAY
for MondayTUESDAY
for TuesdayWEDNESDAY
for WednesdayTHURSDAY
for ThursdayFRIDAY
for FridaySATURDAY
for Saturday
google_firestore_database
.
List backup schedules
To list all backup schedules for a database, use one of the following methods:
Google Cloud console
In the Google Cloud console, go to the Databases page.
- In the list of databases, find the row for the database. In the Scheduled backups column click either View backups or Edit settings, depending on whether a backup schedule exists.
- The Disaster recovery page opens. This page describes backup schedules and lists available backups.
gcloud
Use thegcloud firestore backups schedules list
command.
gcloud firestore backups schedules list \ --database='DATABASE_ID'
'(default)'
for the default database.
Firebase CLI
Use thefirebase firestore:backups:schedules:list
command.
firebase firestore:backups:schedules:list \ --database 'DATABASE_ID'
'(default)'
for the default database.
Describe backup schedule
To retrieve information about a backup schedule, use one of the following methods:
Google Cloud console
In the Google Cloud console, go to the Databases page.
- In the list of databases, find the row for the database. In the Scheduled backups column click either View backups or Edit settings, depending on whether a backup schedule exists.
- The Disaster recovery page opens. This page describes backup schedules and lists available backups.
gcloud
Use thegcloud firestore backups schedules describe
command:
gcloud firestore backups schedules describe \ --database='DATABASE_ID' \ --backup-schedule=BACKUP_SCHEDULE_ID
- DATABASE_ID: The ID of the database to back up. Set to
'(default)'
for the default database. - BACKUP_SCHEDULE_ID: The ID of a backup schedule. You can view the ID of each backup schedule when you list all backup schedules.
Update a backup schedule
To update the retention period of a backup schedule, use one of the following methods:
Google Cloud console
In the Google Cloud console, go to the Databases page.
- In the list of databases, find the row for the database. In the Scheduled backups column click either View backups or Edit settings.
- Click Edit to edit disaster recovery settings.
- Edit the backup schedule settings and then click Save.
gcloud
Use thegcloud firestore backups schedules update
command:
gcloud firestore backups schedules update \ --database='DATABASE_ID' \ --backup-schedule=BACKUP_SCHEDULE_ID \ --retention=RETENTION_PERIOD
- DATABASE_ID: The ID of the database to back up. Set to
'(default)'
for the default database. - BACKUP_SCHEDULE_ID: The ID of a backup schedule. You can view the ID of each backup schedule when you list all backup schedules.
- RETENTION_PERIOD: Set this to a value up to 14 weeks (
14w
).
Firebase CLI
Use thefirebase firestore:backups:schedules:update
command:
firebase firestore:backups:schedules:update \ BACKUP_SCHEDULE \ --retention RETENTION_PERIOD
- BACKUP_SCHEDULE: The full resource name of a backup schedule. You can view the name of each backup schedule when you list all backup schedules.
- RETENTION_PERIOD: Set this to a value up to 14 weeks (
14w
).
You can update the retention period of a backup schedule, but you cannot update its recurrence. If you need a backup schedule with a different recurrence, delete the old backup schedule if it is no longer required and create a new backup schedule with the desired recurrence.
Delete a backup schedule
To delete a backup schedule, use one of the following methods:
Google Cloud console
In the Google Cloud console, go to the Databases page.
- In the list of databases, find the row for the database. In the Scheduled backups column click either View backups or Edit settings, depending on whether a backup schedule exists.
- Click Edit to edit disaster recovery settings.
- Edit the backup schedule settings and then click Save.
gcloud
Use thegcloud firestore backups schedules delete
command:
gcloud firestore backups schedules delete \ --database='DATABASE_ID' \ --backup-schedule=BACKUP_SCHEDULE_ID
- DATABASE_ID: The ID of the database to back up. Set to
'(default)'
for the default database. - BACKUP_SCHEDULE_ID: The ID of a backup schedule. You can view the ID of each backup schedule when you list all backup schedules.
Firebase CLI
Use thefirebase firestore:backups:schedules:delete
command:
firebase firestore:backups:schedules:delete \ BACKUP_SCHEDULE
- BACKUP_SCHEDULE: The full resource name of a backup schedule. You can view the name of each backup schedule when you list all backup schedules.
Note that deleting a backup schedule will not delete backups already created by this schedule. You can wait for them to expire after their retention period, or to manually delete a backup, see delete backup.
Manage backups
List backups
To list available backups, use one of the following methods:
Google Cloud console
In the Google Cloud console, go to the Databases page.
- In the list of databases, find the row for the database. In the Scheduled backups column click either View backups or Edit settings, depending on whether a backup schedule exists.
- Click Edit to edit disaster recovery settings.
- Edit the backup schedule settings and then click Save.
gcloud
Use thegcloud firestore backups list
command:
gcloud firestore backups list \ --format="table(name, database, state)"
--format="table(name, database, state)"
flag formats the output into a
more readable format.
To list only the backups from a specific location, use the --location
flag:
gcloud firestore backups list \ --location=LOCATION \ --format="table(name, database, state)"
LOCATION
with the name of a Cloud Firestore
location.
Firebase CLI
Use thefirebase firestore:backups:list
command:
firebase firestore:backups:list
--location
flag:
firebase firestore:backups:list \ --location=LOCATION
LOCATION
with the name of a Cloud Firestore
location.
Describe a backup
To view details about a backup, use one of the following methods:
Google Cloud console
In the Google Cloud console, go to the Databases page.
- In the list of databases, find the row for the database. In the Scheduled backups column click either View backups or Edit settings, depending on whether a backup schedule exists.
- The Disaster recovery page opens. This page describes backup schedules and lists available backups.
gcloud
Use thegcloud firestore backups describe
command:
gcloud firestore backups describe \ --location=LOCATION \ --backup=BACKUP_ID
- LOCATION: The location of the database.
- BACKUP_ID: The ID of a backup. You can view the ID of each backup when you list all backups.
Firebase CLI
Use thefirebase firestore:backups:get
command:
firebase firestore:backups:get BACKUP
- BACKUP: The full resource name of a backup. You can view the name of each backup when you list all backups.
Delete backup
To delete a backup, use one of the following methods.
Google Cloud console
In the Google Cloud console, go to the Databases page.
- In the list of databases, find the row for the database. In the Scheduled backups column click either View backups or Edit settings, depending on whether a backup schedule exists. The Disaster recovery page opens. This page describes backup schedules and lists available backups.
- In the Backups table, find the row for a backup and in the Actions column, click View more( ). Click Delete.
- Confirm the action using the text field and click Delete.
gcloud
Use thegcloud firestore backups delete
command:
gcloud firestore backups delete \ --location=LOCATION \ --backup=BACKUP_ID
- LOCATION: The location of the database.
- BACKUP_ID: The ID of a backup. You can view the ID of each backup when you list all backups.
Firebase CLI
Use thefirebase firestore:backups:delete
command:
firebase firestore:backups:delete \ BACKUP
- BACKUP: The full resource name of a backup. You can view the name of each backup when you list all backups.
Restore data from a database backup
A restore operation writes the data from a backup to a new Cloud Firestore database.
To begin a restore operation, use one of the following methods:
Google Cloud console
In the Google Cloud console, go to the Databases page.
- In the list of databases, find the row for the database. In the Scheduled backups column click either View backups or Edit settings, depending on whether a backup schedule exists. The Disaster recovery page opens. This page describes backup schedules and lists available backups.
- In the Backups table, find the row for a backup and in the Actions column, click View more(Cloud Shell. ). Click Restore with
-
The Cloud Shell panel opens with a gcloud CLI command to restore from the selected backup. Replace ID_OF_NEW_DATABASE with an ID for the database and run the command.
Running the command returns a response with more information about the operation. The database soon appears in your list of databases. The restore operation will take some time and must complete before the database is accessible.
gcloud
Use thegcloud firestore databases restore
command:
gcloud firestore databases restore \ --source-backup=projects/PROJECT_ID/locations/LOCATION/backups/BACKUP_ID \ --destination-database='DATABASE_ID'
- PROJECT_ID: Your project ID.
- LOCATION: The location of the database backup and the location of the new database created for the restored data.
- BACKUP_ID: The ID of a backup. You can view the ID of each backup when you list all backups.
- DATABASE_ID: A database ID for the new database. You cannot use a database ID that is already in use.
metadata
, name
, and response
components:
metadata: '@type': type.googleapis.com/google.firestore.admin.v1.RestoreDatabaseMetadata backup: projects/PROJECT_ID/locations/LOCATION/backups/BACKUP_ID database: projects/PROJECT_ID/databases/DATABASE_ID operationState: PROCESSING progressPercentage: completedWork: '20' estimatedWork: '100' startTime: '2023-12-06T14:20:17.398325Z' name: projects/PROJECT_ID/databases/DATABASE_ID/operations/operation_uuid response: '@type': type.googleapis.com/google.firestore.admin.v1.Database createTime: '2023-12-06T14:20:17.398325Z' name: projects/PROJECT_ID/databases/DATABASE_ID ...
metadata
field includes a progressPercentage
component, detailing the estimated progress of the restore thus far, and an operationState
specifying the overall state of the restore.
To retrieve this information again, use gcloud firestore operations list
:
gcloud firestore operations list --database=DATABASE_ID
name
field from the output described above, with gcloud firestore operations describe
:
gcloud firestore operations describe OPERATION_NAME
Firebase CLI
Use thefirebase firestore:databases:restore
command:
firebase firestore:databases:restore \ --backup 'BACKUP' \ --database 'DATABASE_ID'
- BACKUP: The full resource name of a backup. You can view the name of each backup when you list all backups.
- DATABASE_ID: A database ID for the new database. You cannot use a database ID that is already in use.