A snapshot is a backup of a disk at one or more points in time. 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.

How are snapshots created

You can manually create snapshots or configure snapshots to be automatically created for a disk as needed. For more information, see Create a snapshot of a disk or Create an automatic snapshot policy.

Description

Snapshots are classified into full snapshots and incremental snapshots. The first snapshot of a disk is a full snapshot that does not contain empty data blocks. Subsequent snapshots are incremental snapshots that store 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, you can restore all disk data to the point in time at which the snapshot was created.
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 written to and modified in the disk do not affect the created snapshots. Snapshots do not affect the original disk data.

Example

Assume that data is written to a disk of 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.
Relationship between snapshots and disks

How are snapshots deleted

When you want to free up space or when the maximum number of snapshots has been reached, you can delete snapshots that are no longer needed. For more information, 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

In contrast to creating a snapshot, when you delete a snapshot, you must free up 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 this deleted snapshot to become a full snapshot. If the disk has only the full snapshot that is deleted, the first snapshot to be created for the disk later 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 of an ECS instance. The following section describes the data blocks 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 disk 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.
How are snapshots deleted

How is the snapshot size calculated

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 data blocks that are contained in the current snapshot and have been 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 View the snapshot size of a disk based on its snapshot chain.

Example

Assume that a disk of an ECS instance has new data written 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
Snapshot size

Relationship between 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 and write 20 GB of data to the disk for the first time. In this case, the size of the created snapshots is 20 GB. Then, 10 GB of data is written to 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 View the snapshot size of a disk based on its snapshot chain.

As shown in the following figure, ① is the disk size and ② is the size of all snapshots created for the disk. Snapshot size and disk size

Difference between snapshot size and system size

  • 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 in a disk, the displayed capacity of the disk in the operating system is reduced. 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 corresponding to the deleted file. Snapshots do not contain the data blocks corresponding to deleted files only if the files are physically deleted from the file systems of the operating system. For more information, you can learn about the TRIM mechanism of file systems.
  • If you do not actively 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 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 in 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.