Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Sql Server Backup on Local Machine

I am using SQL Server Management Studio running on my local machine.

I can log on to a remote box (database engine) and use the Studio to create a database backup which is saved to a drive on the remote box.

How do I get it to save the backup to a drive on my local machine?

like image 758
tinyJoe Avatar asked Jan 25 '10 08:01

tinyJoe


People also ask

How do I create a SQL Server database on my local machine?

Use SQL Server Management StudioIn Object Explorer, connect to an instance of the SQL Server Database Engine and then expand that instance. Right-click Databases, and then select New Database. In New Database, enter a database name.

How do I create a backup database in SQL Server?

Restore the database from a BAK fileRight-click on the database server in the left navigation pane, click Tasks, click Restore. The name of the restoring database appears in the To database list box. To create a new database, enter its name in the list box. Select 'From device'.

How copy SQL database from server to local machine?

First of all, launch the SQL Server Management Studio from Object Explorer and connect to the Source Server. Right-click on the database, select the option Tasks and then choose the Copy Database option. After clicking on the Copy Database Wizard then, the following screen will appear. Press the Next button.


2 Answers

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: In 2010: under the Table/View Options, change 'Script Data' and 'Script Indexes' to True and hit next, In 2012: under 'General', change 'Types of data to script' from 'Schema only' to 'Schema and data' 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.

like image 68
rohit patil Avatar answered Oct 18 '22 14:10

rohit patil


See this MSDN article, for the section on backing up to a network share, e.g.:

BACKUP DATABASE YourDatabase
   TO DISK = '\\SomeMachine\Backups\YourDatabase.Bak';

Backing Up to a File on a Network
Share For SQL Server to access a remote disk file, the SQL Server service account must have access to the network share. This includes having the permissions needed for backup operations to write to the network share and for restore operations to read from it. The availability of network drives and permissions depends on the context is which SQL Server service is running:

  • To back up to a network drive when SQL Server is running in a domain user account, the shared drive must be mapped as a network drive in the session where SQL Server is running. If you start Sqlservr.exe from command line, SQL Server sees any network drives you have mapped in your login session.
  • When you run Sqlservr.exe as a service, SQL Server runs in a separate session that has no relation to your login session. The session in which a service runs can have its own mapped drives, although it usually does not.
  • You can connect with the network service account by using the computer account instead of a domain user. To enable backups from specific computers to a shared drive, grant access to the computer accounts. As long as the Sqlservr.exe process that is writing the backup has access, it is irrelevant whether the user sending the BACKUP command has access.
like image 39
AdaTheDev Avatar answered Oct 18 '22 15:10

AdaTheDev