How can I backup a remote SQL Server database to a local drive?

前端 未结 23 1270
伪装坚强ぢ
伪装坚强ぢ 2020-11-30 16:20

I need to copy a database from a remote server to a local one. I tried to use SQL Server Management Studio, but it only backs up to a drive on the remote server.

Som

相关标签:
23条回答
  • 2020-11-30 17:00

    In Microsoft SQL Server Management Studio you can right-click on the database you wish to backup and click Tasks -> Generate Scripts.

    This pops open a wizard where you can set the following in order to perform a decent backup of your database, even on a remote server:

    • Select the database you wish to backup and hit next,
    • In the options it presents to you:
      1. In 2010: under the Table/View Options, change 'Script Data' and 'Script Indexes' to True and hit next,
      2. In 2012: under 'General', change 'Types of data to script' from 'Schema only' to 'Schema and data'
      3. In 2014: the option to script the data is now "hidden" in step "Set Scripting Options", you have to click the "Advanced" and set "Types of data to script" to "Schema and data" value
    • In the next four windows, hit 'select all' and then next,
    • Choose to script to a new query window

    Once it's done its thing, you'll have a backup script ready in front of you. Create a new local (or remote) database, and change the first 'USE' statement in the script to use your new database. Save the script in a safe place, and go ahead and run it against your new empty database. This should create you a (nearly) duplicate local database you can then backup as you like.

    If you have full access to the remote database, you can choose to check 'script all objects' in the wizard's first window and then change the 'Script Database' option to True on the next window. Watch out though, you'll need to perform a full search & replace of the database name in the script to a new database which in this case you won't have to create before running the script. This should create a more accurate duplicate but is sometimes not available due to permissions restrictions.

    0 讨论(0)
  • 2020-11-30 17:01

    There is the 99% solution to get bak file from remote sql server to your local pc. I described it there in my post http://www.ok.unsode.com/post/2015/06/27/remote-sql-backup-to-local-pc

    In general it will look like this:

    • execute sql script to generate bak files

    • execute sql script to insert each bak file into temp table with varbinary field type and select this row and download data

    • repeat prev. step as many time as you have bak files

    • execute sql script to remove all temporary resources

    that's it, you have your bak files on your local pc.

    0 讨论(0)
  • 2020-11-30 17:01

    Some third-party backup programs allow setting file transferring with specific network permissions. It it very useful when SQL Server service is running under restricted account and does not have enough network permissions. Try using EMS SQL Backup which solves this task.

    0 讨论(0)
  • 2020-11-30 17:02

    The AppHarbor gang has been struggling with this and has developed a temporary solution using SQL server management objects and SqlBulkCopy.

    Check out their blog post about it, or go straight to the code.

    They've only tested it with AppHarbor but it may be worth checking out.

    0 讨论(0)
  • 2020-11-30 17:04

    I know this is late answer but I have to make a comment about most voted answer that says to use generate scripts option in SSMS.

    Problem with that is this option doesn’t necessarily generate script in correct execution order because it doesn't take dependencies into account.

    For small databases this is not an issue but for larger ones it certainly is because it requires to manually re-order that script. Try that on 500 object database ;)

    Unfortunately in this case the only solution are third party tools.

    I successfully used comparison tools from ApexSQL (Diff and Data Diff) for similar tasks but you can’t go wrong with any other already mentioned here, especially Red Gate.

    0 讨论(0)
  • 2020-11-30 17:05

    Look at this blog for a description how to copy a remote database:

    Backup a SQL Server 2008 Database From a Shared Hosting Environment

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