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, high-performance SSDs, and non-replicated SSDs. While taking a snapshot, high-performance and non-replicated SSDs are not available for writes. To take snapshots from local disks residing on dedicated hosts, use Yandex Cloud Backup. This service supports Ubuntu, CentOS, CentOS Stream, and Windows Server.
Alert
When creating a snapshot of the SSD IO
or Non-replicated SSD
type, all write operations will be temporarily suspended, and the disk will be read-only. All suspended writes requested on the guest OS side will be completed after the snapshot is created. During the snapshot generation, the guest OS will be waiting for I/O operations to be completed (iowait
status).
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 where the disk is located. -
Select Compute Cloud.
-
In the left-hand panel, select
-
In the line of the disk, click
-
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.
-
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 | 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 name
first-snapshot
and descriptionmy first snapshot via CLI
.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 resource parameters in the
yandex_compute_snapshot
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 resources you can create with Terraform, see the provider documentation
. -
Make sure the configuration files are valid.
-
In the command line, go to the directory 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 configuration 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 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 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.