Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I generate bacpac file from local machine and upload it on Azure blob?

I'm using SQL Server 2012 , I know how to take bacpac of sql database from azure portal and store that file into blob but

How do I generate bacpac file from local machine and upload it on Azure blob?

Is there any way to do so ? using c# program or any utility ?

like image 493
Neo Avatar asked Mar 31 '15 08:03

Neo


People also ask

How do I upload Bacpac to Azure storage?

To import from a BACPAC file into a new single database using the Azure portal, open the appropriate server page and then, on the toolbar, select Import database. Select the storage account and the container for the BACPAC file and then select the BACPAC file from which to import.


2 Answers

If you are looking to automate this, there is a way:

1) Generate the .bacpac file using SqlPackage.exe

For example:

“C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\sqlpackage.exe” 
/a:Export /ssn:SourceServerName /sdn:SourceDatabaseName      
/tf:C:\DataExtraction\SourceDatabase.bacpac"

This would generate a bacpac under C:\DataExtraction\SourceDatabase.bacpac

for more info go here: SqlPackage.exe

2) Upload the bacpac to Azure Storage as Blob using Azure PowerShell

Switch-AzureMode -Name AzureServiceManagement
$context= New-AzureStorageContext -StorageAccountName "Storageaccountname" -StorageAccountKey "mystoragekeyhere"

Set-AzureStorageBlobContent -Context $context -Container adventureworks -File "NameOfLocal.bacpac" -Blob "NameofBacpacInStorageContainer.bacpac"

for more information on this cmdlet go here: Set-AzureStorageBlobContent

Should you need to Import the following command will help you:

“C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\sqlpackage.exe” 
/a:Import /tsn:TargetServerName /tdn:TargetDatabaseName      
/sf:C:\DataExtraction\SourceDatabase.bacpac"

Should you desire to use sqlpackage.exe add the following directory to your PATH (instructions):

C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\

like image 189
Boboyum Avatar answered Sep 17 '22 22:09

Boboyum


Download and install SSDT tool

[Your DataBase]-> Task -> Export Data tier Application -> [Choose the localPath.bacpac]

You can also directly deploy to SQL Azure using Deploy Data Tier Application to SQL Azure

like image 21
sudhAnsu63 Avatar answered Sep 17 '22 22:09

sudhAnsu63