Restores Concept
Restores Concept
Restore Scenarios:-
1) Complete Database Restore (Point of Failure) ***
DB Crashed on Thursday 4:45PM IST
1) Take Tail Log Backup (if successfull, last 45 minutes of log records can be backed up)
Full Backup - 1, Differential Backup - 1, Tlog Backups - 6, Tail Log Backup - 1
2) Restore Full Backup WITH NORECOVERY
3) Restore recent Diff Backup (Wednesday 9:00) WITH NORECOVERY
4) Restore all the Log Backups from 9:00 Wednesday to 15:00 WITH NORECOVERY
5) Restore Tail Log Backup WITH RECOVERY
Backup Steps
CREATE DATABASE FRIENDSHIP
USE FRIENDSHIP
GO
--1,00,003 Records before Diff1 Backup, so Diff1 Backup takes --backup of two records
only.
BACKUP DATABASE Friendship
TO DISK=N'C:\Backups\Friendship_Diff1.bak'
WITH DIFFERENTIAL
----1,00,007 Records -> Last two Log Records after Tlog1 and before Tlog2 Backup will
be backup up.
BACKUP LOG Friendship
TO DISK=N'C:\Backups\Friendship_Log2.trn'
---:Restore Steps:---
RESTORE DATABASE [Friendship]
FROM DISK = N'C:\Backups\Friendship_Full.bak'
WITH MOVE N'Friendship' TO N'C:\Backup\Friendship.mdf',
MOVE N'Friendship_log' TO N'P:\Backup\Friendship.ldf',
NORECOVERY, REPLACE, STATS = 10
GO
USE QNXT_PLANDATA_UNV
GO
USE QNXT_PLANDATA_UNV
GO
BEGIN TRAN
insert into QNXT_PLANDATA_UNV_PLAN_0 values (1,'Pit1')
insert into QNXT_PLANDATA_UNV_PLAN_0 values (2,'Pit2')
insert into QNXT_PLANDATA_UNV_PLAN_0 values (3,'Pit3')
insert into QNXT_PLANDATA_UNV_PLAN_0 values (4,'Pit4')
COMMIT
STEP:8 FIRST WE NEED TO RUN BELOW QUERY (WE WILL FIND WHO DROPPED TABLE)
select [Current LSN], [Operation], [Transaction ID], [Parent Transaction ID],
[Begin Time], [Transaction Name], suser_sname([Transaction SID]) Who_Dropped
from fn_dblog(null, null)
where [Operation] = 'LOP_BEGIN_XACT' and [Transaction Name]='DROPOBJ'
STEP:9 If log file was truncated, then we can use fn_dump_dblog to retrieve
LSN information from Log Backup.
USE [master]
RESTORE DATABASE [QNXT_PLANDATA_UNV_Copy] FROM DISK = N'D:\Backup\PIT_Full.bak'
WITH
MOVE N'QNXT_PLANDATA_UNV' TO N'C:\Program Files\Microsoft SQL
Server\MSSQL16.SQL_SERVER_ENCRY\MSSQL\DATA\QNXT_PLANDATA_UNV_Copy.mdf',
MOVE N'QNXT_PLANDATA_UNV_log' TO N'C:\Program Files\Microsoft SQL
Server\MSSQL16.SQL_SERVER_ENCRY\MSSQL\DATA\QNXT_PLANDATA_UNV_Copy_log.ldf',
NORECOVERY, STATS = 5
--Prefix 'lsn:0x' along with the LSN number for hexadecimal format.
Page Restore
KDSSG B46 Level001 046 29Mar2024 Restores4
Step:5 after full backup add some more data in existed table.
Step:5 after diff backup add some more data in existed table.
DBCC IND('Pagerestore','page1',0)
DBCC IND('DBname','tablename',0)
DBCC TRACEON(3604,-1)
step:8 we will get table full information once ran below query.
DBCC PAGE(Pagerestore,1,376,3)
DBCC PAGE(dbname,1,pageno,3)
Click address button select decimal option use 8192*page number=total paste there.
After that we got in page full data-----corrupter the data just modified don’t
delete any data after that save and come out.
use Pagerestore
go
select * from [dbo].[page1]
Run DBCC CHECKDB, to identify if just a single page is corrupt or if multiple
pages are corrupt.
--Take Backup with NORECOVERY, this will put database in --RESTORING State.
Create a database with two file groups and create two tables in each file group.
use FFG
GO
--Differential Backup.
BACKUP DATABASE FFG
TO DISK=N'D:\Backup\FFG_DIFF1.BAK'
WITH DIFFERENTIAL
insert into Table1 values (4,'Four')
insert into Table2 values (4,'Char')
insert into Table3 values (4,'Nalakku')
----:RESTORE COMMANDS:----
Before the database restore we have to take TAIL log backup.
BACKUP LOG FFG
TO DISK=N'D:\Backup\FFG_Tail.trn'
WITH NO_TRUNCATE
USE [master]
RESTORE DATABASE [FFG]
FILEGROUP='PRIMARY'
FROM DISK = N'D:\Backup\FFG_FULL.BAK'
WITH NORECOVERY,REPLACE
GO
We must use file and filegroup backup and restore operations in conjunction with transaction log
backups. After you restore the files, you must then restore the transaction log backups that were
created since the file backups were created to bring the database to a consistent state.
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.
use FFG
GO
--Differential Backup.
BACKUP DATABASE FFG
TO DISK=N'D:\Backup\FFG_DIFF1.BAK'
WITH DIFFERENTIAL
----:RESTORE COMMANDS:----
Before the database restore we have to take TAIL log backup.
BACKUP LOG FFG
TO DISK=N'D:\Backup\FFG_Tail.trn'
WITH NO_TRUNCATE