Disks can be rolled back based on application-consistent snapshots without corruption or loss of data. This ensures that applications such as SQL Server start in a consistent state and prevents log rollbacks on database startup. This topic describes how to create application-consistent snapshots for an Elastic Compute Service (ECS) Windows instance and how to check whether the snapshots can be used as expected to restore data. SQL Server is used in the examples.
Usage notes
An ECS instance that runs Windows Server 2022, Windows Server 2019, Windows Server 2016, or Windows Server 2012 R2 is created.
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.
You are already familiar with how to install and use Windows SQL Server. For more information, see the official Windows Server documentation.
Background information
For more information about application-consistent snapshots, see Create application-consistent snapshots in the ECS console.
The following table describes the configurations of the verification environment used in this topic.
Configuration | Description |
Instance type | ecs.g7.2xlarge |
Operating system | Windows Server 2019 Datacenter 64-bit (Simplified Chinese) |
Disk | Enhanced SSDs (ESSDs) |
Application | Microsoft SQL Server 2019 64-bit |
Procedure
Step 1: Prepare a database verification environment
Before you perform the following operations, make sure that Microsoft SQL Server 2019 64-bit is installed on the ECS instance. This section describes how to prepare a database verification environment on the instance.
Connect to the ECS instance.
For more information, see Connection method overview.
Connect to SQL Server.
In the lower-left corner, click the Search icon and enter
ssms
in the search box.Click Microsoft SQL Server Management Studio 18.
In the Connect to Server dialog box, configure the server connection information and click Connect.
In Microsoft SQL Server Management Studio 18, create a test database named AdventureWorks.
Click New Query.
In the query window that appears, enter the following SQL statement:
CREATE DATABASE AdventureWorks;
Right-click the query window and select Execute.
In Microsoft SQL Server Management Studio 18, create a test table named PointInTime.
Click New Query.
In the query window that appears, enter the following SQL statements:
USE AdventureWorks GO IF NOT EXISTS (SELECT name FROM sysobjects WHERE name = 'PointInTime' AND TYPE ='U') CREATE TABLE PointInTime (PIT datetime) WHILE ( 1 = 1 ) BEGIN INSERT PointInTime SELECT GETDATE() WAITFOR DELAY '00:00:001' END
Right-click the query window and select Execute.
In the left-side directory tree, view the created database and table.
Step 2: Attach a Resource Access Management (RAM) role to the instance
Before you enable the application-consistent snapshot feature for an ECS instance, you must configure the required RAM role to the instance.
Step 3: Create application-consistent snapshots in the ECS console
This section describes how to create application-consistent snapshots for a Windows instance on which a SQL Server database resides in the ECS console.
Go to the Instances 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 based on which you want to create a snapshot-consistent group and choose
in the Actions column.Configure the parameters in the Create Snapshot-consistent Group dialog box.
Select the ESSDs for which you want to create snapshots and configure other snapshot parameters.
Select Enable Application-consistent Snapshot and Whether Writer is included by default.
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.
Step 4: Check whether application-consistent snapshots are created
This section describes how to check whether application-consistent snapshots are created and how to check whether insert operations are suspended for the SQL Server database.
On the Cloud Assistant page, view the command execution results.
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 and click it to view the execution results.
If application-consistent snapshots are created, the return value of ExitCode is
0
and the IDs of the created application-consistent snapshots and snapshot-consistent group are displayed in the command output, as shown in the preceding figure.NoteIf 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.
In the command output, view the actions and information involved in the procedure to create the snapshot-consistent group.
Check consistency components. If consistency components do not exist, they are automatically installed.
Automatically recognize and load logical volumes.
Automatically add the corresponding SQL Server database.
The time when snapshots were frozen is
2021-08-05 16:42:59
.
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 group ID to view the details of the snapshot-consistent group.
In the Cloud disk snapshot section, click the ID of a disk snapshot.
On the Snapshots tab, check based on tags whether application-consistent snapshots are created for the disks on the ECS instance.
If application-consistent snapshots are created, the
APPConsistent:True
tag is displayed in the Tag column corresponding to the snapshots, as shown in the following figure.
Connect to the SQL Server database to view the time when insert operations were suspended.
Connect to the ECS instance.
Use Microsoft SQL Server Management Studio 18 to connect to the SQL Server database.
Click New Query.
In the query window that appears, enter the following SQL statements:
USE AdventureWorks select * from PointInTime GO
Right-click the query window and select Execute.
View the query results. In the query results, you can find that no write records were inserted into the database during the freezing time window.
Step 5: Check whether application-consistent snapshots can be used as expected to restore data
Use application-consistent snapshots to restore data on the ECS instance. Then, check whether the last write time of SQL Server data precedes the time when the application pre-freeze script was executed. If yes, the SQL Server data was properly backed up in the application-consistent snapshots and is restored as expected on the ECS instance.
In the ECS console, use the snapshot-consistent group that you created to roll back data on the ECS instance.
For more information, see Roll back disks by using a snapshot-consistent group.
Log on to SQL Server and query the content of the PointInTime table.
Connect to the ECS instance.
Use Microsoft SQL Server Management Studio 18 to connect to the SQL Server database.
Click New Query.
In the query window that appears, enter the following SQL statements:
USE AdventureWorks select * from PointInTime GO
Right-click the query window and select Execute.
View the query results. In the query results, you can find the last write time to the SQL Server database after data is restored.
Insert operations have been stopped before the database was frozen. In this example, after you use the application-consistent snapshots in the snapshot-consistent group that you created to restore data, the last write time to the SQL Server database is
2021-08-05 16:42:57.
This time precedes the2021-08-05 16:42:59.9732143
freezing time obtained in Step 4. Application-consistent snapshots have properly backed up SQL Server data.