Control: 6.7 Ensure That Cloud SQL Database Instances Are Configured With Automated Backups
Description
It is recommended to have all SQL database instances set to enable automated backups.
Backups provide a way to restore a Cloud SQL instance to recover lost data or recover from a problem with that instance. Automated backups need to be set for any instance that contains data that should be protected from loss or damage. This recommendation is applicable for SQL Server, PostgreSql, MySql generation 1 and MySql generation 2 instances.
Remediation
From Google Cloud Console
- Go to the Cloud SQL Instances page in the Google Cloud Console by visiting https://console.cloud.google.com/sql/instances.
- Select the instance where the backups need to be configured.
- Click
Edit
. - In the
Backups
section, check `Enable automated backups', and choose a backup window. - Click
Save
.
From Google Cloud CLI
- List all Cloud SQL database instances using the following command:
gcloud sql instances list --format=json | jq '. | map(select(.instanceType != "READ_REPLICA_INSTANCE")) | .[].name'
NOTE: gcloud command has been added with the filter to exclude read-replicas instances, as GCP do not provide Automated Backups for read-replica instances.
- Enable
Automated backups
for every Cloud SQL database instance using the below command:
gcloud sql instances patch <INSTANCE_NAME> --backup-start-time <[HH:MM]>
The backup-start-time
parameter is specified in 24-hour time, in the UTC±00 time zone, and specifies the start of a 4-hour backup window. Backups can start any time during the backup window.
Default Value
By default, automated backups are not configured for Cloud SQL instances.
Usage
Run the control in your terminal:
powerpipe control run gcp_compliance.control.cis_v400_6_7
Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run gcp_compliance.control.cis_v400_6_7 --share
SQL
This control uses a named query:
select self_link resource, case when backup_enabled then 'ok' else 'alarm' end as status, case when backup_enabled then title || ' automatic backups configured.' else title || ' automatic backups not configured.' end as reason , location as location, project as projectfrom gcp_sql_database_instance;