上QQ阅读APP看书,第一时间看更新
How to snapshot a disk
Snapshots are used to back up persistent disks. They are different from backup disk images since they are created to be used periodically. If we create subsequent snapshots of persistent disk, only the first snapshot will back up the entire data of disk, while the other ones will only have reference to prior snapshots for the duplicate data and will contain updated data or newly added data with logs. This reduces total storage to be used and hence reduces the billing amount. To create a persistent disk snapshot, follow these steps:
- Use the gcloud compute disks snapshot command and provide a disk name as an argument:
gcloud compute disks snapshot sda
- It returns a status flag result as READY or FAILED. To verify the snapshot creation, use the following:
gcloud compute snapshots list
- To restore data from the created snapshot, create a persistent disk larger than the size of the snapshot. Do this from the snapshot itself and make sure you are not doing it from the root directory:
gcloud compute disks create sdb --source-snapshot=test-instance-snapshot --size=600GB
- Attach this persistent disk to an instance:
gcloud compute instances attach-disk test-instance01 --disk=sdb
- The preceding command is useful when snapshot and restoration disks are of the same type. For different types of disks, use a type argument and provide the disk type.
- Finally, to delete the snapshot, use the following command:
gcloud compute snapshots delete test-instance-snapshot