SQL - Backup SQL database

I would like to move the MS SQL Server 2008 database from my labtop to a VM,  How should I backup so I can restore later within the VM with proper security permission?
tommym121Asked:
Who is Participating?
 
David DavidsonCommented:
Run Microsoft SQL Server Management Studio, connect to your SQL Server 2008 physical server, create a New Query, and type the following, substituting for your database name:

BACKUP DATABASE <database name> TO DISK='Database Backup 2013-01-18.bak' WITH FORMAT

Replace the file name with something that makes sense to you.  You can even specify a path, but the service account that SQL Server is running under must have access to the path.

The WITH FORMAT option will not format your hard drive, it will merely ensure that a current file, if it exists, is overwritten instead of appended to.

Access your SQL Server and copy the file.  Be default, the file will be in Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Backup.  The location path may be slightly different if you're using a named instance.  Copy the file to your VM, being sure to copy either to a location that SQL Server instance has access to or to the default backup folder.

Run SQL Server Management Studio, connect to the SQL Server on your VM, create a New Query, and type the following:

RESTORE DATABASE <database name> FROM DISK='Database Backup 2013-01-18.bak' WITH REPLACE

You may get errors complaining about currently existing .mdf and/or .ldf files, or complaining about a path not existing when attempting to create an .mdf or .ldf file.  If so, add some MOVE statements, like this:

RESTORE DATABASE <database name> FROM DISK='Database Backup 2013-01-18.bak'
WITH REPLACE,
MOVE '<database logical name>' TO '<database physical name>',
MOVE '<log logical name>' TO '<log physical name>'

The logical names will be included in the error you get.  The physical names usually mirror the database name and the physical path is usually Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Data.

NOTE: The Recovery Model affects the size of the backup file.  If using the Simple Recovery Model, the backup file will always be as small as possible.  If using the Full Recovery Model, the backup file will include all log transactions and empty space - the backup file size will reflect the size of the database files, regardless if data is in that space or not.  You may want to shrink your database before backing it up if using the Full Recovery Model.

To check your Recovery Model, run Microsoft SQL Server Management Studio, connect to your SQL Server, expand Databases, right-click your database, click Properties, and click Options.  To shrink a database, connect to it with Management Studio, right-click it, click Tasks, Shrink, Database.

Hope this helps.
0
 
ITguy565Commented:
This site should tell you everything you need to know in a tutorial format.

http://www.databasejournal.com/features/mssql/article.php/3773176/SQL-2008-Backup-and-Restore-Part-1.htm
0
 
ZberteocCommented:
The simplest way is to detach the database from your original server:

1. In Management Studio(MS) expand the database folder and right click on the database name ?> Task > Detach > in the window that opens click OK.

2. Copy the database files, mdb, ndx, and log (most likelly you only have .mdb and .log files) in the data folder on the new server


And then attach it to the new server:

3. Connect in MS to the new server, right click on the database folder > Attach > In the window that opens click Add > click on the .mdf file of your database and then OK.

Done. The database even if it doesn't exist will be created and made available on the new server.

Last thing is to make sure that all the users that need access to it will be given permissions. Create a login if it doesn't exist and then map it to the database.
0
 
Jim P.Commented:
0
 
tommym121Author Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.