If you are working with Sitecore in Azure and your databases are Azure SQL Databases, you may find yourself in need of restoring a backup from Azure to your local environment. When you create a database backup from Azure (or your project architect provides it for you), you will notice that the file extension is “.bacpac” and not the familiar .bak of a SQL database. When you first attempt to restore the database, you will notice that you cannot select the .bacpac file. To complete the restore, you will need to follow these FREE Microsoft instructions to “Import Data-tier Application”. Unfortunately, you cannot simply overwrite your existing master database with the new .bacpac like you can with a .bak file, so you have to go through the steps of renaming databases. I put together a short SQL script to help speed that process along:
Run This Script
Make sure to update the variables to match your actual database names!
Last Steps
Manually delete the “_old” database after the script runs. You can add that as a step to the script yourself if you aren’t paranoid like me! I would recommend a full “Republish – publish everything” of your site afterwards.