You can create snapshots for a cloud disk to save its data at a specific point of time. The incremental snapshot only records the data change compared to the last snapshot. This process is quick if the data changes a little. Moreover, deleting a snapshot will not affect your use of snapshot data. You can also restore your cloud disks by using any remaining snapshots.
You can create a snapshot for a cloud disk in any state, but the snapshot can only capture the written data rather than data being written by an app or process. Before creating a snapshot, you can choose to suspend all disk I/O operations, or detach the cloud disk and attach it later to create a complete snapshot.
A snapshot can only capture the written data but not cached data in the memory (such as files in the
/run directory on a Linux CVM) of the cloud disk. We recommend that you shut down the instance, or write all memory data to disk and suspend disk I/O operations before creating a snapshot. This can be done at the following two levels.
For database services, we recommend locking all tables in databases as read-only to ensure that the snapshot captures all data. Taking MySQL as an example, the procedure is as follows:
FLUSH TABLES WITH READ LOCKto close all tables and use the global read lock to lock all tables in every database, as shown below:
UNLOCK TABLESto unlock the tables, as shown below:
For better system performance, data is stored in the memory buffer before it is written to the cloud disk at the proper moment. Therefore, the snapshot created for the cloud disk does not contain data stored in the memory buffer and not already written to the cloud disk. As a result, data inconsistency occurs.
To resolve this issue, run the
sync command to forcibly write the data in the file system memory buffer immediately to the cloud disk, and then prevent new data from being written to the cloud disk. If no error message is returned after the command is executed, the data in the memory buffer has been successfully written to the cloud disk, as shown below:
Log in to the CBS console.
Click Create a snapshot on the right of the target cloud disk.
In the Create a snapshot pop-up window, enter the snapshot name and click OK.
You can use the
CreateSnapshot API to create a snapshot. For more information, see CreateSnapshot.