简体   繁体   English

在现有数据库上恢复 Azure SQL 数据库以维护备份历史记录

[英]Restore Azure SQL DB over an existing DB to maintain backup history

I'm setting up an Azure SQL DB for our Web App.我正在为我们的 Web 应用程序设置 Azure SQL 数据库。 We have enabled Point In Time Retention (PITR) and Long Term Retention (LTR).我们启用了时间点保留 (PITR) 和长期保留 (LTR)。 Our process is to keep backups for 1 year.我们的流程是将备份保留 1 年。

Periodically, we need to upgrade the DB by applying SQL scripts.我们需要定期通过应用 SQL 脚本来升级数据库。 Sometimes there is a problem with the upgrade scripts and the upgrade fails.有时升级脚本有问题,升级失败。 We need to rollback the database to the previous version.我们需要将数据库回滚到以前的版本。

To rollback the DB I tried the restore feature.为了回滚数据库,我尝试了恢复功能。 However, the restore feature seems to only create new DBs;但是,恢复功能似乎只创建新数据库; therein lies the problem.这就是问题所在。 Restoring to a new DB and removing the old one works great, but we lose all our backup history.恢复到新数据库并删除旧数据库效果很好,但我们丢失了所有备份历史记录。 It appears backups are tired to the DB (probably to the ResourceId).看来备份对数据库来说很累(可能是 ResourceId)。

So, how can I use Azure SQL DB and periodically restore a DB and still maintain all the back up history?那么,我如何使用 Azure SQL DB 并定期恢复 DB 并仍然保留所有备份历史记录?

Unfortunately, restoring from a backup in Azure SQL Database always creates a new database.不幸的是,从 Azure SQL 数据库中的备份还原总是会创建一个新数据库。 The secret here may be to rename the newly restored database with the name of the original database.这里的秘诀可能是将新恢复的数据库重命名为原始数据库的名称。 You will even see that the restored database once renamed it then shows all the security recommendations, automatic tuning recommendations of the original database.您甚至会看到恢复的数据库一旦重命名它就会显示所有安全建议,原始数据库的自动调整建议。

So delete existing database, restored the database, and rename it as the original database.所以删除现有数据库,恢复数据库,并重命名为原始数据库。

You can reference this document Recover an Azure SQL database using automated database backups , it gives the answer that all the recover are creating new database.您可以参考此文档Recover an Azure SQL database using automatic database backups ,它给出了所有恢复都在创建新数据库的答案。

By default, SQL Database backups are stored in geo-replicated blob storage (RA-GRS).默认情况下,SQL 数据库备份存储在异地复制 blob 存储 (RA-GRS) 中。 The following options are available for database recovery using automated database backups: Create a new database on the same SQL Database server recovered to a specified point in time within the retention period.以下选项可用于使用自动数据库备份进行数据库恢复: 在同一 SQL 数据库服务器上创建新数据库,该数据库服务器已恢复到保留期内的指定时间点。

  • Create a database on the same SQL Database server recovered to the deletion time for a deleted database.在同一个 SQL 数据库服务器上创建数据库恢复到删除时间的删除数据库。
  • Create a new database on any SQL Database server in the same region recovered to the point of the most recent backups.在恢复到最近备份点的同一区域中的任何 SQL 数据库服务器上创建一个新数据库。
  • Create a new database on any SQL Database server in any other region recovered to the point of the most recent replicated backups.在恢复到最近复制备份点的任何其他区域中的任何 SQL 数据库服务器上创建一个新数据库。

If you configured backup long-term retention, you can also create a new database from any LTR backup on any SQL Database server.如果您配置了备份长期保留,您还可以从任何 SQL 数据库服务器上的任何 LTR 备份创建新数据库。

improtant :重要的

You cannot overwrite an existing database during restore.您不能在还原期间覆盖现有数据库。

"So, how can I use Azure SQL DB and periodically restore a DB and still maintain all the back up history?" “那么,我怎样才能使用 Azure SQL DB 并定期恢复 DB 并仍然保留所有备份历史记录?”

You can use Database replacement :您可以使用数据库替换

If the restored database is intended as a replacement for the original database, you should specify the original database's compute size and service tier.如果还原的数据库旨在替换原始数据库,则应指定原始数据库的计算大小和服务层。 You can then rename the original database and give the restored database the original name using the ALTER DATABASE command in T-SQL.然后,您可以使用 T-SQL 中的ALTER DATABASE命令重命名原始数据库并为恢复的数据库赋予原始名称。

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM