做好如上两个设置,数据库误删后找回数据就会非常轻松,现在说一下如何还原sqlserver数据到故障点。
二、还原命令
还原主要分为四步走:
1、出现故障后,首先执行备份事务日志命令,这里以AdventureWorks作为数据库名。命令如下:
BACKUP LOG AdventureWorks TO DISK = 'C:\SQLServerBackups\AdventureWorks_transcationlog.bak' WITH NORECOVERY;
2、从完整备份还原数据
RESTORE DATABASE [QASupervision] FROM DISK='M:\Database\OA\AdventureWorks_Fullbackup_2014_03_18_010002_0155764.bak' WITH NORECOVERY, REPLACE
3、从差异备份还原数据
RESTORE DATABASE [QASupervision] FROM DISK='M:\Database\OA\AdventureWorks_diffbackup_2014_03_18_020002_0155764.bak' WITH NORECOVERY, REPLACE
4、从事务日志还原数据,还原到某个时间点之前
DECLARE @dt datetime SELECT @dt=DATEADD(HOUR,-16,GETDATE()) select @dt RESTORE LOG [QASupervision] FROM DISK='C:\SQLServerBackups\AdventureWorks_transcationlog.bak' WITH STOPAT=@dt,RECOVERY
5、还原数据库,如果数据库提示正在还原中,则执行此命令即可。
RESTORE DATABASE AdventureWorks WITH RECOVERY