All Products
Search
Document Center

Elastic Compute Service:How snapshots work

Last Updated:Mar 20, 2024

Snapshots are point-in-time backups of disks. You can use a snapshot of a disk to restore disk data to the point in time when the snapshot was created. This topic describes how to create and delete snapshots and calculate the snapshot size. This topic also describes the relationship between the snapshot size and 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 data blocks that were written to the disk when the snapshot was created, except empty data blocks. Subsequent snapshots that you create for the disk are incremental snapshots and contain only data blocks that changed since the previous snapshot. The metadata of full and incremental snapshots includes information about all data blocks. When you roll back a disk by using a snapshot of the disk, you can restore all data of the disk to the point in time when the snapshot was created.

Note

After you initialize a disk, the disk is divided into data blocks based on logical block addresses (LBAs). The data blocks are the minimum granularity for data backup in snapshots. When data is written to the data blocks, every changed data block is labeled for copying to 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).

  • By default, snapshot data is stored in zone-redundant storage (ZRS) buckets in regions where OSS supports ZRS to maximize data redundancy.

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

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

For information about the regions where OSS supports ZRS, 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 are loaded from OSS to the disk. If you access the snapshot data that has not been loaded, the system immediately loads the snapshot data from OSS to the disk. The amount of time required to complete the loading process varies based on the size of the snapshot and could be minutes or hours. Before all data blocks in the snapshot are loaded to the disk, the read latency of the disk increases. When all 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) for the disk is created at 10:00:00. Snapshot 2 is an incremental snapshot that backs up only the changed data blocks A1, B1, and D. The metadata of Snapshot 2 includes information about 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. 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 the maximum number of snapshots is 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 1,000 automatic snapshots. For more information, see the Snapshot limits section in the "Limits" topic.

Description

Compared with creating a snapshot, you must free up storage space based on the data blocks contained in the snapshot and the relationship between the data blocks when you delete a snapshot. When you delete the first snapshot of a disk, 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 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 unreferenced and 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 remains as an incremental snapshot.

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

  3. Lastly, Snapshot 3 is deleted at 16:00:00. In this case, all data blocks in Snapshot 3 are unreferenced and 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 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 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 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 section 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.

    Size of Snapshot 1 = Size of data block A + Size of data block B + Size of data block C = 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 data blocks A1, B1, and D that changed since Snapshot 1. Snapshot 2 is an incremental snapshot.

    Size of Snapshot 2 = Size of data block A1 + Size of data block B1 + Size of data block D = 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 changed since Snapshot 2. Snapshot 3 is an incremental snapshot.

    Size of Snapshot 3 = Size of data block C1 + Size of data block E = 4 MB

  4. Total snapshot size = Size of Snapshot 1 + Size of Snapshot 2 + Size of Snapshot 3 = 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. This process is 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 the system value

  • The snapshot size is calculated by using fixed-sized data blocks as the minimum granularity for data backup in snapshots.

  • When you delete a file from a disk, the used disk capacity that is displayed in the operating system decreases. When you delete a file from the file systems of the operating system, the file is labeled as Deleted, but the data of the file is not physically deleted. File deletion on disks is a write operation, which does not reduce the actual amount of disk space occupied by data. If a snapshot is created during file deletion, the snapshot contains the data blocks that correspond to the deleted file. If files are physically deleted from the file systems of the operating system, snapshots do not contain the data blocks of the deleted files. For more information, view the documentation of the TRIM mechanism of file systems.

  • The snapshot size may still increase even if you do not write data to a system disk. 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 because specific metadata of file systems occupies disk space. The data blocks of the snapshot contain metadata and the written data. 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 file system metadata. The snapshot size is greater than 1 MB.