Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL - Backup SQL database

Posted on 2013-01-18
5
Medium Priority
?
340 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 400 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 600 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 600 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 400 total points
ID: 38797612
0
 

Author Closing Comment

by:tommym121
ID: 38807507
Thanks
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

636 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