by http://webgeektutorials.blogspot.com

Monday, September 19, 2011

Sql Server : How to Point in time recovery

SQL Server offers the ability to do point in time restores of your data in order to restore your database back to the point right before that detrimental command was issued. 
Point in time recovery option which helped us to restore our database without losing a single record to a specific time.Process we followed was :
  • Must be in FULL RECOVERY MODEL
  • Must have a valid FULL BACKUP
Check current recovery model of your database :

SELECT name,recovery_model_desc
FROM sys.databases
1.You can change recovery model from SSMS by right click on your desired database.
2.click properties, on left, select options and change recovery model.
Or
you can do it with following tsql.
USE [master]
GO
ALTER DATABASE [MYDB] SET RECOVERY FULL WITH NO_WAIT
How to check backup history?? [ Click Here  ]

BACKUP LOG [MYDB] TO DISK = 'E:\EmergencyLogBackup.trn' WITH
NOFORMAT, NOINIT, NAME = 'MYDB-Transaction Log  Backup', SKIP,
NOREWIND, NOUNLOAD, STATS = 10  
Create a full backup of database for safe side:
Restore your full database backup BUT with “RESTORE WITH NORECROVERY” option
Now restore your currently created Transaction Log Backup, with “WITH RECOVERY” option, BUT up to your desired time. In our example we will restore our Transaction Log file up to 12:30:00PM.

RESTORE LOG [MYDB]
FROM DISK = 'E:\EmergencyLogBackup.trn'
WITH RECOVERY,
STOPAT = 'Sep 03, 2011 12:30:00 PM'

If you already have transaction log backup/s taken between your point of problem and Full Back. Restore your full back and then restore rest of your intermediate backups (Differential or Log) BUT all with “RESTORE WITH NORECROVERY” option. At the end restore your transaction log backup which you have created after PROBLEM OCCURRED, with “WITH RECOVERY” option.

No comments:

Post a Comment