Back up your disks regularly to ensure that your snapshot data is relatively current, and to reduce the risk of unexpected data loss when carrying out data backup and recovery operations.
Create snapshots
Create snapshots to periodically back up data from your persistent disks.
Before you begin
Ensure that a user with the Backup Repository Admin role created the following items:
- A single VM backup repository for disk snapshots.
- A VM backup plan
with the
disk-snapshot-bpt
name.
To get the permissions that you need to create a snapshot, ask your Project IAM Admin to grant you the following roles:
- Project VM Admin (
project-vm-admin
) - Backup Creator: (
backup-creator
) - Project Viewer: (
project-viewer
)
Create a snapshot
Create a snapshot using either the GDC console or the API.
Console
- Sign in to the GDC console.
- In the navigation menu, click Virtual Machines > Snapshots.
- Select a project.
- Click Create snapshot.
- In the Source disk field, select the disk that you want to create the snapshot from.
- Enter the Snapshot name.
- Click Create.
API
Issue a VirtualMachineBackupRequest
to initiate a snapshot:
apiVersion: virtualmachine.gdc.goog/v1
kind: VirtualMachineBackupRequest
metadata:
name: BACKUP_REQUEST_NAME
namespace: PROJECT_NAME
spec:
virtualMachineBackupPlanTemplate: VM_BACKUP_PLAN
virtualMachineDisk: VM_DISK
virtualMachineBackupName: VM_BACKUP_NAME
Replace the following:
BACKUP_REQUEST_NAME
: the name to give the backup request that is being initiated.PROJECT_NAME
: the name of the GDC project.VM_BACKUP_PLAN
: the name of theVirtualMachineBackupPlanTemplate
to use for configuration of the snapshot. For snapshots, this value isdisk-snapshot-bpt
.VM_DISK
: the name of the disk to snapshot.VM_BACKUP_NAME
: the name of the snapshot to create.
View snapshots
View snapshots and their details by using the Google Cloud console or kubectl
.
Console
- Sign in to the GDC console.
- In the navigation menu, click Virtual Machines > Snapshots.
- Select a project.
- In the list of snapshots, click the snapshot name to view its details.
kubectl
View a snapshot by listing the snapshots and viewing their details.
List the existing snapshots:
kubectl get virtualmachinebackups.virtualmachine.gdc.goog -n PROJECT_NAME
Replace
PROJECT_NAME
with the name of the project.In the list, find the snapshot that you want to view.
View the snapshot details:
kubectl describe virtualmachinebackup.virtualmachine.gdc.goog VM_BACKUP_NAME -n PROJECT_NAME
Replace the following:
VM_BACKUP_NAME
: the name of the snapshot.PROJECT_NAME
: the name of the project.
Delete a snapshot
Delete snapshots by using the Google Cloud console or kubectl
. Disks created from
snapshots are not affected when the underlying snapshot is deleted.
Console
- Sign in to the GDC console.
- In the navigation menu, click Virtual Machines > Snapshots.
- Select a project.
- In the list of snapshots, find the snapshot to delete and click Delete.
- Click Confirm.
kubectl
Delete a snapshot using kubectl
.
List the existing snapshots:
kubectl get virtualmachinebackups.virtualmachine.gdc.goog -n PROJECT_NAME
Replace
PROJECT_NAME
with the name of the project.In the list, find the snapshot that you want to delete.
Issue a
VirtualMachineDeleteBackupRequest
to delete the snapshot:apiVersion: virtualmachine.gdc.goog/v1 kind: VirtualMachineDeleteBackupRequest metadata: name: DELETE_BACKUP_REQUEST_NAME namespace: PROJECT_NAME spec: virtualMachineBackupRef: name: VM_BACKUP_NAME
Replace the following:
DELETE_BACKUP_REQUEST_NAME
: name to give the delete backup request that is being initiated.VM_BACKUP_NAME
: the name of the snapshot to delete.PROJECT_NAME
: the name of the project.
What's next
You can restore a VM disk from an image disk snapshot. For more information, see Restore a VM from a snapshot.