Creating a disk snapshot
A disk snapshot is a copy of the disk file system at a certain point in time.
Preparation
A disk snapshot only contains the data that was already written to the disk when the snapshot was created. If the disk is attached to a running VM, the cache of the apps and OS will not be included in the snapshot.
To ensure the integrity of the snapshot data:
For Linux systems:
- Stop all disk write operations in applications.
- Run one of the following commands:
sync
to write the OS cache to disk.fsfreeze -f
to freeze the file system. To unfreeze it, run thefsfreeze --unfreeze
command.
For all other systems:
- Stop the VM (see Stop).
- Wait until the VM status changes to
STOPPED
.
Creating a snapshot
To create a disk snapshot:
-
In the management console, select the folder where the disk is located.
-
Select Compute Cloud.
-
On the Virtual machines page, go to the Disks tab.
-
In the line with the disk name, click and select the Create snapshot command.
-
Enter a name for the snapshot.
- Length — from 3 to 63 characters.
- The name may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter. The last character can't be a hyphen.
-
If necessary, enter a description of the snapshot.
-
Click Create snapshot.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
View a description of the CLI create snapshot commands:
$ yc compute snapshot create --help
-
Select the disk to take a snapshot of. To get a list of disks in the default folder, run the command:
yc compute disk list
Result:
+----------------------+--------------+-------------+---------------+--------+----------------------+-------------------------+ | ID | NAME | SIZE | ZONE | STATUS | INSTANCE IDS | DESCRIPTION | +----------------------+--------------+-------------+---------------+--------+----------------------+-------------------------+ | a7lqgbt0bb9s40tifuhc | first-disk | 20401094656 | ru-central1-a | READY | a7lcvu28njbhnkcteb5n | | | a7lv5j5hm1p1hppprga7 | second-disk | 21474836480 | ru-central1-a | READY | | | +----------------------+--------------+-------------+---------------+--------+----------------------+-------------------------+
-
Create a snapshot in the default folder:
$ yc compute snapshot create \ --name first-snapshot \ --description "my first snapshot via CLI" \ --disk-id fhm4aq4hvq5g3nepvt9b
This command creates a disk snapshot with the name
first-snapshot
and descriptionmy first snapshot via CLI
.- Length — from 3 to 63 characters.
- The name may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter. The last character can't be a hyphen.
If you don't have Terraform, install it and configure the Yandex.Cloud provider.
-
Describe the resource parameters in the
yandex_compute_snapshot
configuration file.Example configuration file structure:
resource "yandex_compute_snapshot" "snapshot-1" { name = "disk-snapshot" source_disk_id = "<disk ID>" }
For more information about the resources you can create using Terraform, see the provider documentation.
-
Make sure that the configuration files are correct.
-
In the command line, go to the directory where you created the configuration file.
-
Run the check using the command:
$ terraform plan
If the configuration is described correctly, the terminal displays a list of created resources and their parameters. If there are errors in the configuration, Terraform points them out.
-
-
Deploy the cloud resources.
-
If the configuration doesn't contain any errors, run the command:
$ terraform apply
-
Confirm that you want to create the resources.
Afterwards, all the necessary resources are created in the specified folder. You can check resource availability and their settings in management console.
-
A snapshot is created asynchronously. The snapshot is created with the CREATING
status immediately after the create command is run. From this point on, you can resume writing data to disk, and disk operations will not affect the data in the snapshot.
Once the snapshot has been created, its status changes to READY
. From this point on, you can use the snapshot to create images, populate disks, and so on.
Alert
When creating a snapshot or image in Linux, the UUID and PARTUUID of disk partitions are saved. Linux uses this data when mounting partitions, including the root one, so the IDs must be unique. For example, if you clone a boot disk and attach it to the same VM, two partitions with the same UUIDs appear on the VM. As a result, after starting the VM, the root partition may not be the one you specified as the boot disk.
To avoid this, attach the disk to the VM and change all the duplicate UUIDs. Learn more in the instructions for attaching disks.