The Alibaba Cloud snapshot service works with Cloud Assistant to provide the application-consistent snapshot feature. You can use application-consistent snapshots for data rollbacks to prevent logs from being rolled back when applications such as databases start and to ensure that applications start in a consistent state.
Prerequisites
The Elastic Compute Service (ECS) instance based on which you want to create application-consistent snapshots runs one of the following operating systems:
Windows: Windows Server 2022, Windows Server 2019, Windows Server 2016, or Windows Server 2012 R2.
Linux: CentOS 7.6 or later, Ubuntu 18.04 or later, or Alibaba Cloud Linux 2.
The disks of the ECS instance are enhanced SSDs (ESSDs) at the performance levels 0, 1, 2, and 3 (PL0, PL1, PL2, and PL3 ESSDs) or ESSD AutoPL disks, and the file systems are ext3, ext4, XFS, or New Technology File System (NTFS). Network file systems or shared file systems are not supported.
Cloud Assistant Agent is installed on the ECS instance. For more information, see Install Cloud Assistant Agent.
NoteBy default, Cloud Assistant Agent is pre-installed on ECS instances that are created from public images after December 1, 2017.
Background information
By default, the snapshots that you create are crash-consistent. If you enable the application-consistent snapshot feature when you create a snapshot, the system creates an application-consistent snapshot or a file system-consistent snapshot based on the actual scenario. The following table describes the application-consistent and file system-consistent snapshots.
Snapshot type | Description | Implementation |
Application-consistent snapshot | Application-consistent snapshots back up data stored in memory and database transactions in progress when the snapshots are created to ensure consistency between application system data and database transactions. You can use application-consistent snapshots for data rollbacks to prevent data corruption and data loss and to ensure that logs are not rolled back when databases start and that applications start in a consistent state. Application-consistent snapshots are identified by the | The implementation methods of the application-consistent snapshot feature vary based on operating systems.
|
File system-consistent snapshot | If the application-consistent snapshot feature is enabled but relevant conditions are not met, file system-consistent snapshots are created. File system-consistent snapshots synchronize the memory and disk information of file systems when the snapshots are created and freeze write operations on file systems to ensure file system consistency. You can use file system-consistent snapshots to prevent operating systems from performing disk checks (chkdsk) and file system consistency checks (fsck). File system-consistent snapshots are identified by the | The implementation methods of the file system-consistent snapshot feature vary based on operating systems.
|
Procedure
Step 1: Configure a RAM role for an ECS instance
Log on to the Resource Access Management (RAM) console with an Alibaba Cloud account.
Create a RAM role for the application-consistent snapshot feature. For more information, see Create a RAM role for a trusted Alibaba Cloud service.
The following figure shows how to create the AppSnapshotRoleName RAM role.
Create a permission policy for the application-consistent snapshot feature. For more information, see Create custom policies.
Create the AppSnapshotPolicy policy to grant permissions to query snapshot details, create snapshots, configure tags, and query disk details. You can use the following policy content:
{ "Version": "1", "Statement": [ { "Effect": "Allow", "Action": [ "ecs:DescribeSnapshot*", "ecs:CreateSnapshot*", "ecs:TagResources", "ecs:DescribeDisks" ], "Resource": [ "*" ], "Condition": {} } ] }
Attach the AppSnapshotPolicy policy to the AppSnapshotRoleName RAM role. For more information, see Grant permissions to a RAM role.
Attach the AppSnapshotRoleName RAM role to the ECS instance. For more information, see Attach an instance RAM role to an ECS instance.
Step 2: Enable the application-consistent snapshot feature for the ECS instance
Linux instance
For Linux instances, you must configure shell scripts (application pre-freeze and post-thaw scripts) based on the applications deployed on the instances to implement application consistency. This section describes how to enable the application-consistent snapshot feature for a Linux instance.
Write the application pre-freeze and post-thaw scripts based on the applications deployed on the Linux instance and upload the scripts to the instance.
You can use FTP or Cloud Assistant to upload the application pre-freeze and post-thaw scripts to the Linux instance.
Application pre-freeze script: Grant read, write, and execute permissions on the script only to the root user. Set the storage path of the script to /tmp/prescript.sh.
Application post-thaw script: Grant read, write, and execute permissions on the script only to the root user. Set the storage path of the script to /tmp/postscript.sh.
ImportantIf script configurations such as permissions, storage path, or file name are invalid, file system-consistent snapshots are created.
Go to the instance list page in the ECS console.
Log on to the ECS console.
In the left-side navigation pane, choose .
In the top navigation bar, select the region where the ECS instance is located.
Find the instance for which you want to enable the application-consistent snapshot feature and choose
in the Actions column.In the Create Snapshot-consistent Group dialog box, configure the parameters for the snapshot-consistent group.
Select the disks for which you want to create the snapshot-consistent group and configure other snapshot parameters.
Configure the parameters in the Application-consistent Snapshot section.
If you select Enable Application-consistent Snapshot and Enable File System Freeze and Thaw and configure valid scripts, application-consistent snapshots are created.
If you select Enable Application-consistent Snapshot and Enable File System Freeze and Thaw but do not configure valid scripts, file system-consistent snapshots are created.
NoteIf the Cloud Assistant plug-in is not installed on your Linux instance, the plug-in is automatically installed on the instance after you select Enable Application-consistent Snapshot.
Click OK.
After you create the snapshot-consistent group, a message indicating the Cloud Assistant command ID and the execution ID (InvokeId) is displayed, as shown in the following figure. You can check whether application-consistent snapshots are created based on the execution ID.
Windows instance
For Windows instances, you can use VSS to implement application consistency. This section describes how to enable the application-consistent snapshot feature for a Windows instance.
Go to the instance list page in the ECS console.
Log on to the ECS console.
In the left-side navigation pane, choose .
In the top navigation bar, select the region where the ECS instance is located.
Find the instance for which you want to enable the application-consistent snapshot feature and choose
in the Actions column.In the Create Snapshot-consistent Group dialog box, configure the parameters for the snapshot-consistent group.
Select the disks for which you want to create the snapshot-consistent group and configure other snapshot parameters.
Configure the parameters in the Application-consistent Snapshot section.
If you select Enable Application-consistent Snapshot and Contain Writers by Default, application-consistent snapshots are created.
If you select only Enable Application-consistent Snapshot, file system-consistent snapshots are created.
NoteIf the Cloud Assistant plug-in is not installed on your Windows instance, the plug-in is automatically installed on the instance after you select Enable Application-consistent Snapshot.
Click OK.
After you create the snapshot-consistent group, a message indicating the Cloud Assistant command ID and the execution ID (InvokeId) is displayed, as shown in the following figure. You can check whether application-consistent snapshots are created based on the execution ID.
Step 3: Check whether application-consistent snapshots are created
After you perform the preceding steps, you can go to the Cloud Assistant page in the ECS console to check whether application-consistent snapshots are created and go to the Snapshots page in the ECS console to view the details of the created snapshot-consistent group and disk snapshots.
On the Cloud Assistant page, check whether application-consistent snapshots are created.
Log on to the ECS console.
In the left-side navigation pane, choose .
Click the Command Execution Result tab.
Find the execution ID obtained in the previous step in the Task ID column and click the execution ID to view the execution results.
If application-consistent snapshots are created, the return value of the ExitCode parameter is
0
and the ID of the snapshot-consistent group is displayed in the command output, as shown in the preceding figure.NoteIf the return value of the ExitCode parameter is not
0
, an error has occurred. Troubleshoot the error based on the returned error code in the ExitCode column. For more information, see Error codes.
On the Snapshots page, view the details of the created snapshot-consistent group and disk snapshots.
In the left-side navigation pane, choose .
Click the Snapshot-consistent Groups tab, find the snapshot-consistent group that you created, and then click the ID of the snapshot-consistent group to view the details of the snapshot-consistent group.
In the Snapshot Information section, click the ID of a disk snapshot.
In the Basic Information section, check whether the disk snapshot is an application-consistent or file system-consistent snapshot based on the tags of the snapshot.
Application-consistent snapshots are identified by the
APPConsistent:True
tag.File system-consistent snapshots are identified by the
FsConsistent:True
tag.
Error codes
After you perform the preceding operations to create an application-consistent snapshot, an error code (ExitCode) may be returned. If an application-consistent snapshot cannot be created, you can troubleshoot the error based on the returned error code. The following table describes the common error codes.
Error code (ExitCode) | Description |
0 | The application-consistent snapshot is created. |
1 | One or more conditions are not met. Examples:
|
2 | The type or number of the parameters that follow the |
3 | One of the following errors may occur:
|
4 | The snapshot-consistent group cannot be created. |
5 | The snapshot-consistent group is not in the expected state. |
6 | The request to create the snapshot-consistent group timed out. |
7 | A disk snapshot in the snapshot-consistent group is not in the expected state. |
8 | Tags cannot be added to the snapshot. |
9 | The application pre-freeze script cannot be executed. |
10 | The application post-thaw script cannot be executed. |
11 | The I/O of the file systems cannot be frozen. |
12 | The I/O of the file systems cannot be thawed. |
13 | No RAM role is attached to the instance. |
14 | The number of snapshots exceeds the upper limit. |
15 | The snapshot is not in the expected state. |
16 | The snapshot cannot be created when the instant access feature is disabled because the previous snapshot is being created. |
255 | An unknown error has occurred. |
References
For information about how to use ECS SDK for Go to create application-consistent snapshots, see Create application-consistent snapshots by using ECS SDK for Go.