且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将远程SQL Server数据库备份到本地驱动器?

更新时间:2023-02-02 15:33:37

在Microsoft SQL Server Management Studio中,您可以右键单击要备份的数据库,然后单击任务->生成脚本".

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. 2010年:在表/视图"选项下,将脚本数据"和脚本索引"更改为True,然后单击下一步,
  2. 2012年:在常规"下,将数据类型为脚本"从仅模式"更改为模式和数据"
  3. 在2014年:现在,在设置脚本选项"步骤中隐藏"脚本数据的选项,您必须单击高级",并将脚本的数据类型"设置为架构和数据"值

  • 在接下来的四个窗口中,点击全选",然后点击下一步,
  • 选择脚本编写到新的查询窗口
  • In the next four windows, hit 'select all' and then next,
  • Choose to script to a new query window
  • 完成操作后,您将准备好一个备份脚本.创建一个新的本地(或远程)数据库,并在脚本中更改第一个"USE"语句以使用您的新数据库.将脚本保存在安全的地方,然后继续对新的空数据库运行该脚本.这将为您创建一个(几乎)重复的本地数据库,然后您可以根据需要进行备份.

    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.

    如果您具有对远程数据库的完整访问权限,则可以选择在向导的第一个窗口中检查脚本所有对象",然后在下一个窗口中将脚本数据库"选项更改为True. .请注意,您需要执行完整的搜索和&将脚本中的数据库名称替换为新数据库,在这种情况下,您无需在运行脚本之前创建数据库.这样可以创建更准确的副本,但由于权限限制,有时无法使用.

    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.