Create snapshots to periodically backup data from these types of persistent disks:
You can create snapshots from disks even while they are attached to running instances. Snapshots are global resources, so you can use them to restore data to a new disk or instance within the same project. You can also share snapshots across projects.
Before you begin
- If you want to use the command-line examples in this guide, do the following:
- Install or update to the latest version of the Google Cloud CLI.
- Set a default region and zone.
- If you want to use the API examples in this guide, set up API access.
Prepare for creating snapshots
To prepare for creating Persistent Disk or Hyperdisk snapshots, do the following:
Review Best practices for Compute Engine disk snapshots to prepare your disk for snapshotting.
If you wish to customize the default storage location for all your new snapshots, update the snapshot settings for your project (Preview). Google Cloud maintains a predefined default storage location value until you update the snapshot settings for the first time. This predefined location is the nearest multi-region to the source disk.
Read Creating a Persistent Disk snapshot schedule to learn about creating a snapshot schedule and attaching it to your disks. Backing up your disks regularly with scheduled snapshots can reduce the risk of unexpected data loss.
Create a snapshot of Persistent Disk volume
The instructions for creating snapshots of Persistent Disk volumes are different, depending on whether you are creating a snapshot of zonal Persistent Disk or regional Persistent Disk.
Create a snapshot of a zonal Persistent Disk volume
Console
-
In the Google Cloud console, go to the VM instances page.
Go to VM instances
The remaining steps will appear automatically in the Google Cloud console. - Select the project that contains your VM instances.
- In the Name column, click the name of the VM that has the persistent disk to back up.
-
In
Storage :- To back up the boot disk, in the Boot disk section, click the Name of the boot disk.
- To back up an attached persistent disk, in Additional disks, click the Name of the attached persistent disk.
-
Click
Create snapshot . -
In Name, enter a unique name to help identify the purpose of the snapshot, for example:
boot-disk-snapshot
attached-persistent-disk-snapshot
-
In Type, the default is a regular snapshot, which is best for long-term back up and
disaster recovery.
Choose Archive snapshot for more cost-efficient data retention.
-
In the Location section, choose your snapshot storage location. The predefined or customized default location defined in your snapshot settings is automatically selected. Optionally, you can override the snapshot settings and store your snapshots in a custom storage location by doing the following:
-
Choose the type of storage location that you want for your snapshot.
-
Choose Multi-regional
for higher availability at a higher cost.
- Choose Regional snapshots for more control over the physical location of your data at a lower cost.
-
Choose Multi-regional
for higher availability at a higher cost.
-
In the Select location field, select the specific region or multi-region that you want to use. To use the region or multi-region that is closest to your source disk, select Based on disk's location.
-
- To create a manual snapshot, click Create.
gcloud
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
Create your snapshot using the storage location policy defined by your snapshot settings (Preview) or using an alternative storage location of your choice. For more information, see Choose your snapshot storage location.
To create a snapshot of a zonal Persistent Disk volume in the predefined or customized default location configured in your snapshot settings, use the
gcloud compute snapshots create
command.gcloud compute snapshots create SNAPSHOT_NAME \ --source-disk SOURCE_DISK \ --snapshot-type SNAPSHOT_TYPE \ --source-disk-zone SOURCE_DISK_ZONE
Alternatively, to override the snapshot settings and create a snapshot in a custom storage location, include the
--storage-location
flag to indicate where to store your snapshot:gcloud compute snapshots create SNAPSHOT_NAME \ --source-disk SOURCE_DISK \ --source-disk-zone SOURCE_DISK_ZONE \ --storage-location STORAGE_LOCATION \ --snapshot-type SNAPSHOT_TYPE
Replace the following:
- SNAPSHOT_NAME: A name for the snapshot.
- SOURCE_DISK: The name of the zonal Persistent Disk volume from which you want to create a snapshot.
- SNAPSHOT_TYPE: The snapshot type, either STANDARD or ARCHIVE. If a snapshot type is not specified, a STANDARD snapshot is created. Choose Archive for more cost-efficient data retention.
- SOURCE_DISK_ZONE: The zone of the zonal Persistent Disk volume from which you want to create a snapshot.
- STORAGE_LOCATION: For custom storage locations, this is the Cloud Storage multi-region or the Cloud Storage region where you want to store your snapshot. You can specify only one storage location.
Use the
--storage-location
flag only when you want to override the predefined or customized default storage location configured in your snapshot settings.
The gcloud CLI waits until the operation returns a status of
READY
orFAILED
, or reaches the maximum timeout and returns the last known details of the snapshot.
Terraform
To create a snapshot of the zonal Persistent Disk volume, use the
google_compute_snapshot
resource.
To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.
API
Create your snapshot in the storage location policy defined by your snapshot settings (Preview) or using an alternative storage location of your choice. For more information, see Choose your snapshot storage location.
To create your snapshot in the predefined or customized default location configured in your snapshot settings, make a
POST
request to thesnapshots.insert
method:POST https://compute.googleapis.com/compute/v1/projects/DESTINATION_PROJECT_ID/global/snapshots { "name": SNAPSHOT_NAME "sourceDisk": "projects/SOURCE_PROJECT_ID/zones/SOURCE_ZONE/disks/SOURCE_DISK_NAME "snapshotType": SNAPSHOT_TYPE }
Replace the following:
- DESTINATION_PROJECT_ID: The ID of project in which you want to create the snapshot.
- SNAPSHOT_NAME: A name for the snapshot.
- SOURCE_PROJECT_ID: The ID of the source disk project.
- SOURCE_ZONE: The zone of the source disk.
- SOURCE_DISK_NAME: The name of the persistent disk from which you want to create a snapshot.
- SNAPSHOT_TYPE: The snapshot type, either STANDARD or ARCHIVE. If a snapshot type is not specified, a STANDARD snapshot is created.
Alternatively, to override the snapshot settings and create a snapshot in a custom storage location, make a
POST
request to thesnapshots.insert
method and include thestorageLocations
property in your request:POST https://compute.googleapis.com/compute/v1/projects/DESTINATION_PROJECT_ID/global/snapshots { "name": SNAPSHOT_NAME "sourceDisk": "projects/SOURCE_PROJECT_ID/zones/SOURCE_ZONE/disks/SOURCE_DISK_NAME "snapshotType": SNAPSHOT_TYPE "storageLocations": STORAGE_LOCATION }
Replace the following:
- DESTINATION_PROJECT_ID: The ID of project in which you want to create the snapshot.
- SNAPSHOT_NAME: A name for the snapshot.
- SOURCE_PROJECT_ID: The ID of the source disk project.
- SOURCE_ZONE: The zone of the source disk.
- SOURCE_DISK_NAME: The name of the persistent disk from which you want to create a snapshot.
- SNAPSHOT_TYPE: The snapshot type, either STANDARD or ARCHIVE. If a snapshot type is not specified, a STANDARD snapshot is created.
STORAGE_LOCATION: Optional. The Cloud Storage multi-region or the Cloud Storage region where you want to store your snapshot. You can specify only one storage location.
Use the
storageLocations
parameter only when you want to override the predefined or customized default storage location configured in your snapshot settings.
Go
Go
Before trying this sample, follow the Go setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Go API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
Java
Before trying this sample, follow the Java setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Java API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
Node.js
Before trying this sample, follow the Node.js setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Node.js API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Python
Before trying this sample, follow the Python setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Python API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Create a snapshot of a regional Persistent Disk volume
After you have prepared the disk, you can create a snapshot. When creating a snapshot of a regional persistent disk, you must indicate the region where the disk is located.
Console
- Go to the Create a Snapshot page in the Google Cloud console.
Go to the Create a Snapshot page - Enter a snapshot Name.
Select a Snapshot type. The default is a regular snapshot, which is best for long-term back up and disaster recovery.
Choose Archive snapshot for more cost-efficient data retention.
Optionally, enter a Description of the snapshot.
Under Source disk, select an existing disk from which you want to create a snapshot.
In the Location section, choose your snapshot storage location. The predefined or customized default location defined in your snapshot settings is automatically selected. Optionally, you can override the snapshot settings and store your snapshots in a custom storage location by doing the following:
Choose the type of storage location that you want for your snapshot.
- Choose Multi-regional for higher availability at a higher cost.
- Choose Regional snapshots for more control over the physical location of your data at a lower cost.
In the Select location field, select the specific region or multi-region that you want to use. To use the region or multi-region that is closest to your source disk, select Based on disk's location.
Click Create to create the snapshot.
gcloud
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
Create your snapshot using the storage location policy defined by your snapshot settings (Preview) or using an alternative storage location of your choice. For more information, see Choose your snapshot storage location.
To create a snapshot of a regional Persistent Disk volume in the predefined or customized default location configured in your snapshot settings, use the
gcloud compute snapshots create
command.gcloud compute snapshots create SNAPSHOT_NAME \ --source-disk SOURCE_DISK \ --source-disk-region=SOURCE_DISK_REGION --snapshot-type=SNAPSHOT_TYPE
Alternatively, you can override the snapshot settings and store your snapshots in a custom storage location.
gcloud compute snapshots create SNAPSHOT_NAME \ --source-disk SOURCE_DISK \ --source-disk-region=SOURCE_DISK_REGION --storage-location STORAGE_LOCATION \ --snapshot-type SNAPSHOT_TYPE
Replace the following:
- SNAPSHOT_NAME: A name for the snapshot.
- SOURCE_DISK: The name of the regional Persistent Disk volume from which you want to create a snapshot.
- SOURCE_DISK_REGION: The region of the regional Persistent Disk volume from which you want to create a snapshot.
- SNAPSHOT_TYPE: The snapshot type, either STANDARD or ARCHIVE. If a snapshot type is not specified, a STANDARD snapshot is created.
STORAGE_LOCATION: The Cloud Storage multi-region or the Cloud Storage region where you want to store your snapshot. You can specify only one storage location.
Use the
--storage-location
flag only when you want to override the predefined or customized default storage location configured in your snapshot settings.SNAPSHOT_TYPE: The snapshot type, either STANDARD or ARCHIVE. If a snapshot type is not specified, a STANDARD snapshot is created.
The Google Cloud CLI waits until the operation returns a status of
READY
,FAILED
, or reaches the maximum timeout and returns the last known details of the snapshot.
Terraform
The Terraform provider for Google Cloud doesn't support creating a snapshot of a regional Persistent Disk volume. To track this limitation, see the issue on GitHub.
API
Create your snapshot using the storage location policy defined by your snapshot settings (Preview) or using an alternative storage location of your choice. For more information, see Choose your snapshot storage location.
To create a snapshot in the predefined or customized default location configured in your snapshot settings (Preview), make a
POST
request to thesnapshots.insert
method.POST https://compute.googleapis.com/compute/v1/projects/DESTINATION_PROJECT_ID/global/snapshots { "name": SNAPSHOT_NAME "sourceDisk": "projects/SOURCE_PROJECT_ID/regions/SOURCE_REGION/disks/SOURCE_DISK_NAME "snapshotType": SNAPSHOT_TYPE }
Replace the following:
- DESTINATION_PROJECT_ID: The ID of project in which you want to create the snapshot.
- SNAPSHOT_NAME: A name for the snapshot.
- SOURCE_PROJECT_ID: The ID of the source disk project.
- SOURCE_REGION: The region of the source disk.
- SOURCE_DISK_NAME: The name of the persistent disk from which you want to create a snapshot.
- SNAPSHOT_TYPE: The snapshot type, either STANDARD or ARCHIVE. If a snapshot type is not specified, a STANDARD snapshot is created.
Alternatively, to override the snapshot settings and create a snapshot in a custom storage location, make a
POST
request to thesnapshots.insert
method and include thestorageLocations
property in your request.:POST https://compute.googleapis.com/compute/v1/projects/DESTINATION_PROJECT_ID/global/snapshots { "name": SNAPSHOT_NAME "sourceDisk": "projects/SOURCE_PROJECT_ID/regions/SOURCE_REGION/disks/SOURCE_DISK_NAME "snapshotType": SNAPSHOT_TYPE "storageLocations": STORAGE_LOCATION }
Replace the following:
- DESTINATION_PROJECT_ID: The