You cannot restore the backup of a compressed database to an uncompressed database.
During an offline restore, if the specified database is in use, RESTORE forces the users off after a short delay. For online restore of a non-primary filegroup, the database can stay in use except when the filegroup being restored is being taken offline. Any data in the specified database is replaced by the restored data.
For more information about database recovery, see Understanding How Restore and Recovery of Backups Work in SQL Server and Implementing Restore Scenarios for SQL Server Databases.
Cross-platform restore operations, even between different processor types, can be performed as long as the collation of the database is supported by the operating system.
RESTORE can be restarted after an error. In addition, you can instruct RESTORE to continue despite errors, and it restores as much data as possible (see the CONTINUE_AFTER_ERROR option). For more information, see Responding to SQL Server Restore Errors Caused by Damaged Backups.
RESTORE is not allowed in an explicit or implicit transaction.
Restoring a damaged master database is performed using a special procedure. For more information, see Considerations for Restoring the master Database.
Backups created with Microsoft SQL Server cannot be restored to an earlier version of SQL Server.
Restoring a database clears the plan cache for the instance of SQL Server. Clearing the plan cache causes a recompilation of all subsequent execution plans and can cause a sudden, temporary decrease in query performance. As of SQL Server 2005 Service Pack 2, for each cleared cachestore in the plan cache, the SQL Server error log contains the following informational message: "SQL Server has encountered %d occurrence(s) of cachestore flush for the '%s' cachestore (part of plan cache) due to some database maintenance or reconfigure operations". This message is logged every five minutes as long as the cache is flushed within that time interval.
The database being restored must be at least version 80 (SQL Server 2000) to restore to SQL Server 2008. SQL Server 2000 or SQL Server 2005 databases that have a compatibility level less than 80 will be set to compatibility 80 when restored.
Note: |
|---|
|
After you restore a SQL Server 2005 or SQL Server 2000 database to SQL Server 2008, the database becomes available immediately and is then automatically upgraded. If the database has full-text indexes, the upgrade process either imports, resets, or rebuilds them, depending on the setting of the upgrade_optionserver property. If the upgrade option is set to import (upgrade_option = 2) or rebuild (upgrade_option = 0), the full-text indexes will be unavailable during the upgrade. Depending the amount of data being indexed, importing can take several hours, and rebuilding can take up to ten times longer. When the upgrade option is set to import, the associated full-text indexes are rebuilt if no full-text catalog is available. To change the setting of the upgrade_option server property, use sp_fulltext_service.
|
Restore Scenarios
SQL Server supports a variety of restore scenarios:
-
Complete database restore
Restores the entire database, beginning with a full database backup, which may be followed by restoring a differential database backup (and log backups). For more information, see Performing a Complete Database Restore (Simple Recovery Model) or Performing a Complete Database Restore (Full Recovery Model).
-
File restore
Restores a file or filegroup in a multi-filegroup database. Note that under the simple recovery model, the file must belong to a read-only filegroup. After a full file restore, a differential file backup can be restored. For more information, see Performing File Restores (Full Recovery Model) and Performing File Restores (Simple Recovery Model).
-
Page restore
Restores individual pages. Page restore is available only under the full and bulk-logged recovery models. For more information, see Performing Page Restores.
-
Piecemeal restore
Restores the database in stages, beginning with the primary filegroup and one or more secondary filegroups. A piecemeal restore begins with a RESTORE DATABASE using the PARTIAL option and specifying one or more secondary filegroups to be restored. For more information, see Performing Piecemeal Restores.
-
Recovery only
Recovers data that is already consistent with the database and needs only to be made available. For more information, see Recovering a Database Without Restoring Data.
-
Transaction log restore.
Under the full or bulk-logged recovery model, restoring log backups is required to reach the desired recovery point. For more information about restoring log backups, see Applying Transaction Log Backups.
-
Create a mirror database.
For more information, see How to: Prepare a Mirror Database for Mirroring (Transact-SQL).
-
Create and maintain a standby server. For more information about standby servers, see Using Warm Standby Servers.
Discontinued RESTORE Keywords
The following keywords have been discontinued in SQL Server 2008:
|
Discontinued keyword
|
Replaced by…
|
Example of replacement keyword
|
|---|
|
LOAD
|
RESTORE
|
RESTORE DATABASE
|
|
TRANSACTION
|
LOG
|
RESTORE LOG
|
|
DBO_ONLY
|
RESTRICTED_USER
|
RESTORE DATABASE ... WITH RESTRICTED_USER
|
Requirement for Restoring an Encrypted Database
To restore a database that is encrypted, you must have access to the certificate or asymmetric key that was used to encrypt the database. Without the certificate or asymmetric key, the database cannot be restored. As a result, the certificate that is used to encrypt the database encryption key must be retained as long as the backup is needed. For more information, see SQL Server Certificates and Asymmetric Keys.
Databases Enabled for vardecimal Storage Format
Comparison of RECOVERY and NORECOVERY
Roll back is controlled by the RESTORE statement through the [ RECOVERY | NORECOVERY ] options:
-
NORECOVERY specifies that roll back not occur. This allows roll forward to continue with the next statement in the sequence.
In this case, the restore sequence can restore other backups and roll them forward.
-
RECOVERY (the default) indicates that roll back should be performed after roll forward is completed for the current backup.
Recovering the database requires that the entire set of data being restored (the roll forward set) is consistent with the database. If the roll forward set has not been rolled forward far enough to be consistent with the database and RECOVERY is specified, the Database Engine issues an error.
Redoing a Restore
Undoing the effects of a restore is not possible; however, you can negate the effects of the data copy and roll forward by starting over on a per-file basis. To start over, restore the desired file and perform the roll forward again. For example, if you accidentally restored too many log backups and overshot your intended stopping point, you would have to restart the sequence.
A restore sequence can be aborted and restarted by restoring the entire contents of the affected files.
Restore Full-Text Data
Full-text data is restored together with other database data during a complete restore. Using the regular RESTORE DATABASE database_name FROM backup_device syntax, the full-text files are restored as part of the database file restore.
The RESTORE statement also can be used to perform restores to alternate locations, differential restores, file and filegroup restores, and differential file and filegroup restores of full-text data. In addition, RESTORE can restore full-text files only, as well as with database data.
Note: |
|---|
|
Full-text catalogs imported from SQL Server 2005 or SQL Server 2000 are still treated as database files. For these, the SQL Server 2005 procedure for backing up full-text catalogs remains applicable, except that pausing and resuming during the backup operation are no longer necessary. For more information, see Backing Up and Restoring Full-Text Catalogs in SQL Server 2005 Books Online.
|
Database Settings and Restoring
During a restore, most of the database options that are settable using ALTER DATABASE are reset to the values in force at the time of the end of backup.
Note: |
|---|
|
This behavior differs from versions of SQL Server before SQL Server 2000.
|
Using the WITH RESTRICTED_USER option, however, overrides this behavior for the user access option setting. This setting is always set following a RESTORE statement, which includes the WITH RESTRICTED_USER option.
Backup and Restore History Tables
SQL Server includes backup and restore history tables that track the backup and restore activity for each server instance. When a restore is performed, the backup history tables are also modified. For information on these tables, see Viewing Information About Backups.
RESTORE LOG
RESTORE LOG can include a file list to allow for creation of files during roll forward. This is used when the log backup contains log records written when a file was added to the database.
Note: |
|---|
|
For a database using the full or bulk-logged recovery model, in most cases you must back up the tail of the log before restoring the database. Restoring a database without first backing up the tail of the log results in an error, unless the RESTORE DATABASE statement contains either the WITH REPLACE or the WITH STOPAT clause, which must specify a time or transaction that occurred after the end of the data backup. For more information about tail-log backups, see Tail-Log Backups.
|
Online Restore
Note: |
|---|
|
Online restore is allowed only in SQL Server 2005 Enterprise Edition and later versions.
|
Where online restore is supported, if the database is online, file restores and page restores are automatically online restores and, also, restores of secondary filegroup after the initial stage of a piecemeal restore.
For more information, see Performing Online Restores.
Piecemeal Restore
Piecemeal restore, which was new in SQL Server 2005, enhances Microsoft SQL Server 2000 partial restore. Piecemeal restore allows filegroups to be restored after an initial, partial restore of the primary and some of the secondary filegroups. Filegroups that are not restored are marked as offline and are not accessible. The offline filegroups, however, can be restored later by a file restore. To allow the entire database to be restored in stages at different times, piecemeal restore maintain checks to ensure that the database will be consistent in the end.
Note: |
|---|
|
In SQL Server 2000, a partial restore can only be done from a full database backup. This restriction was removed in SQL Server 2005.
|
If a partial restore sequence excludes any FILESTREAM filegroup, point-in-time restore is not supported. You can force the restore sequence to continue. However, the FILESTREAM filegroups that are omitted from your RESTORE statement can never be restored. To force a point-in-time restore, specify the CONTINUE_AFTER_ERROR option together with the STOPAT, STOPATMARK, or STOPBEFOREMARK option, which you must also specify in your subsequent RESTORE LOG statements. If you specify CONTINUE_AFTER_ERROR, the partial restore sequence succeeds and the FILESTREAM filegroup becomes unrecoverable.
For more information about piecemeal restore, see Performing Piecemeal Restores.
Reverting a Database to a Database Snapshot
A revert database operation (specified using the DATABASE_SNAPSHOT option) takes a full source database back in time by reverting it to the time of a database snapshot, that is, overwriting the source database with data from the point in time maintained in the specified database snapshot. Only the snapshot to which you are reverting can currently exist. The revert operation then rebuilds the log (therefore, you cannot later roll forward a reverted database to the point of user error).
Data loss is confined to updates to the database since the snapshot's creation. The metadata of a reverted database is the same as the metadata at the time of snapshot creation. However, reverting to a snapshot drops all the full-text catalogs.
Reverting from a database snapshot is not intended for media recovery. Unlike a regular backup set, the database snapshot is an incomplete copy of the database files. If either the database or the database snapshot is corrupted, reverting from a snapshot is likely to be impossible. Furthermore, even when possible, reverting in the event of corruption is unlikely to correct the problem.
Restrictions on Reverting
Reverting is unsupported under the following conditions:
-
The source database contains any read-only or compressed filegroups.
-
Any files are offline that were online when the snapshot was created.
-
More than one snapshot of the database currently exists.
For more information, see Reverting to a Database Snapshot.