All Products
Search
Document Center

Elastic Compute Service:How snapshots work

Last Updated:Dec 21, 2023

Snapshots are point-in-time copies of disks. You can use a snapshot to restore a disk to the point in time at which the snapshot was created for the disk. This topic describes how to create and delete snapshots, how to calculate the snapshot size, and how the snapshot size is related to the disk size.

Create snapshots

You can manually or automatically create snapshots for disks based on your business requirements. For more information, see Create a snapshot for a disk or Create an automatic snapshot policy.

Description

Snapshots are classified into full snapshots and incremental snapshots. The first snapshot that you create for a disk is a full snapshot. The snapshot contains all the data blocks that were written to the disk at the time of snapshot creation, excluding empty data blocks. Subsequent snapshots that you create for the disk are incremental snapshots and contain only data blocks that have changed since the previous snapshot. The metadata of both full snapshots and incremental snapshots includes the information of all data blocks. When you roll back a disk by using a snapshot of the disk, you can restore all data from the moment when the snapshot was created to the disk.

Note

After a disk is initialized, it is divided into multiple data blocks based on logical block addresses (LBAs). These data blocks are the minimum granularity of data backup for snapshots. When data is written to the data blocks, every changed data block is marked to be copied in the next snapshot. Data that is written to and modified on the disk do not affect the created snapshots. Snapshots do not affect the original disk data.

Created snapshots are stored in Object Storage Service (OSS).

  • In regions where OSS support zone-redundant storage (ZRS), your snapshot data is stored in ZRS buckets by default to maximize data redundancy.

  • In regions where OSS does not support ZRS, your snapshot data is stored in locally redundant storage (LRS) buckets. If your business requires high availability, we recommend that you copy snapshots to further back up data.

  • For data security purposes, you cannot select the OSS buckets that you create to store snapshot data.

For more information, see Overview of storage redundancy and Create a ZRS bucket.

After you use a snapshot to create or roll back a disk, the data blocks that are contained in the snapshot start to be loaded from OSS to the disk. If you access snapshot data that has not been loaded, the system immediately loads the requested data from OSS to the disk. Minutes or hours are required to complete the loading process. The amount of time required varies based on the size of the snapshot. Before all the data blocks in the snapshot are loaded to the disk, the read latency of the disk increases. When all the data blocks in the snapshot are loaded to the disk, the read latency of the disk returns to the normal level.

Example

Assume that data is written to a disk on an Elastic Compute Service (ECS) instance at 10:00:00 and 11:00:00. The following section describes how snapshots are created for the disk:

  1. At 9:00:00, the disk contains data blocks A, B, and C, and the first snapshot (Snapshot 1) is created for the disk. Data blocks A, B and C are all backed up in Snapshot 1. Snapshot 1 is a full snapshot that backs up all data on the disk.

  2. Data continues to be written to the disk. Data block A is changed to A1, data block B is changed to B1, and data block D is added. The second snapshot (Snapshot 2) is created at 10:00:00 for the disk. Snapshot 2 is an incremental snapshot that backs up only the changed data blocks A1, B1, and D. The metadata of Snapshot 2 includes the information of all data blocks A1, B1, C, and D of the disk. Data block C is derived from Snapshot 1.

  3. Data continues to be written to the disk. Data block C is changed to C1 and data block E is added. The third snapshot (Snapshot 3) is created at 11:00:00. Snapshot 3 is an incremental snapshot that backs up only the changed data blocks C1 and E. The metadata of Snapshot 3 includes the information of all data blocks A1, B1, C1, D, and E of the disk. The data blocks A1, B1, and D are derived from Snapshot 2.

  4. The preceding processes are repeated.

image

Delete snapshots

If you want to free up storage space or if the maximum number of snapshots has been reached, you can delete snapshots that are no longer needed. For information about how to delete a snapshot, see Delete a snapshot.

Note

Each disk can have up to 256 manual snapshots and up to 1,000 automatic snapshots. For more information, see the Snapshot limits section in the "Limits" topic.

Description

In contrast to creating a snapshot, when you delete a snapshot, you need to free up storage space based on the data blocks contained in the snapshot and the relationship between the data blocks. When the first snapshot of a disk is deleted, the first incremental snapshot inherits the attributes of the deleted snapshot to become a full snapshot. If the disk has only the full snapshot that is deleted, the next snapshot to be created for the disk is a full snapshot that backs up all data blocks written since the disk was created.

Example

Assume that Snapshot 1, Snapshot 2, and Snapshot 3 are created for a disk on an ECS instance. The following section describes the data blocks that are contained in each snapshot:

  • Snapshot 1: contains data blocks A, B, and C.

  • Snapshot 2: contains data blocks A1 (changed from data block A), B1 (changed from data block B), C (unchanged), and D (new data block). Data block C is derived from Snapshot 1.

  • Snapshot 3: contains data block A1 (unchanged), B1 (unchanged), C1 (changed from data block C), D (unchanged), and E (new data block). Data blocks A1, B1, and D are derived from Snapshot 2.

The following section describes how the snapshots are deleted:

  1. Assume that Snapshot 1 is deleted at 14:00:00. Data blocks A and B contained in Snapshot 1 are not referenced and are directly deleted. Data block C is retained because it is referenced by Snapshot 2. In this case, Snapshot 2 becomes a full snapshot and contains data blocks A1, B1, C, and D. Snapshot 3 is still an incremental snapshot.

  2. Snapshot 2 is deleted at 15:00:00. Data block C contained in Snapshot 2 is not referenced and is directly deleted. Data blocks A1, B1, and D are referenced by Snapshot 3 and are retained. In this case, Snapshot 3 becomes a full snapshot and contains data blocks A1, B1, C1, D, and E.

  3. Snapshot 3 is deleted at 16:00:00. In this case, all data blocks in Snapshot 3 are not referenced and are deleted.

image

Calculate the snapshot size

Description

The total snapshot size of a disk is calculated at the granularity of snapshot chains. A snapshot chain is a chain of all the snapshots created for a disk. The amount of storage space occupied by the data blocks of all snapshots of the disk is calculated. The following section describes the concepts involved in the snapshot size:

  • Full snapshot size: the amount of the storage space occupied by all data blocks in a single snapshot.

  • Incremental snapshot size: the amount of storage space occupied by the data blocks in a snapshot that have changed since the previous snapshot in the same snapshot chain.

  • Total snapshot size: the sum of the size of the first snapshot (full snapshot) and the size of all subsequent incremental snapshots.

    Note

    Snapshots are not stored on disks and do not consume disk space. You are charged region-specific snapshot storage fees based on the size of the snapshots that are stored in each region. For more information, see Snapshots.

You can view the size of snapshots by snapshot chain in the ECS console. For more information, see the View the snapshot size of a disk based on the snapshot chain of the disk section in the "View the snapshot size" topic.

Example

Assume that data is written to a disk on an ECS instance at 10:00:00 and 11:00:00. The following example describes how to calculate the snapshot size of the disk:

  1. Assume that the disk contains data blocks A (2 MB), B(2 MB), and C (2 MB). Snapshot 1 is created at 9:00:00 and backs up data blocks A, B, and C. Snapshot 1 is a full snapshot.

    Snapshot 1 size = Data block A size + Data block B size + Data block C size = 6 MB

  2. Data blocks A1 (2 MB), B1 (2 MB), and D (2 MB) are written to the disk. Snapshot 2 is created at 10:00:00 and backs up only the data blocks A1, B1, and D that have changed since Snapshot 1 was created. Snapshot 2 is an incremental snapshot.

    Snapshot 2 size = Data block A1 size + Data block B1 size + Data block D size = 6 MB

  3. Data blocks C1 (2 MB) and E (2 MB) are written to the disk. Snapshot 3 is created at 11:00: 00 and backs up only data blocks C1 and E that have changed since Snapshot 2 was created. Snapshot 3 is an incremental snapshot.

    Snapshot 3 size = Data block C1 size + Data block E size = 4 MB

  4. Total snapshot size = Snapshot 1 size + Snapshot 2 size + Snapshot 3 size = 16 MB

image

Relationship between the snapshot size and disk size

The size of a single snapshot of a disk does not exceed the disk size. As the number of snapshots increases, the disk size may be smaller than the total size of all snapshots.

Assume that you create a 40-GB disk, write 20 GB of data to the disk, and then create a snapshot for the disk. The size of the snapshot is 20 GB. Assume that you continue to write 10 GB of data to the disk and then create another snapshot for the disk. The disk size is still 40 GB and the total size of snapshots is 30 GB. The preceding processes are repeated. You can use snapshot chains to view the snapshot size. For more information, see the View the snapshot size of a disk based on the snapshot chain of the disk section in the "View the snapshot size" topic.

In the following figure, ① is the disk size and ② is the size of all snapshots of the disk.快照容量和云盘容量

Difference between the snapshot size and system value

  • The snapshot size is calculated by using data blocks that have fixed sizes as the minimum granularity of data backup for snapshots.

  • When you delete a file on a disk, the disk capacity displayed in the operating system decreases. For files systems of the operating system, when you delete a file, the file is marked as Deleted and data of the file is not physically deleted. For disks, file deletion is a write operation, which does not reduce the actual amount of disk space occupied by data. If a snapshot is created at this time, the snapshot contains the data blocks that correspond to the deleted file. Snapshots do not contain the data blocks that correspond to deleted files only if the files are physically deleted from the file systems of the operating system. To have a better understanding, you can learn about the TRIM mechanism of file systems.

  • Even if you do not write data to a system disk, the snapshot size may still increase. When an operating system is running, system files are generated and written to disks and backed up in snapshots.

  • The size of a snapshot may be slightly larger than the size of data that is written to the disk. This is because some metadata of file systems occupies disk space. The data blocks of the snapshot contain metadata and the data written by you. For example, if you create only 1 MB of text files on a disk, the size of the data backed up by snapshots is slightly larger than the size of the text files due to the presence of file system metadata. The snapshot size is greater than 1 MB.