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 disks and drives, such as HDDs, SSDs, and non-replicated SSDs, as well as ultra high-speed network storages with three replicas (SSD).
For non-replicated SSDs and ultra high-speed network storages with three replicas (SSD), the snapshot time is not determined.
To create snapshots of local disks residing on dedicated hosts, use Yandex Cloud Backup. This service supports Ubuntu, CentOS, CentOS Stream, and Windows Server.
Preparation steps
A disk snapshot only contains the data that was written to the disk at the time its 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 snapshot data integrity:
-
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. Replace<mount_point>
with the folder where the file system is mounted, e.g.,/mnt/vdc2
. -
Create a snapshot by following the steps below.
-
Unfreeze the file system:
sudo fsfreeze --unfreeze <mount_point>
Where
--unfreeze
is the parameter to unfreeze the file system. Replace<mount_point>
with the folder where the file system is mounted, e.g.,/mnt/vdc2
.
- Stop the VM (see Stopping).
- 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 line with the disk, click
and select Create snapshot. -
Enter a name for the snapshot. The naming requirements are as follows:
- It must be 2 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- It must start with a letter and cannot end with a hyphen.
-
Provide a description for the snapshot, if required.
-
Click Create.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through the --folder-name
or --folder-id
parameter.
-
See the description of the CLI commands for creating snapshots:
yc compute snapshot create --help
-
Select the disk to create a snapshot of. To get a list of disks in the default folder, run this 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********
This will create a disk snapshot named
first-snapshot
and described asmy first snapshot via CLI
.The snapshot naming requirements are as follows:
- It must be 2 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- It must start with a letter and cannot end with a hyphen.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
-
Define 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 relevant provider documentation
. -
Make sure the configuration files are correct.
-
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 correct, the terminal will display a list of resources to create and their parameters. If the configuration contains any errors, Terraform will point them out.
-
-
Deploy the cloud resources.
-
If the configuration does not contain any errors, run this command:
terraform apply
-
Confirm creating 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 a 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.
HDD or SSD snapshots are created asynchronously. The snapshot is created as soon as you run the create command and gets the Creating
status. You can now resume writing data to the disk, as further disk operations will not affect the data in the snapshot.
Once the snapshot creation is complete, the snapshot status will change to Ready
. You can now use the snapshot to create images, disks, and more.
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 these IDs must be unique. For example, if you clone a boot disk and attach it to the same VM, the VM will have two partitions with identical UUIDs. As a result, the VM may boot from the root partition of the wrong disk, rather than the one you specified as the boot disk.
To avoid this, attach the disk to the VM and change all duplicate UUIDs. For more information, see Attaching a disk to a VM.