Export and Import BACPAC using command line

SQLPackage.exe can be used for the following tasks:

  • Extract: Creates a database snapshot (.dacpac) file from an on-premise (local) SQL Server or Windows Azure SQL Database.
  • Export: Exports a on-premise (local) database – including database schema and user data – from SQL Server or Windows Azure SQL Database to a BACPAC package (.bacpac file).
  • Import: Imports the schema and table data from a BACPAC package into a new user database in an instance of SQL Server or Windows Azure SQL Database.
  • Publish: Incrementally updates a database schema to match the schema of a source .dacpac file. If the database does not exist on the server, the publish operation will create it. Otherwise, an existing database will be updated.
  • DeployReport: Creates an XML report of the changes that would be made by a publish action.
  • DriftReport: Creates an XML report of the changes that have been made to a registered database since it was last registered.
  • Script: Creates a Transact-SQL incremental update script that updates the schema of a target to match the schema of a source.

Let’s see some examples

Export the local database to a bacpac file

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

ssn – Specifies the name of the server that hosts the database.
sdn – Defines the name of the source database.
tf – Specifies a disk file path where the .dacpac or .bacpac file will be written.
If the logged in user is executing the script, Integrated Windows Authentication will be used. So no need to specify the username or password.

Import the bacpac file to SQLAzure

“C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\sqlpackage.exe” /a:Import /sf:C:\DataExtraction\Tailspintoys.bacpac /tsn:cgrd7z8kac.database.windows.net /tdn:Tailspintoys /tu:mysysadmin@cgrd7z8kac /tp:Pa55w0rd

sf – Specifies a source file to be used as the source of action instead of database.
tsn – Specifies the name of the server that hosts the target database.
tdn – Specifies the name of the target database.
tu – SQL Server user that is used to get access to the target database.
tp – specifies password that is used to get access to the target database.

If you are planning to automate this using C# console application, there is a code sample available here
http://code.msdn.microsoft.com/windowsazure/DAC-Framework-Direct-77af5c98#content

Advertisements

12 thoughts on “Export and Import BACPAC using command line

  1. It’s actually a great and helpful piece of
    info. I am glad that you simply shared this helpful info with us.
    Please stay us informed like this. Thank you for sharing.

  2. Hi everybody, here every person is sharing these kinds of
    know-how, therefore it’s good to read this weblog, and I used to
    pay a quick visit this webpage every day.

  3. Hi! Your websites are running lagging for me, this took sort of a moment to
    reload, I dont know whether it is entirely me or
    perhaps your web page however , google worked acceptable for me.
    Well, I am going to thank you very much for putting brilliant
    blog post. I’m sure this has been totally beneficial to
    individual who seem to click here. I personally need to say that you really have done wonderful job with this plus expect to find much more great things through you.
    After viewing the post, I’ve book-marked your site.

  4. Hi! Your site is loading slowly , it consumed like
    a minute to actually load, I actually do not know if it’s just simply me or maybe websites however , facebook
    loaded acceptable for me. Nevertheless, Thanks for publishing such
    type of brilliant articles. Everybody who actually visited this page
    must have found this article seriously handy.
    I am hoping I will be able to get further remarkable information and I
    also should really flatter you by saying you have done remarkable writing.
    Soon after viewing your articles, I have bookmarked your web site.

  5. Hello Yahoo works perfectly yet your site is loading steadily which actually took nearly one minute to be able to
    load, I am not sure if it is my own problem or perhaps your web site problems.
    Well, Thank you for creating an incredibly fantastic blog post.

    I believe this has been really helpful individual who
    seem to visit here. I hope I will be able to get more incredible things and
    I should complement simply by stating you’ve done awesome job.
    After viewing your articles, I have book-marked your web page.

  6. Hey there Your entire web site starts up really slow in my situation, I am
    not sure who’s problem is that however , wikipedia
    starts up extremely good. Anyways, I would like to say thanks for adding awesome post.
    Almost everyone who found this web site should
    have noticed this informative article seriously very helpful.
    I personally have to state that you have done superb job with this
    plus wish to find more brilliant stuff from you. Right after looking at your articles,
    I have book marked your site.

  7. Hello Your entire web site loads up seriously slow to me, I not really know
    who’s problem is that however , facebook starts fairly immediate.
    Nevertheless, I appreciate you for putting up such a wonderful article.
    Nearly everybody who visited this web site really should have
    noticed this content literally helpful. This is undoubtedly
    excellent everything that you actually have done and would like to discover
    a lot more posts from your site. I have got your site book-marked to check
    blog you publish.

  8. Hi Your website loads up really slow if you ask me, I don’t know who’s problem is that on the other hand twitter and facebook opens up extremely fast.
    Anyways, Thank you for publishing an extraordinarily awesome articles.
    I assume it has been necessary to a lot of people who came on this page.
    I personally need to say that you have done amazing work with this and additionally wish to
    find more brilliant content through you. I already
    have your site book marked to look at new stuff
    you publish.

  9. Greetings Yahoo performs great for my situation but your
    website is starting slowly which had taken approximately one minute to actually load up, I’m not sure
    whether or not it’s my very own issue perhaps website problems.
    Well, Thanks for posting an extraordinarily excellent article.
    I believe it really has already been totally helpful to individual
    who click here. I really hope I will be able to find more remarkable things and I should really complement you simply by stating you
    have done fabulous work. To obtain additional understanding
    through articles you write-up, I’ve book-marked this website.

  10. Hello Your main web site runs up really slow in my opinion, I don’t
    know who’s issue is that however , facebook starts up quite fast.
    However thanks for creating excellent blog post. Nearly
    everybody who found this great site should have discovered this short article extremely beneficial.

    This is actually great what you have implemented and wish to check out articles from you.
    After taking a look at your blog post, I have book marked your webblog.

  11. Hey Twitter operates perfectly however your website is running steadily which went on approximately a few minutes to be able
    to load, I don’t know whether it’s my own issue or perhaps your web site problems.
    Well, I need to thank you so much for placing excellent article.
    Almost everyone who found this great site must have discovered this content extremely useful.
    This is terrific everything that you have concluded
    and would like to discover fascinating articles by you.
    I already have your site saved to bookmarks to look at new stuff you post.

  12. Hey there Your web page runs up honestly slow to me, I’m not sure who’s
    issue is that however , flickr opens up relatively immediate.
    Anyway, Thank you for creating a remarkably beautiful article.
    I do believe this has been honestly beneficial to individual
    who seem to click here. I really hope I will be able to get further incredible things and I also should certainly compliment by telling you have done good work.
    Just after looking at your articles, I’ve bookmarked
    your web site.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s