![How to backup your database to a storage account using a managed identity ?](https://technicalandcloud.com/wp-content/uploads/2023/02/English-Version-3-800x600.png)
How to backup your database to a storage account using a managed identity ?
What if I told you that we can export your database to a storage account, automatically using a managed identity ? the rest is just below
Prerequisites
You will need:
- SQL Database
- Automation Account
- My Github : -azure-backupsqldatabase/Export DB PAAS By Automation Account.ps1 at main · technicalandcloud/-azure-backupsqldatabase (github.com)
- One Managed Identity ( System or User) – Contributor Role
In Storage Account, enable « Allow Azure services and resources to access this server« :
![](https://technicalandcloud.com/wp-content/uploads/2023/02/image-10.png)
Deployment
First step, we will create our Managed Identity.
Go to Managed Identities and click on Create:
![](https://technicalandcloud.com/wp-content/uploads/2023/02/image-1-1920x262.png)
Fill in the requested fields.
Once the identity is created, go to Azure Role Assignments:
![](https://technicalandcloud.com/wp-content/uploads/2023/02/image-4-1920x527.png)
and apply the Contributor role to it:
![](https://technicalandcloud.com/wp-content/uploads/2023/02/image-5-1920x604.png)
Then go to Automation Account in Identity and select User assigned and click Add to add your previously created Identity:
![](https://technicalandcloud.com/wp-content/uploads/2023/02/image-1920x427.png)
Once finished, go to my github page:
Retrieve the Code and put it in a Runbook:
Remember to change the client ID of your Managed Identities:
![](https://technicalandcloud.com/wp-content/uploads/2023/02/image-3.png)
Once finished, we can save and launch the execution:
![](https://technicalandcloud.com/wp-content/uploads/2023/02/image-6-1920x932.png)
Fill in the different fields mentioned on the right:
![](https://technicalandcloud.com/wp-content/uploads/2023/02/image-11.png)
Once completed and launched, we can return to the SQL Server, we see an export in progress :
![](https://technicalandcloud.com/wp-content/uploads/2023/02/image-8.png)
If we go back to our storage account, we can see our .BACPAC file in our container:
![](https://technicalandcloud.com/wp-content/uploads/2023/02/image-9.png)
Then, we can go to automation account -> Schedule, to automate the export:
![](https://technicalandcloud.com/wp-content/uploads/2023/02/image-12.png)
Conclusion
Now you know How to backup your database to a storage account using a managed identity, and you can make the export automatic.