This page describes Spanner backup schedule operations and explains how to set up a backup schedule for your database.
Before you begin
-
To get the permissions that you need to create and manage backup schedules, ask your administrator to grant you the following IAM roles on the instance:
-
Create, view, update, and delete backup schedules:
Cloud Spanner Backup Admin (
roles/spanner.backupAdmin
) -
Create and view backup schedules:
Cloud Spanner Backup Writer (
roles/spanner.backupWriter
)
-
Create, view, update, and delete backup schedules:
Cloud Spanner Backup Admin (
Create a backup schedule
Console
In the Google Cloud console, go to the Spanner Instances page.
Click the instance containing the database.
Click the database.
In the navigation menu, click the Backup/Restore.
Click Create backup schedule.
Fill out the form, then click Create.
gcloud
Before using any of the command data below, make the following replacements:
- SCHEDULE_ID: the backup schedule ID.
- PROJECT_ID: the project ID.
- INSTANCE_ID: the ID of the instance where you want to create the backup schedule.
- DATABASE_ID: the ID of the database where you want to create the backup schedule.
-
RETENTION_DURATION: the retention duration of
the backups created by the schedule. For example, if you want the retention duration to be one
day, you can use
86400s
. -
CRONTAB_EXPRESSION:
the crontab expression for the backup schedule frequency. For example, if you want the
backup schedule frequency to be every 12 hours, you can use
0 12 * * *
. -
BACKUP_TYPE:
whether it's a full backup schedule or an incremental backup schedule. Possible values are
full-backup
orincremental-backup
. -
ENCRYPTION_TYPE:
the encryption type of backups created by the backup schedule.
Valid values are
USE_DATABASE_ENCRYPTION
,GOOGLE_DEFAULT_ENCRYPTION
, orCUSTOMER_MANAGED_ENCRYPTION
. If you useCUSTOMER_MANAGED_ENCRYPTION
, you must specify akmsKeyName
. If your backup type isincremental-backup
, the encryption type must beGOOGLE_DEFAULT_ENCRYPTION
.
Execute the following command:
Linux, macOS, or Cloud Shell
gcloud spanner backup-schedules create SCHEDULE_ID \ --project=PROJECT_ID \ --instance=INSTANCE_ID \ --database=DATABASE_ID \ --retention-duration=RETENTION_DURATION \ --cron="CRONTAB_EXPRESSION" \ --backup-type=BACKUP_TYPE \ --encryption-type=ENCRYPTION_TYPE
Windows (PowerShell)
gcloud spanner backup-schedules create SCHEDULE_ID ` --project=PROJECT_ID ` --instance=INSTANCE_ID ` --database=DATABASE_ID ` --retention-duration=RETENTION_DURATION ` --cron="CRONTAB_EXPRESSION" ` --backup-type=BACKUP_TYPE ` --encryption-type=ENCRYPTION_TYPE
Windows (cmd.exe)
gcloud spanner backup-schedules create SCHEDULE_ID ^ --project=PROJECT_ID ^ --instance=INSTANCE_ID ^ --database=DATABASE_ID ^ --retention-duration=RETENTION_DURATION ^ --cron="CRONTAB_EXPRESSION" ^ --backup-type=BACKUP_TYPE ^ --encryption-type=ENCRYPTION_TYPE
REST v1
Before using any of the request data, make the following replacements:
- PROJECT_ID: the project ID.
- INSTANCE_ID: the ID of the instance where you want to create the backup schedule.
- DATABASE_ID: the ID of the database where you want to create the backup schedule.
- SCHEDULE_ID: the backup schedule ID.
-
BACKUP_TYPE:
whether it's a full backup schedule or an incremental backup schedule.
Possible values are
fullBackupSpec
orincrementalBackupSpec
. -
ENCRYPTION_TYPE: the encryption type of backups
created by the backup schedule. Possible values are
USE_DATABASE_ENCRYPTION
,GOOGLE_DEFAULT_ENCRYPTION
, orCUSTOMER_MANAGED_ENCRYPTION
. If you useCUSTOMER_MANAGED_ENCRYPTION
, you must specify akmsKeyName
. If your backup type isincremental-backup
, the encryption type must beGOOGLE_DEFAULT_ENCRYPTION
. - RETENTION_DURATION: the retention duration of the backups created by the schedule.
HTTP method and URL:
POST https://spanner.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID/backupSchedules?backup_schedule_id=SCHEDULE_ID
Request JSON body:
{ "retentionDuration": "RETENTION_DURATION", "spec": { "cronSpec": { "text": "0 2 * * *" } }, "encryptionConfig": { "encryptionType": "ENCRYPTION_TYPE" }, "BACKUP_TYPE": {} }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID/backupSchedules/SCHEDULE_ID", "retentionDuration": "86400s", "encryptionConfig": { "encryptionType": "USE_DATABASE_ENCRYPTION" }, "spec": { "cronSpec": { "text": "0 2 * * *", "timeZone": "UTC", "creationWindow": "14400s" } }, "BACKUP_TYPE": {}, "updateTime": "2024-05-22T11:13:51.835590Z" }
Client libraries
C#
To create a full backup schedule, see the following sample code:
To create an incremental backup schedule, see the following sample code:C++
To create a full backup schedule, see the following sample code:
To create an incremental backup schedule, see the following sample code:Go
To create a full backup schedule, see the following sample code:
To create an incremental backup schedule, see the following sample code:Java
To create a full backup schedule, see the following sample code:
To create an incremental backup schedule, see the following sample code:Node.js
To create a full backup schedule, see the following sample code:
To create an incremental backup schedule, see the following sample code:Python
To create a full backup schedule, see the following sample code:
To create an incremental backup schedule, see the following sample code:Get a backup schedule
Console
In the Google Cloud console, go to the Spanner Instances page.
Click the instance containing the database.
Click the database.
In the navigation menu, click the Backup/Restore.
Click the Schedules tab to view all the backup schedules and their information.
gcloud
Before using any of the command data below, make the following replacements:
- PROJECT_ID: the project ID.
- INSTANCE_ID: the instance ID.
- DATABASE_ID: the database ID.
- SCHEDULE_ID: the backup schedule ID.
Execute the following command:
Linux, macOS, or Cloud Shell
gcloud spanner backup-schedules describe SCHEDULE_ID \ --project=PROJECT_ID \ --instance=INSTANCE_ID \ --database=DATABASE_ID
Windows (PowerShell)
gcloud spanner backup-schedules describe SCHEDULE_ID ` --project=PROJECT_ID ` --instance=INSTANCE_ID ` --database=DATABASE_ID
Windows (cmd.exe)
gcloud spanner backup-schedules describe SCHEDULE_ID ^ --project=PROJECT_ID ^ --instance=INSTANCE_ID ^ --database=DATABASE_ID
You should receive a response similar to the following:
{ encryptionConfig: encryptionType: USE_DATABASE_ENCRYPTION incrementalBackupSpec: {} name: projects/my-project/instances/my-instance/databases/my-database/backupSchedules/my-schedule retentionDuration: 2592000s spec: cronSpec: creationWindow: 14400s text: 0 */4 * * * timeZone: UTC updateTime: '2024-09-13T10:24:18.754839Z' }
REST v1
Before using any of the request data, make the following replacements:
- PROJECT_ID: the project ID.
- INSTANCE_ID: the instance ID.
- DATABASE_ID: the database ID.
- SCHEDULE_ID: the backup schedule ID.
HTTP method and URL:
GET https://spanner.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID/backupSchedules/SCHEDULE_ID
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID/backupSchedules/SCHEDULE_ID", "retentionDuration": "100000s", "encryptionConfig": { "encryptionType": "USE_DATABASE_ENCRYPTION" }, "spec": { "cronSpec": { "text": "0 2 * * *", "timeZone": "UTC", "creationWindow": "14400s" } }, "fullBackupSpec": {}, "updateTime": "2024-05-22T11:13:51.835590Z" }
Client libraries
C#
C++
Go
Java
Node.js
Python
List backup schedules
Console
In the Google Cloud console, go to the Spanner Instances page.
Click the instance containing the database.
Click the database.
In the navigation menu, click the Backup/Restore.
Click the Schedules tab to view all the backup schedules and their information.
gcloud
Before using any of the command data below, make the following replacements:
- PROJECT_ID: the project ID.
- INSTANCE_ID: the instance ID.
- DATABASE_ID: the database ID.
Execute the following command:
Linux, macOS, or Cloud Shell
gcloud spanner backup-schedules list \ --project=PROJECT_ID \ --instance=INSTANCE_ID \ --database=DATABASE_ID
Windows (PowerShell)
gcloud spanner backup-schedules list ` --project=PROJECT_ID ` --instance=INSTANCE_ID ` --database=DATABASE_ID
Windows (cmd.exe)
gcloud spanner backup-schedules list ^ --project=PROJECT_ID ^ --instance=INSTANCE_ID ^ --database=DATABASE_ID
You should receive a response similar to the following:
Name | Backup type | Cron | Retention duration | Encryption type |
---|---|---|---|---|
my-full-schedule | FULL | 30 12 * * * | 2592000s | USE_DATABASE_ENCRYPTION |
my-incr-schedule | INCREMENTAL | 0 */4 * * * | 2592000s | USE_DATABASE_ENCRYPTION |
REST v1
Before using any of the request data, make the following replacements:
- PROJECT_ID: the project ID.
- INSTANCE_ID: the instance ID.
- DATABASE_ID: the database ID.
HTTP method and URL:
GET https://spanner.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID/backupSchedules
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "backupSchedules": [ { "name": "projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID/backupSchedules/SCHEDULE_ID", "retentionDuration": "172800s", "encryptionConfig": { "encryptionType": "USE_DATABASE_ENCRYPTION" }, "spec": { "cronSpec": { "text": "0 */12 * * *", "timeZone": "UTC", "creationWindow": "14400s" } }, "fullBackupSpec": {}, "updateTime": "2024-09-09T07:21:43.946180Z" }, { "name": "projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID/backupSchedules/SCHEDULE_ID", "retentionDuration": "2592000s", "encryptionConfig": { "encryptionType": "CUSTOMER_MANAGED_ENCRYPTION", "kmsKeyName": "projects/PROJECT_ID/locations/us-central1/keyRings/cmek-demo/cryptoKeys/test-key" }, "spec": { "cronSpec": { "text": "30 12 * * *", "timeZone": "UTC", "creationWindow": "14400s" } }, "fullBackupSpec": {}, "updateTime": "2024-09-17T18:27:53.868741Z" } ] }
Client libraries
C#
C++
Go
Java
Node.js
Python
Update a backup schedule
Console
In the Google Cloud console, go to the Spanner Instances page.
Click the instance containing the database.
Click the database.
In the navigation menu, click the Backup/Restore.
Click the Schedules tab.
Select More actions for your backup schedule and click Update.
You can update the frequency and retention time of the backup schedule. If it's a full backup schedule, you can also update the encryption type.
Click Save.
gcloud
Before using any of the command data below, make the following replacements:
- SCHEDULE_ID: the backup schedule ID.
- PROJECT_ID: the project ID.
- INSTANCE_ID: the ID of the instance where you want to modify the backup schedule.
- DATABASE_ID: the ID of the database where you want to modify the backup schedule.
- RETENTION_DURATION: the retention duration of the backups created by the schedule.
-
CRONTAB_EXPRESSION:
the crontab expression for the backup schedule frequency. For example, if you want the
backup schedule frequency to be every 12 hours, you can use
0 12 * * *
. -
ENCRYPTION_TYPE:
the encryption type of backups created by the backup schedule.
Valid values are
USE_DATABASE_ENCRYPTION
,GOOGLE_DEFAULT_ENCRYPTION
, orCUSTOMER_MANAGED_ENCRYPTION
. If you useCUSTOMER_MANAGED_ENCRYPTION
, you must specify akmsKeyName
. If your backup type isincremental-backup
, the encryption type must beGOOGLE_DEFAULT_ENCRYPTION
.
Execute the following command:
Linux, macOS, or Cloud Shell
gcloud spanner backup-schedules update SCHEDULE_ID \ --project=PROJECT_ID \ --instance=INSTANCE_ID \ --database=DATABASE_ID \ --retention-duration=RETENTION_DURATION \ --cron="CRONTAB_EXPRESSION" \ --encryption-type=ENCRYPTION_TYPE
Windows (PowerShell)
gcloud spanner backup-schedules update SCHEDULE_ID ` --project=PROJECT_ID ` --instance=INSTANCE_ID ` --database=DATABASE_ID ` --retention-duration=RETENTION_DURATION ` --cron="CRONTAB_EXPRESSION" ` --encryption-type=ENCRYPTION_TYPE
Windows (cmd.exe)
gcloud spanner backup-schedules update SCHEDULE_ID ^ --project=PROJECT_ID ^ --instance=INSTANCE_ID ^ --database=DATABASE_ID ^ --retention-duration=RETENTION_DURATION ^ --cron="CRONTAB_EXPRESSION" ^ --encryption-type=ENCRYPTION_TYPE
REST v1
Before using any of the request data, make the following replacements:
- PROJECT_ID: the project ID.
- INSTANCE_ID: the ID of the instance where you want to modify the backup schedule.
- DATABASE_ID: the ID of the database where you want to modify the backup schedule.
- SCHEDULE_ID: the backup schedule ID.
-
RETENTION_DURATION: the retention duration of
the backups created by the schedule. For example, if you want the retention duration to be one day,
specify
86400s
. -
ENCRYPTION_TYPE:
the encryption type of backups created by the backup schedule.
Possible values are
USE_DATABASE_ENCRYPTION
,GOOGLE_DEFAULT_ENCRYPTION
, orCUSTOMER_MANAGED_ENCRYPTION
. If you useCUSTOMER_MANAGED_ENCRYPTION
, you must specify akmsKeyName
. If your backup type isincremental-backup
, the encryption type must beGOOGLE_DEFAULT_ENCRYPTION
.
HTTP method and URL:
PATCH https://spanner.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID/backupSchedules/SCHEDULE_ID?updateMask=retention_duration,encryption_config,spec.cron_spec.text
Request JSON body:
{ "retentionDuration": "RETENTION_DURATION", "spec": { "cronSpec": { "text": "0 2 * * *" } "encryptionConfig": { "encryptionType": "ENCRYPTION_TYPE" }, }, }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID/backupSchedules/SCHEDULE_ID", "retentionDuration": "86400s", "encryptionConfig": { "encryptionType": "USE_DATABASE_ENCRYPTION" }, "spec": { "cronSpec": { "text": "0 2 * * *", "timeZone": "UTC", "creationWindow": "14400s" } }, "fullBackupSpec": {}, "updateTime": "2024-05-22T11:13:51.835590Z" }
Client libraries
C#
C++
Go
Java
Node.js
Python
Delete a backup schedule
Console
In the Google Cloud console, go to the Spanner Instances page.
Click the instance containing the database.
Click the database.
In the navigation menu, click the Backup/Restore.
Select More actions for your backup schedule and click Delete.
Type the backup schedule name.
Click Confirm.
gcloud
Before using any of the command data below, make the following replacements:
- SCHEDULE_ID: the backup schedule ID.
- PROJECT_ID: the project ID.
- INSTANCE_ID: the ID of the instance where you want to delete the backup schedule.
- DATABASE_ID: the ID of the database where you want to delete the backup schedule.
Execute the following command:
Linux, macOS, or Cloud Shell
gcloud spanner backup-schedules delete SCHEDULE_ID \ --project=PROJECT_ID \ --instance=INSTANCE_ID \ --database=DATABASE_ID
Windows (PowerShell)
gcloud spanner backup-schedules delete SCHEDULE_ID ` --project=PROJECT_ID ` --instance=INSTANCE_ID ` --database=DATABASE_ID
Windows (cmd.exe)
gcloud spanner backup-schedules delete SCHEDULE_ID ^ --project=PROJECT_ID ^ --instance=INSTANCE_ID ^ --database=DATABASE_ID
REST v1
Before using any of the request data, make the following replacements:
- PROJECT_ID: the project ID.
- INSTANCE_ID: the ID of the instance where you want to delete the backup schedule.
- DATABASE_ID: the ID of the database where you want to delete the backup schedule.
- SCHEDULE_ID: the backup schedule ID.
HTTP method and URL:
DELETE https://spanner.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID/backupSchedules/SCHEDULE_ID
To send your request, expand one of these options:
You should receive a successful status code (2xx) and an empty response.
Client libraries
C#
C++
Go
Java
Node.js
Python
Set IAM access control policy
You can set an IAM access policy to specify who has access to the backup schedule.
gcloud
Before using any of the command data below, make the following replacements:
- SCHEDULE_ID: the backup schedule ID.
- PROJECT_ID: the project ID.
- INSTANCE_ID: the instance ID.
- DATABASE_ID: the database ID.
Execute the following command:
Linux, macOS, or Cloud Shell
gcloud spanner backup-schedules set-iam-policy SCHEDULE_ID \ --project=PROJECT_ID \ --instance=INSTANCE_ID \ --database=DATABASE_ID \ policy.json
Windows (PowerShell)
gcloud spanner backup-schedules set-iam-policy SCHEDULE_ID ` --project=PROJECT_ID ` --instance=INSTANCE_ID ` --database=DATABASE_ID ` policy.json
Windows (cmd.exe)
gcloud spanner backup-schedules set-iam-policy SCHEDULE_ID ^ --project=PROJECT_ID ^ --instance=INSTANCE_ID ^ --database=DATABASE_ID ^ policy.json
You should receive a response similar to the following:
Updated IAM policy for backupSchedule [SCHEDULE_ID]. bindings: - members: - user:test@google.com role: roles/editor etag: BwYi82k-fho= version: 1
policy.json
file that you can use along with this
gcloud CLI command:
{ "version": 1, "etag": "BwYi8ypICC0=", "bindings": [ { "role": "roles/editor", "members": [ "user:test@gmail.com" ] } ] }
REST v1
Before using any of the request data, make the following replacements:
- PROJECT_ID: the project ID.
- INSTANCE_ID: the instance ID.
- DATABASE_ID: the database ID.
- SCHEDULE_ID: the backup schedule ID.
HTTP method and URL:
POST https://spanner.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID/backupSchedules/SCHEDULE_ID:setIamPolicy?alt=json
Request JSON body:
{ "policy": { "version": 1, "etag": "BwYi8ypICC0=", "bindings": [ { "role": "roles/editor", "members": [ "user:test@gmail.com" ] } ] } }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ { "version": 1, "etag": "etag", "bindings": [ { "role": "roles/non-primitive", "members": [ "user:test@gmail.com" ] } ] } }
Get IAM access control policy
gcloud
Before using any of the command data below, make the following replacements:
- SCHEDULE_ID: the backup schedule ID.
- PROJECT_ID: the project ID.
- INSTANCE_ID: the instance ID.
- DATABASE_ID: the database ID.
Execute the following command:
Linux, macOS, or Cloud Shell
gcloud spanner backup-schedules get-iam-policy SCHEDULE_ID \ --project=PROJECT_ID \ --instance=INSTANCE_ID \ --database=DATABASE_ID
Windows (PowerShell)
gcloud spanner backup-schedules get-iam-policy SCHEDULE_ID ` --project=PROJECT_ID ` --instance=INSTANCE_ID ` --database=DATABASE_ID
Windows (cmd.exe)
gcloud spanner backup-schedules get-iam-policy SCHEDULE_ID ^ --project=PROJECT_ID ^ --instance=INSTANCE_ID ^ --database=DATABASE_ID
You should receive a response similar to the following:
bindings: - members: - user:test@gmail.com role: roles/editor etag: BwYi82k-fho= version: 1
REST v1
Before using any of the request data, make the following replacements:
- INSTANCE_ID: the instance ID.
- DATABASE_ID: the database ID.
- SCHEDULE_ID: the backup schedule ID.
- PROJECT_ID: the project ID.
HTTP method and URL:
POST https://spanner.googleapis.com/v1/projects/PROJECT_ID/instances/INSTANCE_ID/databases/DATABASE_ID/backupSchedules/SCHEDULE_ID:getIamPolicy?alt=json
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ { "version": 1, "etag": "BwYbyZ9pc4o=", "bindings": [ { "role": "roles/editor", "members": [ "user:test@gmail.com" ] } ] } }