With Cloud Block Storage (CBS), you can create snapshots and save cloud disk data at a specific point of time. Tencent Cloud creates snapshots in an incremental manner, which means it only creates data that has changed since the last snapshot. If the size of the changed data is small, snapshot creation is quick. Because snapshots are incrementally created, deleting snapshots does not affect the use of any snapshot data. Therefore, you can restore your cloud disks by using any remaining snapshots.
You can create a snapshot of a cloud disk in any state, but the snapshot will only save the data that is already written to the cloud disk at the current moment. When any app or process is writing data, the data might not yet have been saved to the snapshot that is being created. If this is the case, you can choose to suspend all writes and create the snapshot as soon as possible, or unmount the cloud disk and mount it later to ensure the integrity of snapshot data.
A snapshot only contains data that is already written to the disk (but not data that is in the memory and not yet written to the disk) at the moment the snapshot is created. We strongly recommend that you shut down the instance or ensure that the memory data is already written to the cloud disk and then suspend all writes to the cloud disk before creating the snapshot. For this purpose, you need to do the following.
For database services, we recommend that you lock all tables in databases as read-only to avoid a situation where new data is written to the cloud disk and cannot be captured by the snapshot that is being created. By using MySQL as an example, the procedure is as follows:
FLUSH TABLES WITH READ LOCKto close all opened 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, when appropriate. Therefore, when you create the snapshot, the data stored in the memory buffer and not already written to the cloud disk will not be written to or recovered from the snapshot. 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:
You can use the CreateSnapshot API to create a snapshot. For more information, see CreateSnapshot.