SQL server Database restore sequence Steps
I have seen many people are still unclear about the database restoration sequence. Recently I have answered number of database restoration questions SSC, MSDN... I have got a comment from Anonymous user.
It’s simple task to the experienced DBA’s. However it’s very important to know the database restoration sequence. It’ll help number of situation.
I have seen many people are still unclear about the database restoration sequence. Recently I have answered number of database restoration questions SSC, MSDN... I have got a comment from Anonymous user.
It’s simple task to the experienced DBA’s. However it’s very important to know the database restoration sequence. It’ll help number of situation.
For example,
Your database got damaged for anyone of the reason. (Or) You may get a request from DEV team to restore a database from production to development.
I already wrote an article about Step by step backup/restore using T-SQL. But it’s not fully focus the restoration sequence.
Here I am going to give you the scripts with explanation and examples too. I hope this will help you.
I have scheduled every Sunday full backup @1 AM (1 AM) and every @6 hours differential backup (daily 2 AM onwards) and every @3 hour log backup (2:30 Am onwards).
Just for giving real time example I have moved the log files from current drive (C) to another one drive (D) and i started the SQL server. I have seen the database that shows without the expandable symbol (i.e +).
Now the database “IMPORTANT_DB” log file has gone on 13 th jun 2011 Monday at 11:40 PM
Now How can i bring the database back to online?
As I already know about my backup policy even though I supposed to check the system tables because where the backup is located and the backup job got succeeded or not.
Here is the script to check the backup details.
SELECT
database_name,[type],backup_finish_date,
(backup_size/1024/1024) size_mb,physical_device_name,
[user_name]
FROM MSDB.DBO.BACKUPSET A JOIN MSDB.DBO.BACKUPMEDIAFAMILY B
ON(a.media_set_id=b.media_set_id) WHERE
DATABASE_NAME in('dbadata')
--type ='d'and
--and backup_finish_date>=getdate()-14
ORDER BY backup_finish_date DESC
It's very important to take the tail log backup before going to do anything. Lets try the tail log backup.
BACKUP LOG [dbadata] TO DISK = N'C:\Backup\dbadata_Taillog.trn' WITH NO_TRUNCATE
Msg 3447, Level 16, State 1, Line 1
Could not activate or scan all of the log files for database 'dbadata'.
Msg 3013, Level 16, State 1, Line 1
BACKUP LOG is terminating abnormally.
In my case,I can’t do the tail log backup.
Check the database if it is online or not using below command.
SELECT state_desc,DB_NAME (database_id) FROM SYS.MASTER_FILES WHERE state_desc <>'ONLINE'
Let me try to access the database
USE DBADATA
Got error I can’t access the database
Msg 945, Level 14, State 2, Line 1
Database 'dbadata' cannot be opened due to inaccessible files or insufficient memory or disk space. See the SQL Server errorlog for details.
Let's check the error log
SP_READERRORLOG
Error: 17207, Severity: 16, State: 1.
FileMgr::StartLogFiles: Operating system error 2(failed to retrieve text for this error. Reason: 15100) occurred while creating or opening file 'XXX \dbadata.ldf'. Diagnose and correct the operating system error, and retry the operation.
File activation failure. The physical file name "XXX dbadata.ldf" may be incorrect.
The log cannot be rebuilt because there were open transactions/users when the database was shutdown, no checkpoint occurred to the database, or the database was read-only. This error could occur if the transaction log file was manually deleted or lost due to a hardware or environment failure.
OK now run the following script and find the backup location.
SELECT
database_name,[type],backup_finish_date,
(backup_size/1024/1024) size_mb,physical_device_name,
[user_name]
FROM MSDB.DBO.BACKUPSET A JOIN MSDB.DBO.BACKUPMEDIAFAMILY B
ON(a.media_set_id=b.media_set_id) WHERE
DATABASE_NAME in('dbadata')
--type ='d'and
--and backup_finish_date>=getdate()-14
ORDER BY backup_finish_date DESC
Backup details from the scripts for that particular DB
Backup Device | Type |
Y:\Backup\dbadata_full_12_jun_2011_1AM.bak | Full |
Y:\Backup\dbadata_Diff_13_jun_2011_2AM.bak | Differential |
Y:\Backup\dbadata_Diff_13_jun_2011_8AM.bak Y:\Backup\dbadata_Diff_13_jun_2011_2PM.bak | Differential Differential |
Y:\Backup\dbadata_Diff_13_jun_2011_8PM.bak | Differential |
Y:\Backup\dbadata_log_13_jun_2011_230AM.trn | Log |
Y:\Backup\dbadata_log_13_jun_2011_530AM.trn | Log |
Y:\Backup\dbadata_log_13_jun_2011_830AM.trn | Log |
Y:\Backup\dbadata_log_13_jun_2011_1130AM.trn | Log |
Y:\Backup\dbadata_log_13_jun_2011_230PM.trn | Log |
Y:\Backup\dbadata_log_13_jun_2011_530PM.trn | Log |
Y:\Backup\dbadata_log_13_jun_2011_830PM.trn | Log |
Y:\Backup\dbadata_log_13_jun_2011_1130PM.trn | Log |
Steps to restore the database using available backups.
RESTORE FILELISTONLY FROM DISK ='Y:\Backup\dbadata_full_12_jun_2011_1AM.bak'
First put the database in single user mode by using the below command.
ALTER DATABASE DBAdata SET SINGLE_USER WITH ROLLBACK IMMEDIATE
Here i am going to overwrite (replace) the database. If you want you can leave the damaged database and restore a new one.
Restore the latest full database backup has done on Sunday with norecovery option.
Restore the latest full database backup has done on Sunday with norecovery option.
RESTORE DATABASE DBAdata FROM DISK ='Y:\Backup\dbadata_full_12_jun_2011_1AM.bak'
WITH replace,norecovery
Next run the latest differential backup done on Monday at 8 PM with norecovery option.
RESTORE DATABASE DBAdata FROM DISK ='Y:\Backup\dbadata_Diff_13_jun_2011_8PM.bak'
WITH norecovery
Then lastly run the log backup one by one done on Monday after the differential backup.
RESTORE DATABASE DBAdata FROM DISK ='Y:\Backup\dbadata_log_13_jun_2011_830PM.trn'
with norecovery
RESTORE DATABASE DBAdata FROM DISK ='Y:\Backup\dbadata_log_13_jun_2011_1130PM.trn'
WITH recovery
If you missed anyone of the previous log backup then you will get this error. That’s why people are recommended to keep all log backup safely.
Msg 4305, Level 16, State 1, Line 2
The log in this backup set begins at LSN 3873000000044400001, which is too recent to apply to the database. An earlier log backup that includes LSN 3873000000042400001 can be restored.
Msg 3013, Level 16, State 1, Line 2
RESTORE DATABASE is terminating abnormally.
What was given just an example.
Symantec Norton Ghost 15.0 (1 PC)

What was given just an example.
Symantec Norton Ghost 15.0 (1 PC)
