06 Sep

Restore bacpac to Azure

Microsoft SQL Azure
In one my previous posts I told you how you can backup an Azure database to bacpac files.
In this post I’ll show you how you can restore those files to Azure by using Power Shell.


You will need the following data:

  • The SQL server installation folder (default: C:\Program Files (x86)\Microsoft SQL Server): [INSTALFOLDER]
  • The SQL Server URL: [SQLSERVER]
  • SQL Login User: [USER]
  • SQL Login Password: [PASSWORD]
  • Folder where all Bacpac files are located: [BACPACFOLDERS]

$SqlInstallationFolder = [INSTALFOLDER]
$ConnectionString = "Server=tcp:[SQLSERVER];User ID=[USER];Password=[PASSWORD];Trusted_Connection=False;Encrypt=True"
$goodlist = dir
$DacAssembly = "$SqlInstallationFolder\110\DAC\bin\Microsoft.SqlServer.Dac.dll"
Add-Type -Path $DacAssembly
$Services = new-object Microsoft.SqlServer.Dac.DacServices $ConnectionString
foreach($i in $goodlist){
$name = $i.Name.Substring(0, $i.Name.length - 7);
Write-Host "Starting import $name at $now"; 
$Package = [Microsoft.SqlServer.Dac.BacPackage]::Load([BACPACFOLDERS] + $i);
$Services.ImportBacpac($Package, $name); 
Write-Host "   Restore $name complete";}

This will import the databases to your Azure SQL server.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.