I'm looking for the best way to back up an Azure SQL database and restore it into a development environment. Specifically, should I be using PowerShell with SQLPackage to create a BACPAC for importing, or is there a more effective method? Also, do I need to delete the development environment's database each time I run this process?
3 Answers
A straightforward method you can use is the 'create database as copy' syntax. Here’s a link to the documentation for that: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-database-transact-sql?view=azuresqldb-current&preserve-view=true&tabs=sqlpool&WT.mc_id=DP-MVP-5001699#create-a-copy-of-a-database-on-another-logical-server
Before diving in, consider a few factors: How large is your database? Do you need all the data, or would a sample suffice? If your data contains sensitive information, like GDPR data, you'll need to ensure it’s obfuscated in the development environment. Also, think about your connection method and whether you want to schedule the process at specific times or run it on demand. We had to back up our production database and make sure to clean a lot of data to comply with regulations before moving to dev.
I just went through this process, and I found that using SQL copy was the easiest approach. I recommend scripting everything into a pipeline. Our pipeline does a SQL copy from Production to the lower environment, initially setting the lower DB's SKU higher for a faster copy. We then use Azure Data Factory to obfuscate any PII before scaling down. This way, we keep minimal impact on the source DB, and the whole process for our 400GB prod DB takes about an hour to run nightly.
Related Questions
Fix Not Being Able To Add New Categories With Intuitive Category Checklist For Wordpress
Get Real User IP Without Installing Cloudflare Apache Module
How to Get Total Line Count In Visual Studio 2013 Without Addons
Install and Configure PhpMyAdmin on Centos 7
How To Setup PostfixAdmin With Dovecot and Postfix Virtual Mailbox
Dovecot Error Unknown database driver mysql