SQL Server Restore Azure SQL Database on a schedule

gcuhipw9  于 2023-10-15  发布在  其他
关注(0)|答案(1)|浏览(123)

Once a week, we need to run a restore of one Azure SQL database to have it replace an existing one. In other words, once a week, we need to fully replace Azure_DB_2 with Azure_DB_1 (via Restore), but keep the name of the replaced database, as Azure_DB_2.

Because Azure SQL Server does not support Restore with Replace, I have to first temporarily rename Azure_DB_2. To accomplish this, I've set up an Agent Job on my local SQL Server to first rename Azure_DB_2 to Azure_DB_2a. Then what I want to do is Restore Azure_DB_1 as name Azure_DB_2. As the final step, I'll DROP table Azure_DB_2a.

It's that middle step, Restore Azure_DB_1 as name Azure_DB_2, that I'm a little confused as how to accomplish. It's easy to do inside Azure Portal, but that doesn't help me for automatic scheduling.

If possible, it would be great to simply add it as a step in the Agent Job, but if I'm reading correctly, it seems I can only do a Restore of an Azure SQL database via a Powershell script, and not using T-SQL inside SSMS? Ideally the best solution is to have the entire process contained in one Agent job. Can someone assist with the T-SQL syntax to accomplish an Azure Restore?

yptwkmov

yptwkmov1#

Per Dan Guzman's suggestion, I've added a Powershell script as one of the steps in the Agent Job. All works perfectly.

相关问题