Import export Azure databases using Azure REST Api programmatically C# Net

With the help of cloud technology most of the websites, mobile app or big contents are moved to cloud for high availability and each of use. Like the content files, most of the database also hosted in the cloud. Once of the best known cloud service providers is Azure and the features they are providing with the database storage is tremendous. We all know about SQL Server databases and now we can this database in the cloud. So in this post we’ll see how we can control the database programmatically. Like import export azure databases using Azure rest Api programmatically C# net. The Azure REST management Api provides easy way to manage all the resources in Azure.

Here we’ll use the Azure Rest Api for database to import export the databases. The following things will be covered;

  1. Get authorization token to access the REST Api.
  2. Creating the required json object to pass with the import/export request.
  3. Check the import/export status and wait until the import/export completes.

First, we’ll see how we can generate the authorization token to access the REST Api. you can refer the following url to find out the clientId, clientSecret and tenantId values in Azure portal. The generated token will be used with other requests.

 

Before we see how to import/export the database, we’ll see how to get the progress of the request. When we send the request to Azure, Azure will send a url in the response, that can be used to check the status of the progress. Since the the process will take some time, the method IsDatabaseImportExportCompleted will wait and check the the status = “Competed”. The status check Api url will look like this https://management.azure.com/subscriptions/{YourSubscriptionId}/resourceGroups/{YourSubscriptionId}/providers/Microsoft.Sql/servers/{YourServerName}/importExportOperationResults/{ImportExportOperationId}?api-version=2014-04-01-Preview

Now we export the database, when exporting the database the exported file will be stored in blob storage. So we have to specify the access credentials of blob storage.

 

Fianllywe will jump into import export part.

When importing the database, the Azure Api will use the exported file the we created earlier in blob storage.

 

We can pass the data to Api in josn or xml format and I have passed the data as joson.

Happy clouding 🙂

References:

https://docs.microsoft.com/en-us/rest/api/sql/Databases%20-%20Import%20Export/Import

https://social.msdn.microsoft.com/Forums/vstudio/en-US/25faf680-53ed-4d45-a82c-da20a7dbffdd/run-powershell-functionality-thruogh-cnet-apis?forum=ssdsgetstarted

http://www.mikefal.net/2016/05/19/azure-sql-databases-with-powershell-exporting-and-importing/

https://github.com/davidebbo/AzureWebsitesSamples

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: