4

I am playing around with SQL Azure and in my learning curve. I Have migrated a database from my on premises instance to the Azure server. Now my question is, how do I move a database from Azure to on premises instance.

Source : Azure , Database name : Azuretest

Destination : Sql server 2016 on premises instance in my laptop.

Is Azure to On Premise database migration possible?

enter image description here

asked Aug 1, 2017 at 17:47

4 Answers 4

4
  1. Export the Data-tier to local disk from the Azure database. It will save a bacpac file.

Right click the database you need to export --> Task-->Export data-tier application and follow the steps until the bacpac file is created.

  1. Import the backpack file from the local disk to the On premises Instance by using the same utility from tasks.

Right click the database branch in your on premise instance --> Import data tier application and now use the bacpac file saved in first step to create the database.

enter image description here

answered Aug 1, 2017 at 18:00
7
  • That will only do data, how about schema? Commented Aug 1, 2017 at 18:07
  • It will do the whole database. Commented Aug 1, 2017 at 18:07
  • You can read more about it here: learn.microsoft.com/en-us/sql/relational-databases/… Commented Aug 1, 2017 at 18:08
  • Thank you. I hit extract instead of export and only saw option for dacpac and not bacpac. Sorry about that. Commented Aug 1, 2017 at 18:33
  • 1
    No harm done. :) Commented Aug 1, 2017 at 18:35
1

Just in case someone needs more details on the steps as mentioned by Daniel:

  1. Export the Data-tier to local disk from the Azure database. It will save a bacpac file.

Right click the database you need to export --> Task-->Export data-tier application and follow the steps until the bacpac file is created.

  1. Import the backpack file from the local disk to the On premises Instance by using the same utility from tasks.

Right click the database branch in your on premise instance --> Import data tier application and now use the bacpac file saved in first step to create the database.

Thank you Daniel.

enter image description here

answered Aug 1, 2017 at 19:20
2
  • I updated the answer with your more detailed description. Commented Aug 1, 2017 at 19:34
  • 1
    Awesome! I am sure this will help others in future. Commented Aug 1, 2017 at 19:40
0

Creating an empty database in Azure.

USE [master] 
GO
CREATE DATABASE [Migrate2OnPrem] 
GO
ALTER DATABASE [Migrate2OnPrem] SET COMPATIBILITY_LEVEL = 130 
GO
ALTER DATABASE [Migrate2OnPrem] SET QUERY_STORE (OPERATION_MODE = READ_WRITE, 
CLEANUP_POLICY = (STALE_QUERY_THRESHOLD_DAYS = 7), DATA_FLUSH_INTERVAL_SECONDS = 900, 
INTERVAL_LENGTH_MINUTES = 60, MAX_STORAGE_SIZE_MB = 10, QUERY_CAPTURE_MODE = AUTO, 
SIZE_BASED_CLEANUP_MODE = AUTO) 
GO
ALTER DATABASE [Migrate2OnPrem] SET READ_WRITE GO

Exporting database to a .bacpac file

Using sqlpackage.exe action Export create a .bacpac file at my local host.

cd "C:\Program Files\Microsoft SQL Server130円\DAC\bin\"
.\SqlPackage.exe /Action:Export /SourceServerName:tcp:taiobadw.database.windows.net,1433 
 /SourceDatabaseName:Migrate2OnPrem /su:taiobmdjamshed /sp:password 
 /TargetFile:"C:\Migrate2OnPrem.bacpac" 

Importing to On-Prem server

Using sqlpackage.exe action Import import the .bacpac file from my local host (that you created in the step above.

.\sqlpackage.exe /a:Import /sf:C:\Migrate2OnPrem.bacpac /tsn:localhost /tdn:Migrate2OnPrem
answered Aug 1, 2017 at 18:32
0

Besides export\import .bacpac described by other users, there is another way to migrate a database, which in many cases may be preferable.

You can create a .sql script of Azure database and then run it in SQL Server

Generate t-sql script via Sql Server Managment Studio

right click on database -> Generate script

enter image description here

The Script Wizard will open.

In the Set Scripting Options section, click the Advanced. Specify the Types of data for script option to Schema and Data. Pay attention to the options Script for server version and Script for database engine type, here you can choose which database to create the script for.

enter image description here

Specify where the script should be saved and click Finish

To import a .sql file, simply open it in Sql Server Managment Studio and press F5. If the .sql file is very large then you can use the sqlcmd utility.

sqlcmd -S <server> -i C:\<your file here>.sql 

Note, when creating a .sql script or Export data tier application, the data should not be changed in the database, since these methods do not provide transactional consistency of the exported data. If you are exporting a live database, then create a copy of it temporarily for export.

CREATE DATABASE AdventureWorksCopy
AS COPY OF AdventureWorks
GO
answered Oct 30, 2020 at 14:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.