/*
Restore相当于从备份集中重建整个或者部分数据库.
Recovery 则是将数据库从脱机状态恢复到联机状态中供用户使用.
一旦对数据库进行了Recovery,则将无法再进行Restore操作.

Recovery在SQL Server启动时也会发生,在数据库启动过程中,SQL Server会检查事务日志,
看是否存在已提交或未提交的事务,如果发现在最后一次检查点发生后,还有已提交的事务,
则SQL Server会对这些事务进行REDO(ROLL FORWARD);而如果发现未提交的事务,则进行UNDO(ROLL BACK)

*/


-- 数据库恢复
RESTORE DATABASE PartDB FROM PartDBdev WITH RECOVER


-- 恢复时指定数据库文件生成位置
RESTORE DATABASE PartDB
FROM DISK='I:\sqlserver\diskbackup\Part.bak'
WITH
MOVE 'PartDB'TO 'D:\MSSQL\Data\PartDB.mdf',
MOVE 'PartDB_Log' TO 'D:\MSSQL\Data\PartDB.ldf'
WITH RECOVERY


-- 恢复到指定时间点
RESTORE DATABASE PartDB
FROM DISK='I:\sqlserver\diskbackup\Part.bak'
WITH NORECOVERY

RESTORE LOG PartDB
FROM DISK='I:\sqlserver\diskbackup\Part_log.trn'
WITH RECOVERY,STOPAT 'jan 11,2012 8:00pm'


-- 恢复到指定日志序列号
RESTORE DATABASE PartDB
FROM DISK='I:\sqlserver\diskbackup\Part.bak'
WITH NORECOVRY

RESTORE LOG PartDB
FROM DISK='I:\sqlserver\diskbackup\Part_log.trn'
WITH RECOVRY,STOPATMARK LSN:2433:5422


-- 条带备份恢复
RESTORE DATABASE PartDB
FROM
DISK='I:\sqlserver\diskbackup\Part.bak',
DISK='J:\sqlserver\diskbackup\PartDB\Part.bak'
WITH NORECOVRY


-- 数据页恢复(DBCC CHECKDB)
RESTORE DATABASE PartDB PAGE '20:1570,20:1571,20:1572'
FROM DISK='I:\sqlserver\diskbackup\Part.bak'
WITH NORECOVRY