How do I copy SQL Azure database to my local development server?

后端 未结 22 1017
抹茶落季
抹茶落季 2020-11-28 01:06

Does anyone know how I can copy a SQL Azure database to my development machine? I\'d like to stop paying to have a development database in the cloud, but it\'s the best way

相关标签:
22条回答
  • 2020-11-28 01:23

    Using msdeploy.exe

    Caveat: msdeploy.exe fails to create the destination database on its own, so you need to create it manually first.

    1. Copy the connection string on the database properties page. Adjust it so that it contains a correct password. database properties page
    2. Get the connection string for the destination DB.
    3. Run msdeploy.exe like this:

      "c:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -dest:dbDacFx="destination_DB_connection_string",dropDestinationDatabase=true -source:dbDacFx="azure_DB_connection_string",includeData=true -verbose
      

    Using SqlPackage.exe

    1. Export the azure DB to a bacpac package.

      "c:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\SqlPackage.exe" /a:Export /ssn:"azure_db_server" /sdn:"azure_db_name" /su:"user_name" /sp:"password" /tf:"file.bacpac"
      
    2. Import the package to a local DB.

      "c:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\SqlPackage.exe" /a:Import /SourceFile:"file.bacpac" /TargetServerName:".\SQLEXPRESS" /TargetDatabaseName:CopyOfAzureDb
      
    0 讨论(0)
  • 2020-11-28 01:24

    Copy Azure database data to local database: Now you can use the SQL Server Management Studio to do this as below:

    • Connect to the SQL Azure database.
    • Right click the database in Object Explorer.
    • Choose the option "Tasks" / "Deploy Database to SQL Azure".
    • In the step named "Deployment Settings", connect local SQL Server and create New database.

    enter image description here

    "Next" / "Next" / "Finish"

    0 讨论(0)
  • 2020-11-28 01:25

    It's pretty easy. This worked for me...in terms of getting an Azure SQL database down onto your local machine...:

    1. Open your SQL Management Studio and connect to your Azure SQL Server.
    2. Select the database you would like to get down onto your local machine, and right-click...select "Generate Scripts". Follow the prompts...

    BUT, be careful in that if you ALSO want the DATA, as well as the scripts, be sure to check the Advanced Options before beginning the generating...scroll down to "Types of data to script", and make sure you have "Schema and data"...or whatever is appropriate for you.

    It will give you a nice SQL script file which can then be run on your local machine and it will create the database as well as populate it with all the data.

    Bare in mind that in my case, I have no FK or other constraints...also, it wasn't a lot of data.

    I don't recommend this as a backup mechanism in general...

    0 讨论(0)
  • 2020-11-28 01:25

    The accepted answer is out of date. I found a better answer: Use Import Data-tier Application

    More detailed information please see this article: Restoring Azure SQL Database to a Local Server

    0 讨论(0)
  • 2020-11-28 01:27

    There are multiple ways to do this:

    1. Using SSIS (SQL Server Integration Services). It only imports data in your table. Column properties, constraints, keys, indices, stored procedures, triggers, security settings, users, logons, etc. are not transferred. However it is very simple process and can be done simply by going through wizard in SQL Server Management Studio.
    2. Using combination of SSIS and DB creation scripts. This will get you data and all missing metadata that is not transferred by SSIS. This is also very simple. First transfer data using SSIS (see instructions below), then create DB Create script from SQL Azure database, and re-play it on your local database.
    3. Finally, you can use Import/Export service in SQL Azure. This transfers data (with a schema objects) to Azure Blob Storage as a BACPAC. You will need an Azure Storage account and do this in Azure web portal. It is as simple as pressing an "Export" button in the Azure web portal when you select the database you want to export. The downside is that it is only manual procedure, I don't know a way to automate this through tools or scripts -- at least the first part that requires a click on the web page.

    Manual procedure for method #1 (using SSIS) is the following:

    • In Sql Server Management Studio (SSMS) create new empty database on your local SQL instance.
    • Choose Import Data from context menu (right click the database -> Tasks -> Import data...)
    • Type in connection parameters for the source (SQL Azure). Select ".Net Framework Data Provider for SqlServer" as a provider.
    • Choose existing empty local database as destination.
    • Follow the wizard -- you will be able to select tables data you want to copy. You can choose to skip any of the tables you don't need. E.g. if you keep application logs in database, you probably don't need it in your backup.

    You can automate it by creating SSIS package and re-executing it any time you like to re-import the data. Note that you can only import using SSIS to a clean DB, you cannot do incremental updates to your local database once you already done it once.

    Method #2 (SSID data plus schema objects) is very simple. First go though a steps described above, then create DB Creation script (righ click on database in SSMS, choose Generate Scripts -> Database Create). Then re-play this script on your local database.

    Method #3 is described in the Blog here: http://dacguy.wordpress.com/2012/01/24/sql-azure-importexport-service-has-hit-production/. There is a video clip with the process of transferring DB contents to Azure Blob storage as BACPAC. After that you can copy the file locally and import it to your SQL instance. Process of importing BACPAC to Data-Tier application is described here: http://msdn.microsoft.com/en-us/library/hh710052.aspx.

    0 讨论(0)
  • 2020-11-28 01:28

    You can use the new Azure Mobile Services to do a nightly backup export from SQL Azure to a .bacpac file hosted in Azure Storage. This solution is 100% cloud, doesn't require a 3rd party tool and doesn't require a local hosted SQL Server instance to download/copy/backup anything.

    There's about 8 different steps, but they're all easy: http://geekswithblogs.net/BenBarreth/archive/2013/04/15/how-to-create-a-nightly-backup-of-your-sql-azure.aspx

    0 讨论(0)
提交回复
热议问题