Creating a disk snapshot
A disk snapshot is a copy of the disk file system at a specific point in time.
You can create snapshots of network drives, such as HDDs, SSDs, and non-replicated SSDs, as well as ultra-high performance network storages with three replicas (SSD).
For non-replicated SSDs and ultra-high performance network storages with three replicas (SSD), the snapshot time is not determined.
To take snapshots of local disks residing on dedicated hosts, use Yandex Cloud Backup. This service supports Ubuntu, CentOS, CentOS Stream, and Windows Server.
Setup
A disk snapshot only contains the data that had already been written to the disk when the snapshot was created. If the disk is attached to a running VM, the OS and app cache will not be included in the snapshot.
To ensure the integrity of the snapshot data:
-
Stop all disk write operations in applications.
-
Write the OS cache to the disk:
sync
-
Freeze the file system:
sudo fsfreeze --freeze <mount_point>
Where
--freeze
is the parameter to freeze the file system. Instead of<mount_point>
, specify the folder the file system is connected to, e.g.,/mnt/vdc2
. -
Create a snapshot following the guide below.
-
Unfreeze the file system:
sudo fsfreeze --unfreeze <mount_point>
Where
--unfreeze
is the parameter to unfreeze the file system. Instead of<mount_point>
, specify the folder the file system is connected to, e.g.,/mnt/vdc2
.
- Stop the virtual machine (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 containing the disk. -
Select Compute Cloud.
-
In the left-hand panel, select
Disks. -
In the row with the disk, click
and select Create snapshot. -
Enter a name for the snapshot. The naming requirements are as follows:
- The name must be from 3 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter and the last character cannot be a hyphen.
-
If necessary, enter a description of the snapshot.
-
Click Create.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
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.
-
See the description of the CLI commands to create snapshots:
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 | PLACEMENT GROUP | DESCRIPTION | +----------------------+--------------+-------------+-------------------+--------+----------------------+-----------------+-------------+ | a7lqgbt0bb9s******** | first-disk | 20401094656 | ru-central1-a | READY | a7lcvu28njbh******** | | | | a7lv5j5hm1p1******** | 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 fhm4aq4hvq5g********
As a result, a disk snapshot is created with the
first-snapshot
as the name andmy first snapshot via CLI
as the description.The snapshot naming requirements are as follows:
- The name must be from 3 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter and the last character cannot be a hyphen.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
-
Describe the parameters of the
yandex_compute_snapshot
resource in the configuration file.Here is an example of the 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 with Terraform, see the provider documentation
. -
Make sure the configuration files are correct.
-
In the command line, go to the folder where you created the configuration file.
-
Run a check using this command:
terraform plan
If the configuration is described correctly, the terminal will display a list of created resources and their parameters. If the configuration contains any errors, Terraform will point them out.
-
-
Deploy cloud resources.
-
If the configuration does not contain any errors, run this command:
terraform apply
-
Confirm that you want to create the resources.
All the resources you need will then be created in the specified folder. You can check the new resources and their settings using the management console
. -
- Get the list of disks using the list REST API method for the Disk resource or the DiskService/List gRPC API call.
- Create a snapshot using the create REST API method for the Snapshot resource or the SnapshotService/Create gRPC API call.
An HDD or SSD snapshot is created asynchronously. The snapshot is created as soon as you run the create command and gets the Creating
status. 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 creation is completed, its status will change 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. For more information, see the guide on attaching a disk.