IT tutorials
 
Database
 

SQL Server 2008 R2 : Database Backup and Restore (part 4) - Backing Up a Database

11/17/2012 5:02:56 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
Now that you know the types of backups, the recovery models they relate to, and the devices you can write to, you are ready to back up your database. You can create backups with SQL Server 2008 by using either the SSMS or T-SQL. Some backups are supported only through T-SQL, but the vast majority can be accomplished with either tool.

Creating Database Backups with SSMS

The backup options in SSMS are accessible through the Object Explorer. For example, you can right-click the AdventureWorks2008 database in the SSMS Object Explorer, select Tasks and Backup, and a backup window like the one shown in Figure 2 appears.

Figure 2. The Back Up Database window in SSMS.

The Source section on the Back Up Database window contains information relative to the database that will be backed up. The target database is displayed in the first drop-down, along with the recovery model set for the database. The backup types available in the drop-down are dependent on the recovery model. For simple recovery, only full and differential backup types are available. For full recovery and bulk-logged recovery models, all backup types are available in the drop-down.

The Backup Set section allows you to give the backup a meaningful name and specify when the backup set will expire. When the backup set expires, the backup can be overwritten and is no longer retained. If the backup is set to expire after 0 days, it will never expire.

The Destination section identifies the disk or tape media that will contain the backup. You can specify multiple destinations in this section by clicking the Add button. For disk media, you can specify a maximum of 64 disk devices. The same limit applies to tape media. If multiple devices are specified, the backup information is spread across those devices. All the devices must be present for you to be able to restore the database. If no tape devices are attached to the database server, the Tape option is disabled.

You can select several different types of options for a database backup. Figure 3 shows the options page available when you back up a database by using SSMS.

Figure 3. The Back Up Database Options page in SSMS.

The Overwrite Media section allows you to specify options relative to the destination media for the backup. Keep in mind that a given media set can contain more than one backup. This can occur if the Append to the Existing Backup Set options is selected. With this option, any prior backups contained on the media set are preserved, and the new backup is added to it. With the Overwrite All Existing Backup Sets option, the media set contains only the latest backup, and no prior backups are retained.

You can use the options in the Reliability section to ensure that the backup that has been created can be used reliably in a restore situation. Verifying the backup when finished is highly recommended, but doing so causes the backup time to be extended during the verification. Similarly, the Perform Checksum Before Writing to Media option helps ensure that you have a sound backup, but again, it causes the database backup to run longer.

The options in the Transaction Log section are available for databases in the full recovery or bulk-logged model. These options are disabled in the simple recovery model. The Truncate the Transaction Log option causes any inactive portion of the transaction log to be removed after the database backup is complete.

The set of options in the Tape Drive section are enabled only when tape has been selected for the destination media. Selecting the Unload the Tape After Backup option causes the media tape to be ejected when the backup completes. This option can help identify the end of a backup and prevent the tape from being overwritten the next time the backup runs. The Rewind the Tape Before Unloading option is self-explanatory; it causes the tape to be released and rewound before you unload the tape. The last set of options relate to compressed database backups.

Note

Keep in mind that all backups can be performed while the database is in use. SQL Server is able to keep track of the changes occurring during the backup and can maintain transactional consistency as of the end of the backup. You need to consider some performance overhead during the actual backup, but the backup can occur during active database hours. However, it is still a good idea to schedule your database backups during off-hours, when database activity is at a minimum.


Creating Database Backups with T-SQL

The T-SQL BACKUP command offers a myriad of options to perform all the backup operations available in SSMS. However, SSMS does not support some backup operations that can be performed only with T-SQL.

The BACKUP command comes in three different flavors. The first flavor involves the backup of a database. The command syntax starts with BACKUP DATABASE, followed by the relevant parameters and options. The second flavor involves the backup of a file or filegroup that is part of the database. The command syntax for this type of backup also utilizes the BACKUP DATABASE command, but a file or filegroup is specified after the database name to identify which parts of the database should be backed up. The last flavor involves the backup of the database’s transaction log. The syntax for backing up the transaction log starts with BACKUP LOG. Each flavor shares many of the same options. The basic syntax for backing up a database follows:

BACKUP DATABASE { database_name | @database_name_var }
TO < backup_device > [ ,...n ]
[ [ MIRROR TO < backup_device > [ ,...n ] ] [ ...next-mirror ] ]
[ WITH
     [ BLOCKSIZE = { blocksize | @blocksize_variable } ]
     [ [ , ] { CHECKSUM | NO_CHECKSUM } ]
     [ [ , ] COMPRESSION | NO_COMPRESSION]
     [ [ , ] COPY_ONLY ]
     [ [ , ] { STOP_ON_ERROR | CONTINUE_AFTER_ERROR } ]
     [ [ , ] DESCRIPTION = { 'text' | @text_variable } ]
     [ [ , ] DIFFERENTIAL ]
     [ [ , ] EXPIREDATE = { date | @date_var }
     | RETAINDAYS = { days | @days_var } ]
     [ [ , ] PASSWORD = { password | @password_variable } ]
     [ [ , ] { FORMAT | NOFORMAT } ]
     [ [ , ] { INIT | NOINIT } ]
     [ [ , ] { NOSKIP | SKIP } ]
     [ [ , ] MEDIADESCRIPTION = { 'text' | @text_variable } ]
     [ [ , ] MEDIANAME = { media_name | @media_name_variable } ]
     [ [ , ] MEDIAPASSWORD = { mediapassword | @mediapassword_variable } ]
     [ [ , ] NAME = { backup_set_name | @backup_set_name_var } ]
     [ [ , ] { NOREWIND | REWIND } ]
     [ [ , ] { NOUNLOAD | UNLOAD } ]
     [ [ , ] RESTART ]
     [ [ , ] STATS [ = percentage
 ] ]
]


					  

The number of options is extensive, but many of them are optional. A BACKUP DATABASE command can be as simple as the following example:

BACKUP DATABASE [AdventureWorks2008]
 TO  DISK = N'C:\mssql2008\backup\AdventureWorks2008_COPY.bak'

The first part of the BACKUP command is related to the database you want to back up (database_name), followed by the location to which you want to write the backup (backup_device). The remainder of the syntax relates to the options that can be specified following the WITH clause. These options determine how your backup will be created and the properties of the resulting backup. Table 1 outlines these options.

Table 1. BACKUP DATABASE Options
OptionDescription
BLOCKSIZEThe physical block size that will be used to create the backup. The default is 64KB.
CHECKSUM | NO_CHECKSUMWhen CHECKSUM is specified, a checksum is calculated before the backup is written to validate that the backup is not corrupt. The default is NO_CHECKSUM.
COMPRESSION | NO_COMPRESSIONThis new option in SQL Server 2008, available only with the Enterprise or Developer Edition, causes the backup file to be compressed. The default is NO_COMPRESSION.
STOP_ON_ERROR | CONTINUE_AFTER_ERRORThis option is used in conjunction with the CHECKSUM option. The STOP_ON_ERROR option, which is the default, causes the backup to fail if the checksum cannot be validated.
DESCRIPTIONThis is a 255-character description of the backup set.
DIFFERENTIALThis option causes a differential backup to occur, which captures changes only since the last backup.
EXPIREDATEThis option specifies the date on which the backup set will expire and be overwritten.
RETAINDAYSThis option specifies the number of elapsed days before the backup set can be overwritten.
PASSWORDThis is a password that must be specified when restoring the backup set.
FORMAT | NOFORMATFORMAT causes the existing media header and backup set to be overwritten. The default is NOFORMAT.
INIT | NOINITThe INIT option causes a backup set to be overwritten. The backup set is not overwritten if the backup set has not expired or if it does not match the media name specified with the NAME option. NOINIT, which is the default, causes the backup set to be appended to the existing media.
NOSKIP | SKIPNOSKIP, which is the default, allows backup sets to be overwritten if they have expired. The SKIP option skips expiration and media name checks and is used to prevent the overwriting of backup sets.
MEDIADESCRIPTIONThis is a 255-character description for the entire backup media containing the backup sets.
MEDIANAMEThis is a 128-character name for the backup media. If it is specified, the target media must match this name.
MEDIAPASSWORDThis is a password for the media set. When media is created with this password, the password must be supplied to be able to create a backup set on that media or to restore from that media.
NAMEThis is a 128-character name for the backup set.
NOREWIND | REWINDThis option is used for tape operations. REWIND, which is the default, causes the tape to be released and rewound after it fills.
NOUNLOAD | UNLOADThis option is used for tape operations. NOUNLOAD, which is the default, causes the tape to remain in the tape drive after a backup completes. UNLOAD causes the tape to be rewound and unloaded when the backup completes.
RESTARTThis option has no effect and is in place only for backward compatibility.
STATSThis option causes completion statistics to be displayed at the specified interval to assess progress.
COPY_ONLYThis option allows a backup to be made without affecting the normal sequence of backups.
 
Others
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us