Join Simon Allardice for an in-depth discussion in this video Creating backups, part of SQL Server 2008 Essential Training.
We have all these great features of SQL Server to keep our data fast and clean. We've got constraints for integrity, transactions, indexes, but at the end of the day all these databases are being stored on files on a hard drive and hard drives break. So even if you've created your database files on a nice RAID 10 unit, you still need to be it backing up and backing up regularly. Or we can do this using SQL Server Management Studio or even just SQL commands. We can get this going.
We backup one database at a time. So open up the databases, select the one you're interested in, not that it really matters, and come down to tasks where you'll find an entry for backup. I select that. The reason why I say it doesn't matter which database you right-click on is because the first question you get in the backup window is which database you're interested in backing up. Most of the time for a straightforward situation, you're going to keep the default values. Really the only choice you're interested in here is this backup type. Is it full or is it deferential? And in fact the first time through the only option you'll be able to do is a full backup.
After you've done one full backup, you can select to do a differential one, which will be smaller in size, because it's essentially the changes between your last full backup and the state of the database right now. The reason that SQL Server is able to do this is because it keeps track of the different backups that you've done. It likes to understand when you did your full backups, when you did your differentials, and one of the impacts of that, I mean that if you're selecting a full backup, you also have this option here to do what's called a Copy Only Backup, which really detaches from the main chain of backups, creating a self-contained one.
You'll notice that you're not able to do a copy only backup when it's differential, because you haven't got anything to make a difference on. So we're going to do a full backup. It's not a copy only, And backing up the database. We can give it a name. I'll accept the default here. There is an expiration option here that the backup set will expire after certain amount of days. If it's zero that just means it won't expire at all. Now this section down here, the destination, this can trick people and trip people up. I've known several people that have been bitten by this.
This is the default location that your backups will go to. It's actually just the path that SQL Server is installed at and we've got a Backup\AdventureWorksLT. bak file. Okay, that's fine. But people see this button. They can click Add and it gives them the ability to add a new path or add a new destination on disk. That looks all right. Here's the issue. If you do this and you can add multiple locations in here to back out to, but it does not copy the backup and duplicate it from place-to-place.
What it will do is almost like a basic RAID pan that will split up the backup across multiple files. Now that means it can be faster, which is a good thing, but it means if you have multiple locations and you have a need to do a restore, you have to get the backup files from every location. So this is not a redundancy option. It's just a speed one. I'm going to click over here on the left to the Options page. Now I've already done a couple of backups, both full and differential, and it's asking me here, do I want to back up to the existing backup set? And yes I do. I'm continuing it but I do have the options where I could say back up to a new media set or overwrite all the old ones.
I do have some options here to verify the backup when finished. Yup, I think I'll do that. Click back to the General page and I'm just going to go for it. Click OK. This is a fairly small database. So it's a pretty quick job, but obviously if you have lots of rows it's going to take a little while to work. That's how you'd get your first backup started. Now your organization may have and hopefully does have a more strategic backup strategy that should include SQL Server. You may have third-party tools that you're dealing with, because backup and restore should really be an enterprise-wide idea.
But if you're going to be involved even in basic administration of SQL Server you certainly want to be comfortable with doing a casual backup.
- Using T-SQL (Transact-SQL)
- Managing databases with SQL Server Management Studio
- Understanding database normalization
- Using SELECT statements
- Building indexes
- Monitoring database size and integrity
- Backing up and restoring databases
- Creating functions and stored procedures
- Managing database permissions
- Creating and formatting reports
- Adding charts to reports
- Creating and executing a simple SSIS package
Skill Level Beginner
Q: I'm having problems installing the free Express R2 version of SQL Server on Windows XP. I tried 64-bit and 32-bit versions. In the videos, the author installs from a DVD. Do I need to do the same?
Q: The link to the installer for the AdventureWorks sample database, as shown in the Chapter 2 movie "Installing sample databases," no longer works. Where can I find the installer?
A: Microsoft has reorganized its site. The sample files are still there, but they're a bit harder to find. To install them:
1) Visit http://msftdbprodsamples.codeplex.com/.
2) Click the link to "SQL Server 2008 R2 OLTP."
3) Click the AdventureWOkrs2008R2 Data File link and agree to the conditions to download the MDF file.
4) Move the MDF file to your SQL Server Directory, usually located at C:\Program Files\Microsfot SQL Server\MSSQL 10_50.MSSQLSERVER\MSSQL\DATA.
5) Open the SQL Sever Management Studio and connect to your instance using an account with administrative privileges.
6) Attach the sample database by right-clicking the Databases folder in the Object Explorer and choosing Attach from the pop-up menu.
7) Click the Add button in the next menu and navigate to the MDF file in the Locate Database Files window that appears. Select it and click OK.
8) Remove the reference to the log file in the "AdventureWorks2008R2" database details: pane by selecting the Log entry and clicking removing.*
9) Click OK to return to SQL Server Management Studio and complete the attachment process.
*MDF files are the "data" files for SQL Server databases. They often come along with LOG files (ldf files). This one didn't so we need to REMOVE the reference to the non-existent log file. Select the second row in the lower section (it should say File Type: Log and Message: Not Found) and click the REMOVE button.
For an illustrated version of these instructions (with screenshots), click here for a PDF version.