The Alibaba Cloud snapshot service works with Cloud Assistant to provide the application-consistent snapshot feature. Application-consistent snapshots can be used 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 2019, Windows Server 2016, and Windows Server 2012 R2.
    • Linux: CentOS 7.6 or later, Ubuntu 18.04 or later, and Alibaba Cloud Linux 2.1903 LTS 64-bit.
  • The disks of the ECS instance are enhanced SSDs (ESSDs) and the file systems are ext3, ext4, XFS, or New Technology File System (NTFS). Network file systems or shared file systems are not supported.
  • The Cloud Assistant client is installed on the instance. For more information, see Install the Cloud Assistant client.
    Note By default, the Cloud Assistant client is pre-installed on ECS instances that were 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.
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. This ensures consistency between application system data and database transactions. The application-consistent snapshots can be used 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 APPConsistent:True tag.

The implementation methods of the application-consistent snapshot feature vary based on operating systems.
  • For Windows operating systems, the feature is implemented by using Volume Shadow Copy Service (VSS).
  • For Linux operating systems, the feature is implemented by using custom shell scripts. You must write your own scripts based on your applications. When you use custom scripts, Alibaba Cloud does not take responsibility for application consistency issues.
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. File system-consistent snapshots can be used to prevent operating systems from performing disk checks (chkdsk) and file system consistency checks (fsck).

File system-consistent snapshots are identified by the FsConsistent:True tag.

The implementation methods of the application-consistent snapshot feature vary based on operating systems.
  • For Windows operating systems, if no VSS writers are available, file system-consistent snapshots are created by default.
  • For Linux operating systems, if no application scripts are available, file system-consistent snapshots are created by default.

Procedure

  1. Step 1: Configure a RAM role for the ECS instance

    Before you enable the application-consistent snapshot feature for an instance, you must configure a Resource Access Management (RAM) role for the instance.

  2. Enable the application-consistent snapshot feature based on the operating system of the instance.
  3. Step 3: Check whether application-consistent snapshots are created

    After you request to create application-consistent snapshots, you can go to the Cloud Assistant page in the ECS console to check whether the snapshots are created and go to the Snapshots page in the ECS console to view snapshot details.

Step 1: Configure a RAM role for the ECS instance

  1. Log on to the RAM console by using your Alibaba Cloud account.
  2. 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. RAM role for the application-consistent snapshot feature
  3. Create a permission policy for the application-consistent snapshot feature. For more information, see Create a custom policy.
    Permission policy
    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:
    {
        "Version": "1",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "ecs:DescribeSnapshot*",
                    "ecs:CreateSnapshot*",
                    "ecs:TagResources",
                    "ecs:DescribeDisks"
                ],
                "Resource": [
                    "*"
                ],
                "Condition": {}
            }
        ]
    }
  4. Attach the AppSnapshotPolicy policy to the AppSnapshotRoleName RAM role. For more information, see Grant permissions to a RAM role.
    Grant permissions
  5. Attach the AppSnapshotRoleName RAM role to the ECS instance. For more information, see Attach an instance RAM role.
    Attach the RAM role to the instance

Step 2: Enable the application-consistent snapshot feature for the instance if it is a 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.

  1. Go to the Instances page in the ECS console.
    1. Log on to the ECS console.
    2. In the left-side navigation pane, choose Instances & Images > Instances.
    3. In the top navigation bar, select the region where the ECS instance is located.
  2. Find the instance for which you want to enable the application-consistent snapshot feature and choose More > Disk and Image > Create Snapshot-consistent Group in the Actions column.
  3. In the Create Snapshot-consistent Group dialog box, configure parameters to create a snapshot-consistent group and enable the instant access feature.
  4. In the Create Snapshot-consistent Group dialog box, specify parameters in the Application-consistent Snapshot section.
    Application-consistent Snapshot section
    • If you select Enable Application-consistent Snapshot and Whether Writer is included by default, application-consistent snapshots are created.
    • If you select only Enable Application-consistent Snapshot, file system-consistent snapshots are created.
    Note If the Cloud Assistant plug-in is not installed on your instance, the plug-in is automatically installed on the instance after you select Enable Application-consistent Snapshot.
  5. Click OK.
    After the snapshot-consistent group is created, a message is displayed and indicates the Cloud Assistant command ID and the execution ID, as shown in the following figure. You can check whether application-consistent snapshots are created based on the execution ID. Execution ID

Step 2: Enable the application-consistent snapshot feature for the instance if it is a 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.

  1. Write the application pre-freeze and post-thaw scripts based on the applications deployed on the 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 instance.
    • Application pre-freeze script: Grant have read, write, and execute permissions on the script only to the root user. Set the save path of the script to /tmp/prescript.sh.
    • Application post-thaw script: Grant have read, write, and execute permissions on the script only to the root user. Set the save path of the script to /tmp/postscript.sh.
    Notice If script configurations such as permissions, save path, or file name are invalid, file system-consistent snapshots are created.
  2. Go to the Instances page in the ECS console.
    1. Log on to the ECS console.
    2. In the left-side navigation pane, choose Instances & Images > Instances.
    3. In the top navigation bar, select the region where the ECS instance is located.
  3. Find the instance for which you want to enable the application-consistent snapshot feature and choose More > Disk and Image > Create Snapshot-consistent Group in the Actions column.
  4. In the Create Snapshot-consistent Group dialog box, configure parameters to create a snapshot-consistent group and enable the instant access feature.
  5. In the Create Snapshot-consistent Group dialog box, specify parameters in the Application-consistent Snapshot section.
    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.
    Note If the Cloud Assistant plug-in is not installed on your instance, the plug-in is automatically installed on the instance after you select Enable Application-consistent Snapshot.
  6. Click OK.
    After the snapshot-consistent group is created, a message is displayed and indicates the Cloud Assistant command ID and the execution ID, as shown in the following figure. You can check whether application-consistent snapshots are created based on the execution ID. 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 details of the created snapshot-consistent group and disk snapshots.

  1. On the Cloud Assistant page, check whether application-consistent snapshots are created.
    1. Log on to the ECS console.
    2. In the left-side navigation pane, choose Maintenance & Monitoring > ECS Cloud Assistant.
    3. Click the Command Execution Result tab.
    4. Find the execution ID obtained in the previous step and click it to view the execution results.
      Execution results

      If application-consistent snapshots are created, the return value of ExitCode is 0, and the ID of the snapshot-consistent group is displayed in the command output, as shown in the preceding figure.

      If the return value of ExitCode 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.

  2. On the Snapshots page, view the details of the created snapshot-consistent group and disk snapshots.
    1. In the left-side navigation pane, choose Storage & Snapshots > Snapshots.
    2. Click the Snapshot-consistent Group tab, find the snapshot-consistent group that you created, and then click the ID of the snapshot-consistent group to view its details.
    3. In the Cloud disk snapshot section, click the ID of a disk snapshot.
    4. On the Snapshots tab, check whether the disk snapshots contained in the snapshot-consistent group that you created are application-consistent or file system-consistent snapshots based on their tags.
      • Application-consistent snapshots are identified by the APPConsistent:True tag.Tag of application-consistent snapshots
      • File system-consistent snapshots are identified by the FsConsistent:True tag.Tag of file system-consistent snapshots

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.
Error code (ExitCode) Description
0 The application-consistent snapshot is created.
1 One or more specified conditions are not met. Examples:
  • The disk category is not supported.
  • The snapshot name is invalid.
  • The network connection fails.
  • No RAM role is attached to the instance.
  • The operating system of the instance is not supported.
2 The type or number of the parameters that follow --params is invalid.
3 One of the following errors may occur:
  • No ESSDs are attached to the instance.
  • The RAM role attached to the instance has no permissions to call snapshot-related API operations.
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 single 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 because the previous snapshot is being created and the instant access feature is disabled.
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.