Skip to main content

Configuring Backup and Disaster Recovery in GCP

Configure Persistent Disk snapshot schedules and Cloud SQL backups with point-in-time recovery, then run a real restore test to prove they work.

38 Terms

Overview and What You Will Learn

A backup is only useful if you can restore from it, so this lab treats the restore test as the main event. You will schedule Persistent Disk snapshots, restore one onto a new disk and read the data back, then enable Cloud SQL automated backups with point-in-time recovery and restore a backup into a second instance.

By the end you will be able to:

  • Create a snapshot schedule with retention and attach it to a disk.
  • Restore a disk from a snapshot and verify the file contents.
  • Enable Cloud SQL backups and point-in-time recovery for PostgreSQL.
  • Restore a Cloud SQL backup into another instance and check the data.
  • Explain recovery point and recovery time objectives for each mechanism.

Why This Matters in Production

A completed backup job proves that data was written somewhere, and nothing more. Consider a team whose nightly database backup reports success for a year, and who learns during a real incident that one critical table was never captured. The only defense is a restore test that checks real data, run on a schedule, because that is the one step that catches silent failures, missing tables, and expired retention before they cost you the data.

Core Principles

Each GCP resource has its own backup mechanism, and each needs its own tested restore. Two numbers describe the outcome: the recovery point objective (RPO), how much data you can afford to lose, and the recovery time objective (RTO), how long you can afford to be down.

Mechanism Protects Typical RPO
Disk snapshot schedule Persistent Disk data Schedule interval, such as 24 hours
Cloud SQL automated backup Whole database instance Up to 24 hours
Point-in-time recovery Cloud SQL between backups Seconds to minutes
flowchart TD D[(Persistent Disk)] -->|Schedule| SN[Snapshot] SN -->|Create disk| RD[(Restored disk)] RD -->|Mount and read| V{Data correct?} V -->|Yes| OK([Backup trusted]) V -->|No| FIX([Fix backup job]) classDef store fill:#DBEAFE,color:#1E293B classDef step fill:#326CE5,color:#FFFFFF classDef good fill:#10B981,color:#FFFFFF classDef bad fill:#EF4444,color:#FFFFFF class D,RD store class SN,V step class OK good class FIX bad

Snapshots are incremental, so only changed blocks are stored after the first one. Point-in-time recovery for PostgreSQL works by archiving the write-ahead log, which is why it has its own flag, separate from daily backups.

Detailed Step-by-Step Practical Lab

You need gcloud, a billing account ID, and the psql client for the Cloud SQL part. Cloud Shell has all of these.

Step 1: Create a project and enable the APIs

Bash
export BILLING_ACCOUNT=0X0X0X-0X0X0X-0X0X0X
gcloud projects create gcp-backup-lab-2026 --name="Backup and DR Lab"
gcloud billing projects link gcp-backup-lab-2026 --billing-account=$BILLING_ACCOUNT
gcloud config set project gcp-backup-lab-2026
gcloud services enable compute.googleapis.com sqladmin.googleapis.com

Step 2: Create a VM and a data disk with known contents

Bash
gcloud compute disks create disk-app-data-backup-test \
--zone=asia-south1-a --size=20GB --type=pd-balanced
gcloud compute instances create vm-backup-test \
--zone=asia-south1-a --machine-type=e2-small \
--image-family=debian-12 --image-project=debian-cloud
gcloud compute instances attach-disk vm-backup-test \
--zone=asia-south1-a --disk=disk-app-data-backup-test --device-name=appdata
gcloud compute ssh vm-backup-test --zone=asia-south1-a --quiet --command='
sudo mkfs.ext4 -F /dev/disk/by-id/google-appdata &&
sudo mkdir -p /mnt/appdata &&
sudo mount /dev/disk/by-id/google-appdata /mnt/appdata &&
echo "order-1001 paid 4599.00" | sudo tee /mnt/appdata/orders.txt &&
sudo sync'

Step 3: Create a daily snapshot schedule and attach it

Bash
gcloud compute resource-policies create snapshot-schedule daily-snapshot-policy \
--region=asia-south1 \
--daily-schedule \
--start-time=03:00 \
--max-retention-days=14 \
--on-source-disk-delete=keep-auto-snapshots
gcloud compute disks add-resource-policies disk-app-data-backup-test \
--zone=asia-south1-a \
--resource-policies=daily-snapshot-policy

The start time is in UTC, so 03:00 is 08:30 in Mumbai.

Step 4: Take a manual snapshot now

Bash
gcloud compute disks snapshot disk-app-data-backup-test \
--zone=asia-south1-a \
--snapshot-names=snapshot-manual-test

Step 5: Restore the snapshot to a new disk and prove it

Bash
gcloud compute disks create disk-restored-from-snapshot \
--zone=asia-south1-a \
--source-snapshot=snapshot-manual-test
gcloud compute instances attach-disk vm-backup-test \
--zone=asia-south1-a --disk=disk-restored-from-snapshot --device-name=restored
gcloud compute ssh vm-backup-test --zone=asia-south1-a --quiet --command='
sudo mkdir -p /mnt/restored &&
sudo mount -o ro,noload /dev/disk/by-id/google-restored /mnt/restored &&
cat /mnt/restored/orders.txt'

Seeing order-1001 paid 4599.00 is the proof. A snapshot command that finished without errors proves nothing by itself.

Step 6: Create a Cloud SQL instance with backups and point-in-time recovery For PostgreSQL, point-in-time recovery uses --enable-point-in-time-recovery. The --enable-bin-log flag is for MySQL only.

Bash
gcloud sql instances create pg-backup-test \
--database-version=POSTGRES_15 \
--edition=ENTERPRISE \
--tier=db-f1-micro \
--region=asia-south1 \
--backup-start-time=03:00 \
--enable-point-in-time-recovery \
--retained-backups-count=7 \
--retained-transaction-log-days=3
gcloud sql users set-password postgres \
--instance=pg-backup-test --password='Lab-Only-Pass-2026'

Step 7: Add data, then take an on-demand backup

Bash
cat > orders.sql << 'SQL_EOF'
CREATE TABLE orders (id INT PRIMARY KEY, status TEXT);
INSERT INTO orders VALUES (1001, 'paid'), (1002, 'shipped');
SQL_EOF
PGPASSWORD='Lab-Only-Pass-2026' gcloud sql connect pg-backup-test \
--user=postgres --quiet < orders.sql
gcloud sql backups create --instance=pg-backup-test
gcloud sql backups list --instance=pg-backup-test

Step 8: Restore the backup into a second instance and check the data Copy the backup ID from the list output. Restoring overwrites the target, so use a separate instance rather than the source.

Bash
export BACKUP_ID=1760000000000
gcloud sql instances create pg-backup-test-restored \
--database-version=POSTGRES_15 --edition=ENTERPRISE \
--tier=db-f1-micro --region=asia-south1
gcloud sql backups restore $BACKUP_ID \
--restore-instance=pg-backup-test-restored \
--backup-instance=pg-backup-test --quiet
gcloud sql users set-password postgres \
--instance=pg-backup-test-restored --password='Lab-Only-Pass-2026'
echo "SELECT * FROM orders;" > check.sql
PGPASSWORD='Lab-Only-Pass-2026' gcloud sql connect pg-backup-test-restored \
--user=postgres --quiet < check.sql

Both rows should come back. Note how long the restore took, because that real duration is your measured RTO.

Step 9: Clean up

Bash
gcloud compute instances delete vm-backup-test --zone=asia-south1-a --quiet
gcloud compute disks delete disk-app-data-backup-test disk-restored-from-snapshot \
--zone=asia-south1-a --quiet
gcloud compute snapshots delete snapshot-manual-test --quiet
gcloud sql instances delete pg-backup-test-restored --quiet
gcloud sql instances delete pg-backup-test --quiet
rm -f orders.sql check.sql
gcloud projects delete gcp-backup-lab-2026 --quiet

Production Best Practices & Common Pitfalls

  • Schedule real restore tests. Quarterly is a sensible start, and a test should verify actual data such as row counts or file checksums, not just that a restore command succeeded.
  • Match retention to requirements. A workload with a seven-year regulatory rule needs a policy built for it, not the 14-day window in this lab.
  • Store copies in another region. Snapshots accept --storage-location, and Cloud SQL supports cross-region read replicas that can be promoted during a regional outage.
  • Restore a point in time with a clone. To recover from a bad DELETE, clone the instance to a moment just before it. This works only within the transaction log retention window:
Bash
gcloud sql instances clone pg-backup-test pg-backup-test-pitr \
--point-in-time='2026-10-13T08:15:00Z'
  • Protect the backups themselves. Turn on --deletion-protection for production instances, restrict who can delete snapshots, and consider customer-managed encryption keys.
  • Consider Backup and DR Service. For many workloads across projects, the managed Backup and DR Service adds central policies and immutable, access-controlled vaults.
  • Alert on failures. Create a log-based alert for failed backup operations so a silent failure becomes a page.
Common Mistake

Configuring backups and never performing a test restore. The job reports success every night, and the first real restore is the first time anyone learns it was incomplete.

Common Mistake

Using the MySQL flag --enable-bin-log on a PostgreSQL instance. Point-in-time recovery then is not configured the way you think, so confirm it in the instance settings.

Security

The lab password is for a disposable instance only. In production use IAM database authentication or Secret Manager, and remember a snapshot or backup contains the same sensitive data as the original.

Quick Reference & Troubleshooting Commands

Command Description
gcloud compute resource-policies create snapshot-schedule Define a snapshot schedule
gcloud compute disks add-resource-policies Attach a schedule to a disk
gcloud compute disks snapshot Take a manual snapshot
gcloud compute disks create --source-snapshot= Restore a snapshot to a new disk
gcloud sql backups create Take an on-demand backup
gcloud sql backups restore Restore a backup into an instance
gcloud sql instances clone --point-in-time= Recover to a specific moment
Symptom Likely fix
Restored disk will not mount Check the filesystem type and mount read-only with noload if needed
Restore fails with a size or version error The target needs the same database version and at least the source's storage
Point-in-time clone fails The timestamp is outside the log retention window or before PITR was enabled
Scheduled snapshots missing Confirm the policy is attached and check the schedule's UTC start time

Resources

Artifact Registry

Google Cloud's current, unified package and container image storage service, the successor to the older Container Registry. It supports container images alongside language packages like npm, Maven, and Python packages in one service, and supports cleanup policies to automatically remove old, untagged image versions.

BigQuery

Google Cloud's serverless data warehouse for analytics, priced based on the volume of data a query actually scans rather than pre-provisioned compute capacity. Selecting only needed columns and querying a properly partitioned table's relevant date range are the two highest-impact levers for controlling BigQuery cost.

Bigtable (GCP)

A wide-column NoSQL database built for very high throughput at extremely low latency, suited to time-series data, IoT telemetry, and analytics workloads with massive write volume. It is a specialized tool distinct from Firestore's document model or Cloud SQL's relational model.

Billing Account (GCP)

A separate object from a Project that holds the actual payment method for Google Cloud usage. One Billing Account can be linked to many Projects, all of whose usage is billed to that same account, letting a company centralize payment while individual Projects retain their own separate IAM control over resources.

Cloud Armor

A security policy service attached to a Global External HTTP(S) Load Balancer, filtering malicious requests before they reach the backend. It supports rate-based rules blocking a single source IP exceeding a request threshold, and preconfigured WAF rules blocking common attack patterns like SQL injection, Google's equivalent of AWS WAF or Azure WAF.

Cloud Functions (GCP)

Google Cloud's event-driven, single-purpose compute service, the most granular and shortest-lived compute unit in GCP's compute spectrum. It fits a narrow niche compared to Cloud Run - a specific triggered action like resizing an uploaded image, rather than a full application with multiple routes and business logic.

Cloud Load Balancing

Google Cloud's family of load balancing products, spanning Global External HTTP(S) Load Balancers (public, distributed globally via a single IP), Regional External Load Balancers, and Internal Load Balancers reachable only from within the VPC. The right type depends on traffic type and whether the backend should ever be reachable from the public internet.

Cloud Logging

Google Cloud's service for collecting, storing, and querying log data from every GCP service and custom applications. Its query filter syntax lets logs be narrowed by resource, severity, and specific field values, and Log Sinks can route matching logs to BigQuery, Cloud Storage, or Pub/Sub for long-term retention beyond the default window.

Cloud Monitoring

Google Cloud's metrics, dashboards, and alerting service. An alert policy requires a Notification Channel explicitly attached to actually notify someone when it fires - without one, the policy still evaluates and logs its own firing history, but nobody is ever told, a common and easy-to-miss misconfiguration.

Cloud NAT

A service providing outbound-only internet connectivity for resources with no external IP address, GCP's equivalent of an AWS or Azure NAT Gateway. Cloud NAT requires a Cloud Router in the same region and provides zero inbound connectivity capability - a resource behind it remains completely unreachable from the internet.

Cloud Run

A fully managed, serverless platform for running containerized applications, scaling automatically to zero when idle and billing only for actual invocations. It combines the flexibility of running any container with zero OS management overhead, making it the right default for a standard stateless containerized web service.

Cloud SQL

Google Cloud's managed relational database service, supporting MySQL, PostgreSQL, and SQL Server. It is the right default for a traditional relational workload with moderate scale needs, handling patching, backups, and replication automatically without requiring OS-level access to the underlying database server.

Cloud Spanner

A globally distributed, strongly consistent relational database offering both SQL semantics and horizontal scalability beyond what a single Cloud SQL instance can provide. It is the right choice specifically when a workload needs both relational query capability and massive scale simultaneously, not simply because a workload feels large or important.

Cloud Storage Bucket

The top-level container for objects in Google Cloud Storage, GCP's object storage service equivalent to AWS S3 or Azure Blob Storage. Every object uploaded to Cloud Storage must belong to exactly one bucket, and bucket-level settings control default storage class, location, and access permissions for everything inside it.

Cloud VPN (GCP)

A service connecting an on-premises network to a GCP VPC over an encrypted tunnel, similar to VPN Gateway in Azure or a Site-to-Site VPN in AWS. It requires a Cloud Router as its foundation and is distinct from VPC Network Peering, which connects two GCP VPCs directly rather than an external network.

Compute Engine

Google Cloud's Infrastructure-as-a-Service offering, providing full virtual machines with complete OS-level control. It is the right choice specifically when a workload needs custom software, specific OS configurations, or hardware-level access that GKE and Cloud Run don't expose.

Error Reporting (GCP)

A Google Cloud operations service that automatically aggregates and groups application errors from logs and instrumented code, surfacing recurring error patterns and their frequency without requiring manual log searching for each individual occurrence.

Firestore

A serverless NoSQL document database built for mobile and web application data, flexible schemas, and real-time client synchronization. It is not a strong fit for workloads needing complex relational joins or multi-row transactions across unrelated entities, which point instead to Cloud SQL or Spanner.

GCP Audit Log

A specific category of Cloud Logging entry recording administrative actions and data access. Admin Activity logs (configuration changes) are always enabled and cannot be disabled; Data Access logs (who read or wrote actual data) are disabled by default for most services and must be explicitly enabled before that history exists.

GCP Firewall Rule

A rule defined at the VPC level controlling inbound or outbound traffic, applied using network tags or Service Accounts on instances rather than being tied to a specific subnet boundary. A firewall rule only affects VMs carrying the exact matching tag or identity - a VM without it is entirely unaffected, silently, with no error to flag the mismatch.

GCP Folder

An optional grouping node in the GCP resource hierarchy, sitting between the Organization and individual Projects. Folders are commonly used to group Projects by team, department, or environment, letting IAM permissions and Organization Policies be applied once at the Folder level rather than repeated across every Project inside it.

GCP IAM Role Types

Google Cloud IAM roles come in three types: Basic roles (Owner, Editor, Viewer) which are broad and legacy; Predefined roles curated by Google and scoped to a specific service's specific needs; and Custom roles built from individual permissions for access needs a predefined role doesn't precisely match.

GCP Organization

The top-level node in Google Cloud's resource hierarchy, tied to a Google Workspace or Cloud Identity domain. An Organization contains Folders and Projects, and policies or IAM permissions set at this level automatically apply to everything beneath it across the entire company.

GCP Project

The fundamental unit of organization in Google Cloud - every resource belongs to exactly one Project, which serves as the boundary for billing, IAM permissions, and API enablement. A Project has a permanent, globally unique Project ID chosen at creation and never changeable, distinct from its display name which can be updated freely.

GCP Quota

A default limit on how much of a specific resource (like VM CPUs or API calls) can be used per Project per region, designed to prevent runaway costs and protect shared infrastructure. Quotas can be checked and increased through the Console ahead of a known future need, such as a planned launch event.

GCP Storage Class

A pricing and access tier for Cloud Storage objects - Standard, Nearline, Coldline, or Archive - trading lower storage cost against higher retrieval cost and a longer minimum storage duration. Deleting or overwriting an object before its class's minimum duration elapses still bills as if it were stored the full minimum period.

GKE Autopilot

A mode of Google Kubernetes Engine where Google manages node provisioning, sizing, and patching entirely - you define workloads, and nodes appear automatically to run them, billed per pod resource request rather than per node. It is the lower-effort default for most containerized workloads, versus Standard mode's direct node pool control.

Managed Instance Group

A group of identical Compute Engine VMs created from an Instance Template and managed as a single unit, GCP's equivalent of an AWS Auto Scaling Group or Azure VM Scale Set. A Managed Instance Group can autoscale based on a metric like CPU utilization, adding or removing instances automatically within configured minimum and maximum bounds.

Network Tag (GCP)

A freeform string label attached to a Compute Engine VM at creation time, used to target firewall rules to specific VMs. Network tags are simple but can be forgotten or misspelled at scale, which is why Service Account-based targeting is often preferred for anything security-critical in a growing fleet.

OS Login

A Compute Engine feature that ties SSH access to a user's actual Google Identity and IAM permissions, rather than manually managing individual SSH public keys per VM. Enabling OS Login means revoking a departing employee's GCP access also immediately revokes their SSH access to every VM, with no separate key cleanup needed.

Organization Policy (GCP)

A constraint applied at the Organization, Folder, or Project level that restricts what resources are allowed to look like across everything beneath that level - for example, blocking external IP addresses on VMs or restricting allowed regions. Unlike IAM, which controls who can act, Organization Policy controls what configurations are permitted.

Persistent Disk (GCP)

The block storage attached to a Compute Engine VM, equivalent to an AWS EBS volume or Azure Managed Disk. Persistent Disks come in zonal (replicated within one zone, lower cost) and regional (synchronously replicated across two zones, survives a single zone failure) variants.

Security Command Center

Google Cloud's security posture management service, continuously scanning deployed resources against security best practices and surfacing specific, severity-ranked findings - like a publicly accessible storage bucket - rather than a single opaque score. Findings should be prioritized by actual severity, not treated as a count to minimize.

Service Account (GCP)

An identity used by applications, VMs, and automated processes to authenticate to Google Cloud APIs, rather than by a human user. A Service Account is itself also a resource with its own IAM permissions, and can be attached directly to a VM or impersonated temporarily, both safer alternatives to downloading its long-lived JSON key file.

Shared VPC

A configuration where one Project (the host) owns a VPC network, while other Projects (service projects) attach to it and deploy resources using its subnets. This centralizes network administration in the host Project while letting individual teams in service Projects still manage their own resources independently.

Spot VM (GCP)

A Compute Engine VM using Google's spare, unused capacity at a steep discount, with the trade-off that Google can reclaim the instance with short notice. Spot VMs are appropriate only for fault-tolerant, interruption-tolerant workloads like batch processing, never for customer-facing services needing reliable availability.

VPC (GCP)

A Virtual Private Cloud in Google Cloud is a global resource by default, unlike the regional VPC or VNet model in AWS or Azure - a single GCP VPC can span every region, with individual subnets defined per-region inside it. The default auto-mode VPC pre-creates a subnet in every region, while a custom-mode VPC starts empty until subnets are deliberately defined.

VPC Network Peering

A direct connection between two separate VPCs, potentially in different Projects or Organizations, with traffic never touching the public internet. Peering must be established from both sides to become active, and is explicitly non-transitive - if VPC A peers with B, and B peers with C, A cannot reach C without its own direct peering connection to C.

Explore More in GCP Operations, Security, and Production Readiness

All 6 Topics

Frequently Asked Questions

Is Configuring Backup and Disaster Recovery in GCP free to learn on DevOps Network?

Yes - this topic, like everything on DevOps Network, is 100% free with no paywall or sign-up gate.

What does the Configuring Backup and Disaster Recovery in GCP topic cover?

Configure Persistent Disk snapshot schedules and Cloud SQL backups with point-in-time recovery, then run a real restore test to prove they work.

Found a mistake, an outdated step or a broken link?