Solved

SQL - Backup SQL database

Posted on 2013-01-18
5
316 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
5 Comments
 
LVL 11

Assisted Solution

by:itguy565
itguy565 earned 100 total points
Comment Utility
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
Comment Utility
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 26

Assisted Solution

by:Zberteoc
Zberteoc earned 150 total points
Comment Utility
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
Comment Utility
0
 

Author Closing Comment

by:tommym121
Comment Utility
Thanks
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now