This article explores the process to recover data in AWS RDS SQL Server and its recent enhancements.

本文探讨了在AWS RDS SQL Server中恢复数据的过程及其最新增强功能。

AWS RDS简介 (Introduction to AWS RDS)

Amazon Web Services (AWS) is a leading cloud solutions provider. It is a highly available solution and provides better infrastructure management with reduced administrative costs – prompting many organizations to move their infrastructure to the cloud. With its pay-as-you-go model, AWS frees organizations from maintaining equipment, resulting in time and cost savings.

Amazon Web Services(AWS)是领先的云解决方案提供商。 它是一个高度可用的解决方案,可以通过降低的管理成本提供更好的基础架构管理,从而促使许多组织将其基础架构迁移到云中。 凭借其按需付费的模式,AWS使组织免于维护设备,从而节省了时间和成本。

AWS offers following support for SQL Server databases:

AWS为SQL Server数据库提供以下支持:

  • SQL Server on Amazon EC2 instance Amazon EC2实例上SQL Server
  • Amazon Relational Database Service (RDS) 亚马逊关系数据库服务(RDS)

Amazon RDS is a platform as a service (PaaS) solution that provides highly available SQL Server instances while removing the need to maintain underlying infrastructure. It also reduces administrative efforts for backups, database maintenance, minor upgrades, and monitoring. You can learn more about Amazon RDS using this link.

Amazon RDS是一种平台即服务(PaaS)解决方案,可提供高可用性SQL Server实例,同时无需维护基础基础架构。 它还减少了备份,数据库维护,次要升级和监视的管理工作。 您可以使用此链接了解有关Amazon RDS的更多信息。

在本地SQL Server中恢复数据的方案 (Scenario to recover data in on-premises SQL Server )

Let’s explore a scenario involving an on-premises SQL Server instance. Suppose you have a database, TestDB that is backed up regularly. A developer accidentally deletes rows from a table in the database that need to be recovered. You can think of the following solutions:

让我们探讨涉及本地SQL Server实例的方案。 假设您有一个定期备份的数据库TestDB。 开发人员意外地从数据库中的表中删除了需要恢复的行。 您可以想到以下解决方案:

  • Restore the latest database backup to the SQL instance. You can restore the backup on the same instance with different name, such as TestDB_recover 将最新的数据库备份还原到SQL实例。 您可以在具有不同名称的同一实例上还原备份,例如TestDB_recover
  • You can extract the data from a cloned database and import it into the original database. You can either use data scripts or use the SSMS import-export wizard 您可以从克隆的数据库中提取数据,并将其导入到原始数据库中。 您可以使用数据脚本或使用SSMS导入导出向导

Unfortunately, there are some limitations in the RDS database, and you cannot recover your data from a database backup since it does not allow you to restore the database with a new name from the same backup file. We will cover this scenario and solution to recover data in this article.

不幸的是,RDS数据库中有一些限制,您不能从数据库备份中恢复数据,因为它不允许您从同一备份文件中以新名称还原数据库。 我们将在本文中介绍此方案和恢复数据的解决方案。

在AWS RDS SQL Server中恢复数据的步骤 (Steps to recover data in AWS RDS SQL Server)

创建一个RDS SQL Server实例 (Create an RDS SQL Server instance)

Follow the instructions in the article AWS RDS SQL Server – Launching a new database instance and create a new Amazon RDS SQL instance.

请按照文章AWS RDS SQL Server –启动新的数据库实例并创建新的Amazon RDS SQL实例中的说明进行操作。

In the following screenshot, we can see the Amazon RDS SQL Server Express edition and DB identifier is myrdsinstance:

在以下屏幕截图中,我们可以看到Amazon RDS SQL Server Express版本,并且数据库标识符为myrdsinstance:

If you click on myrdsinstance under the DB identifier column, it launches DB instance properties. Under the Connectivity and security tab, you can see the endpoint. We require this endpoint to connect to RDS instance using SSMS.

如果单击数据库标识符列下的myrdsinstance ,它将启动数据库实例属性。 在“连接性和安全性”选项卡下,您可以看到端点。 我们要求此端点使用SSMS连接到RDS实例。

You should have Public accessibility set to Yes in order to connect it outside the Amazon cloud:

您应该将“ 公共可访问性”设置为“ 是” ,以便将其连接到亚马逊云之外:

In SSMS, specify the endpoint in the server name and provide the user name and password specified during Amazon RDS instance creation:

在SSMS中,在服务器名称中指定终端节点,并提供在Amazon RDS实例创建期间指定的用户名和密码:

By default, you can see the rdsadmin database in AWS RDS SQL Server. The rdsadmin database stores objects that contain procedures to manage databases. We should not make any changes to rdsadmin database and treat this as a system database for Amazon RDS SQL Server instance.

默认情况下,您可以在AWS RDS SQL Server中看到rdsadmin数据库。 rdsadmin数据库存储的对象包含管理数据库的过程。 我们不应对rdsadmin数据库进行任何更改,并将其视为Amazon RDS SQL Server实例的系统数据库。

创建一个新的数据库和对象 (Create a new database and objects )

Execute the following CREATE DATABASE statement for creating testdb that stores our tables:

执行以下CREATE DATABASE语句以创建用于存储表的testdb:

CREATE DATABASE TestDB;

Once a database is created, we can use the sp_helpfile command to see data and log file information:

创建数据库后,我们可以使用sp_helpfile命令查看数据和日志文件信息:

USE testdb;
GO
sp_helpfile;

We can then create a Customers table and insert two records in it.

然后,我们可以创建一个Customer表并在其中插入两个记录。

Create table Customers
( CustID int,CustName varchar(30)
)Insert into Customers values (1, 'Rajendra')
Insert into Customers values (2, 'Kusum')

在AWS S3存储桶中执行数据库完全备份 (Perform database full backup in AWS S3 bucket)

Let’s perform a full database backup of this database and store it in an S3 bucket. We cannot take the database backup directly using the native database backup command in AWS RDS SQL Server. Rather, we need to use stored procedure msdb.dbo.rds_backup_database and specify the S3 bucket name along with the backup file name. You can follow steps in article AWS RDS SQL Server migration using native backups to configure the S3 bucket and configure an Amazon RDS instance with it.

让我们对该数据库执行完整的数据库备份,并将其存储在S3存储桶中。 我们无法使用AWS RDS SQL Server中的本机数据库备份命令直接进行数据库备份。 相反,我们需要使用存储过程msdb.dbo.rds_backup_database并指定S3存储桶名称以及备份文件名称。 您可以按照文章使用本地备份进行AWS RDS SQL Server迁移中的步骤配置S3存储桶并使用它配置Amazon RDS实例。

 exec msdb.dbo.rds_backup_database @source_db_name='TestDB', @s3_arn_to_backup_to='arn:aws:s3:::rdstestsql/TestDB_Full.bak', @overwrite_S3_backup_file=1;

You can copy S3 bucket ARN from S3 bucket properties. Select the S3 bucket and click on Copy Bucket ARN as shown in the following image:

您可以从S3存储桶属性复制S3存储桶ARN。 选择S3存储桶,然后单击Copy Bucket ARN,如下图所示:

Execute the backup command mentioned above, and it starts the database backup.

执行上述备份命令,它将启动数据库备份。

We need to use another stored procedure to track the status of the database backup. Specify the task id from the above screenshot:

我们需要使用另一个存储过程来跟踪数据库备份的状态。 从上面的屏幕快照中指定任务ID:

exec msdb..rds_task_status @task_id= 15

You can execute this procedure multiple times to see the status changes.

您可以多次执行此过程以查看状态更改。

As shown below, the status changes: Created -> In_PROGRESS -> SUCCESS:

如下所示,状态更改:已创建-> In_PROGRESS->成功:

If there is an error while doing a database backup, you can see the error message in the task status:

如果执行数据库备份时发生错误,则可以在任务状态中看到错误消息:

Once the task status is completed successfully, you can see the backup file in the S3 bucket:

任务状态成功完成后,您可以在S3存储桶中看到备份文件:

从客户表中删除数据 (Delete data from Customers table)

We have database backup now. Suppose someone accidentally deleted records from the database:

我们现在有数据库备份。 假设有人不小心从数据库中删除了记录:

Delete from Customers where CustID=2

在AWS RDS SQL Server中恢复数据的旧方法 (Old approach to recover data in AWS RDS SQL Server)

We have a database backup before the accidental removal of data. Previously Amazon RDS did not allow restoring a database backup on the same instance if the source database was already present on the RDS instance. You can reference the backup error message in Amazon blogs.

在意外删除数据之前,我们有一个数据库备份。 以前,如果源数据库已经存在于RDS实例上,则Amazon RDS不允许在同一实例上还原数据库备份。 您可以在Amazon博客中引用备份错误消息。

For example, in our case, we cannot restore a database backup from the S3 bucket into an existing RDS instance with a different name such as testdatabase_recoverdata. We will cover the reason for this later.

例如,在我们的情况下,我们无法将数据库备份从S3存储桶还原到具有不同名称(例如testdatabase_recoverdata)的现有RDS实例。 我们稍后将说明原因。

You can restore the backup on a different instance and script out data there. This means you need to manufacture a separate RDS instance for restoration purpose only.

您可以在其他实例上还原备份,并在其中编写数据脚本。 这意味着您仅需要为恢复目的而制造一个单独的RDS实例。

Previously AWS RDS SQL Server allowed two solutions for it.

以前,AWS RDS SQL Server为此提供了两种解决方案。

  • Restore database backup in different RDS instance 在不同的RDS实例中还原数据库备份
  • Use SSMS import-export wizard to recover the data 使用SSMS导入导出向导恢复数据

在AWS RDS SQL Server中恢复数据的新方法 (New approach to recover data in AWS RDS SQL Server)

On October 24th, 2018, Amazon announced an exciting feature for database backup and restore. Below is the screenshot from the RDS feature announcement.

2018年10月24日,亚马逊宣布了一项令人兴奋的数据库备份和还原功能。 以下是RDS功能公告的屏幕截图。

Amazon RDS now supports restoring a differently-named database from the backup to an existing RDS instance where the source database exits:

Amazon RDS现在支持将名称不同的数据库从备份还原到现有RDS实例,在该实例中源数据库将退出:

在现有AWS RDS SQL Server实例上使用新名称还原数据库 (Restore database with a new name on existing AWS RDS SQL Server instance )

Let’s restore the database from the backup in the S3 bucket. We need to use the same stored procedure, only with different parameters:

让我们从S3存储桶中的备份还原数据库。 我们需要使用相同的存储过程,仅使用不同的参数:

exec msdb.dbo.rds_restore_database
@restore_db_name='TestDB_Recover',
@s3_arn_to_restore_from='arn:aws:s3:::rdstestsql/TestDB_Full.bak';

It starts a task to restore the database and you can note the task id:

它启动一个任务来还原数据库,您可以记下任务ID:

Check the status for the database restore using the query below. In the following screenshot, we can see status Success along with duration, source backup file, and database name.

使用以下查询检查数据库还原的状态。 在以下屏幕截图中,我们可以看到状态为Success以及持续时间,源备份文件和数据库名称。

exec msdb..rds_task_status @task_id= 16

Here is the result:

结果如下:

Let’s verify the record in the new database by running the query below:

让我们通过运行以下查询来验证新数据库中的记录:

Select * from TestDB_Recover.dbo.customers

We can see both the records in the restored database. We can script this out and recover data in the source database:

我们可以在还原的数据库中看到这两个记录。 我们可以编写脚本并在源数据库中恢复数据:

We cannot use the import and export wizard in Amazon RDS to export data from a restored database to a source database:

我们无法使用Amazon RDS中的导入和导出向导将数据从已还原的数据库导出到源数据库:

Earlier, we mentioned that Amazon RDS does not allow database restoration from backup on the source database RDS instance. Let’s see the reason for it.

之前,我们提到Amazon RDS不允许从源数据库RDS实例上的备份还原数据库。 让我们看看原因。

验证源和还原数据库的数据库文件属性 (Verify database file properties for source and restored database)

Execute the following commands on the source database TestDB and new (restored) database TestDB_Recover. It gives us file name, physical file name, and file_guid:

在源数据库TestDB和新的(还原的)数据库TestDB_Recover上执行以下命令。 它为我们提供了文件名,物理文件名和file_guid:

Use TestDB
go
SELECT name,physical_name, file_guid FROM sys.database_files;
go
Use TestDB_Recover
go
SELECT name,physical_name, file_guid FROM sys.database_files;

In the following screenshot, note the following:

在以下屏幕截图中,请注意以下几点:

  • The file name for data and log files are similar for both source and restored database 源数据库和还原数据库的数据文件和日志文件的文件名相似
  • We have different physical file names for data and log files in both the source and restored database 源数据库和还原数据库中的数据和日志文件都有不同的物理文件名
  • The file_guid is similar for both source and restored database. Amazon RDS initially did not allow restoration due to similar file_guid for both databases. It returns the following error message:

    源数据库和还原数据库的file_guid相似。 由于两个数据库的file_guid类似,Amazon RDS最初不允许还原。 它返回以下错误消息:

    Database TestDB_clone cannot be restored because there is already an existing database with the same file_guid on the instance.

    无法还原数据库TestDB_clone ,因为实例上已经存在一个具有相同file_guid的数据库

结论 (Conclusion)

In this article, we explored data recovery in AWS RDS SQL Server database from the database backups. You can restore a different database from the S3 bucket backup on an existing database as part of this new enhancement. You should be aware of this enhancement for database backup and restoration in RDS SQL Server.

在本文中,我们探讨了从数据库备份在AWS RDS SQL Server数据库中的数据恢复。 作为此新增强功能的一部分,您可以从现有数据库上的S3存储桶备份还原不同的数据库。 您应该了解RDS SQL Server中数据库备份和还原的增强功能。

翻译自: https://www.sqlshack.com/recover-data-in-aws-rds-sql-server/

在AWS RDS SQL Server中恢复数据相关推荐

  1. aws rds监控慢sql_在AWS RDS SQL Server中实施SSL连接

    aws rds监控慢sql This article explores a method to enforce SSL for all connections in AWS RDS SQL Serve ...

  2. 在AWS RDS SQL Server中进行审核

    This article explores the server and database audit in AWS RDS SQL Server. 本文探讨了AWS RDS SQL Server中的 ...

  3. aws rds监控慢sql_AWS RDS SQL Server中的本机差异备份概述

    aws rds监控慢sql This article explores the differential backups in AWS RDS SQL Server using recovery sc ...

  4. aws rds 加密_AWS RDS SQL Server中的加密备份和还原

    aws rds 加密 ol li p{ font-size: 14px; color: #252525; } ol li p{ font-size: 14px; color: #252525; } I ...

  5. aws rds监控慢sql_在AWS RDS SQL Server上使用SSIS包

    aws rds监控慢sql In the first part of the article, Explore SQL Server Integration Services (SSIS) on AW ...

  6. aws rds监控慢sql_在AWS RDS SQL Server上的SSAS中部署表格数据库

    aws rds监控慢sql In this article, we are going to explore Analysis Service for AWS RDS SQL Server in de ...

  7. aws rds 加密_AWS RDS SQL Server中的透明数据加密(TDE)

    aws rds 加密 In this article, we will review Transparent Data Encryption (TDE) in AWS RDS SQL Server. ...

  8. aws rds监控慢sql_AWS RDS SQL Server中的初始Windows身份验证配置

    aws rds监控慢sql In this article, we will be exploring the process of enabling Windows authentication i ...

  9. aws rds监控慢sql_AWS RDS SQL Server中的高级Windows身份验证配置

    aws rds监控慢sql This article will cover advanced configurations for Windows Authentication in AWS RDS ...

最新文章

  1. Hadoop对Spark:正面比拼报告(架构、性能、成本、安全性和机器学习)
  2. 奥比中光2022春季校园招聘全面启动!
  3. 缓存伪静态html,伪静态缓存(整站静态化)
  4. 03013_JDBC工具类
  5. linux中的SGI(核间中断)IPI_RESCHEDULE详解
  6. UVA - 10480 Sabotage(最小割-最大流+输出割边)
  7. 实例60:python
  8. RPC-非阻塞通信下的同步API实现原理,以Dubbo为例
  9. 离线或在线加载pytorch、mmdetection预训练模型vgg、resnet、alexnet等
  10. 小蒜的A+B 计蒜客 - T1283
  11. iphone分屏功能怎么用_你用iPhone手机,没学会这7个功能,难怪会说手机不好用...
  12. LeetCode 72 编辑距离
  13. 【平衡二叉树】超市促销
  14. JS-修改图片颜色值
  15. 社科院与杜兰大学金融管理硕士——承载梦想,带自己遨游世界的“风帆”
  16. On teaching mathematics--Arnold
  17. 《 阿Q正传》-鲁迅 词语解释 | 经典语录
  18. Sentinel-1 (哨兵1号)轨道数据下载网址跟(2022更新)
  19. 透光按键激光打标机,激光打标机
  20. 联机分析处理(OLAP)到底是什么?

热门文章

  1. IntelliJ IDEA实时模板变量
  2. mac上使用终端生成RSA公钥和密钥
  3. Android View 自定义RangeSeekBar范围选择器
  4. 40款免费社交图标素材
  5. js隐藏打开项目隐藏编辑 和删除按钮
  6. Number类型及方法(js)
  7. kubernetes之三:service
  8. git进阶(撤销pull、撤销merge、撤销add)
  9. 【PHP学习】—PHP连接数据库(六)
  10. ES6学习(七)—Set 和 Map 数据结构