Solved

SQL - Backup SQL database

Posted on 2013-01-18
5
330 Views
Last Modified: 2013-01-22
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?
0
Comment
Question by:tommym121
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 11

Assisted Solution

by:itguy565
itguy565 earned 100 total points
ID: 38794952
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
 
LVL 1

Accepted Solution

by:
David Davidson earned 150 total points
ID: 38794990
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
 
LVL 27

Assisted Solution

by:Zberteoc
Zberteoc earned 150 total points
ID: 38795337
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
 
LVL 38

Assisted Solution

by:Jim P.
Jim P. earned 100 total points
ID: 38797612
0
 

Author Closing Comment

by:tommym121
ID: 38807507
Thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question