This page describes how to schedule exports of your Cloud Firestore data. To run exports on a schedule, we recommend deploying an App Engine service that calls the Cloud Firestore managed export feature. Once deployed, you can schedule calls to this service using the App Engine Cron Service.
Before you begin
Before you schedule data exports with the managed export feature, you must complete the following tasks:
- Enable billing for your Google Cloud Platform project. Only GCP projects with billing enabled can use the export and import feature.
- Create a Cloud Storage bucket for your project in a location near your Cloud Firestore database location. You cannot use a Requester Pays bucket for export and import operations.
- Install the Google Cloud SDK to grant access permissions and deploy the application.
Configure access permissions
The app uses the App Engine default service account to authenticate and authorize its export operations. When you create a project, the default service account is created for you with the following format:
YOUR_PROJECT_ID@appspot.gserviceaccount.com
The service account requires permission to start an export operation and to write to your Cloud Storage bucket. To grant these permissions, assign the following IAM roles to the default service account:
Cloud Datastore Import Export Admin-
OwnerorStorage Adminrole on the bucket
You can use the gcloud and gsutil command-line
tools from the Google Cloud SDK to assign these roles:
-
Assign the Cloud Datastore Import Export Admin role:
gcloud projects add-iam-policy-binding YOUR_PROJECT_ID \ --member serviceAccount:YOUR_PROJECT_ID@appspot.gserviceaccount.com \ --role roles/datastore.importExportAdmin -
Assign the Storage Admin role on your bucket:
gsutil iam ch serviceAccount:YOUR_PROJECT_ID@appspot.gserviceaccount.com:storage.admin \ gs://BUCKET_NAME
Application files
In a new folder, create the following application files using the code below:
- app.yaml
- Configures the App Engine runtime. The app uses the standard environment Node.js runtime.
- app.js
- The main app code. This app sets up a web service at
https://YOUR_PROJECT_ID.appspot.comthat starts export operations. - package.json
- Includes information about the app and its dependencies.
- cron.yaml
- Configures a cron job that calls the web service.
app.yaml
The code above assumes this app is the default application. If it is not, add the following line:
target: cloud-firestore-admin
app.js
package.json
cron.yaml
Modify the url line to configure the export operation. The app sets up a
service at https://YOUR_PROJECT_ID.appspot.com/cloud-firestore-export that
accepts the following URL parameters:
- outputUriPrefix
- the location of you Cloud Storage bucket in the format of
gs://BUCKET_NAME. - collections
- A comma separated list of collection IDs to export. If not specified, the operation exports all collections.
For example, to export all collections with collection ID Songs or Albums
, you would use the following:
url: /cloud-firestore-export?outputUriPrefix=gs://BUCKET_NAME&collections;=Songs,Albums
The example cron.yaml runs an export every 24 hours. For different
schedule options, see the schedule format.
Deploy the app and cron job
Using gcloud, deploy the app and the cron job:
gcloud app deploy app.yaml cron.yaml
Test your cron job
You can test your deployed cron job by starting it in the Cron Jobs page of the Google Cloud Platform Console.
Open the Cron Jobs page in the GCP console.
Open the Cron Jobs pageFor the cron job with a description of Daily Cloud Firestore Export, click Run now.
After the job completes, see the status message under Status. Click View to see the job log. The status message and job log will provide information on job success or failure.
View your exports
After an export operation completes, you can view the exports in your Cloud Storage bucket:
Open the Cloud Storage browser in the GCP Console.
Open the Cloud Storage browser

