Showing posts with label Restore. Show all posts
Showing posts with label Restore. Show all posts

This log backup contains bulk-logged changes. It cannot be used to stop at an arbitrary point in time.

Point-In-time restore is not supported If a log backup taken under the BULK-LOGGED recovery model contains bulk-logged changes. Trying to perform point-in-time recovery on a LOG backup that contains bulk changes will cause the following Error.

Msg 4341, Level 16, State 1, Line 1
This log backup contains bulk-logged changes. It cannot be used to stop at an arbitrary point in time.


I would like to walk-through the scenario here...

USE MASTER
GO


/*Creating new Database named : DB1*/
CREATE DATABASE DB1
GO

/*Setting Database recovery mode to BULK_LOGGED*/
ALTER DATABASE DB1 SET RECOVERY BULK_LOGGED
GO


/*Creating a table named : Table1*/
USE DB1
GO

CREATE TABLE table1
(
id INT IDENTITY(1,1),
column1 VARCHAR(10)

)
GO

/*Inserting a record into "Table1" */
INSERT table1 VALUES('Pandian')
GO


/*Taking Full BackUp*/
BACKUP DATABASE db1 TO DISK='e:\backup\Full.Bak' WITH INIT
GO


/*Performing some BULK operation*/
SELECT * INTO table2 FROM table1
GO

/*Inserting data into "table2" */
INSERT table2 VALUES('SQL DBA')
GO

/*Identifying current timestamp*/
SELECT GETDATE()
GO
-- 2011-02-27 19:55:28.760

/*Taking Log BackUp*/
USE MASTER
GO
BACKUP
LOG db1 TO DISK='e:\backup\Log.Trn' WITH INIT
GO


/*Droping the table*/
USE DB1
GO
DROP TABLE
table2
GO

/*Identifying the Bulk-Operation performed any, from the Log backup file*/
USE MASTER
GO
RESTORE HEADERONLY FROM DISK
='e:\backup\log.trn'
GO

/*Result from the above statement*/
We have a column called "HasBulkLoggedData", The column has value '1', means the Log backup contains Bulk operation

/*Performing DATA restore on DB1 database with NoRecovery Model for continue with Log restore*/
RESTORE DATABASE DB1 FROM DISK='e:\backup\Full.Bak' WITH NORECOVERY, REPLACE
GO

/*Performing LOG restore on DB1 database upto Partiular time */
RESTORE LOG DB1 FROM DISK='e:\backup\log.trn' WITH RECOVERY, STOPAT ='2011-02-27 19:55:28.760'
GO

Now, we should get an error as given below

Msg 4341, Level 16, State 1, Line 1
This log backup contains bulk-logged changes. It cannot be used to stop at an arbitrary point in time.


Now, the database seems to be middle of the Restore..., How to recover that ?

RESTORE DATABASE db1 WITH RECOVERY
GO


Note:But, we can restore LOG backup fully without any Point-in-time in this scenario!

To Cleanup Backup and Restore history

To remove the Backup and Restore related history from the system tables older than the specified date:

USE msdb
GO
EXEC sp_delete_backuphistory '2011-01-31'
GO

To remove the Backup and Restore related history from the system tables for the specified Database:

USE msdb
GO
EXEC sp_delete_Database_backuphistory 'SQLDB1'
GO

Backup/Restore history removed from the following system tables
1.backupfile
2.backupfilegroup
3.backupmediafamily
4.backupmediaset
5.backupset
6.restorefile
7.restorefilegroup
8.restorehistory

How to Restore MASTER database...

Why/when should restore the Master database:
- Incase of any failure login into an Instance due to forgot the login credentials
- Windows authentication credentials removed mistakenly and Sysadmin('sa') password also changed...
- we can fix this issue by restoring the Master database.

When should backup the Master database ?
1. If any changes done at Master database like whenever new login created/modified

2. New database created or Mapped the user with database.

What are the things needs to be considered before restore the Master database ?
1. If there is any changes to Master database after the database backup created.

2. Any login created/modified after the Master database backup created.

3. Any associated/mapped user with user databases after the Master database backup created.

4. Any user database created after the Master database backup created.

5. Any user database re-attached as it creates system tables to maintain the availability.

6. Any objects, logins, or databases have been deleted after Master database was backed up, those objects, logins, and databases should be deleted from Master database also.

7. Any user database no longer available that are referenced in a Master database backup, It report errors when restoring the Master database. Those databases should be dropped after the Master backup is restored.

8. The SQL Server instance stopped automatically once the Master database restore activity completed.

How to restore the Master database backup ?
Restoring Master database is not direct way like user defined database as it needs some additional workarround here..

1. Identify the Sqlservr.exe location.

2. Stop the SQL Server Instance.

3. Start the SQL Server in single user mode from command prompt...

If the SQL Server is Default instance:

If the SQL Server is Named instance:

Press Enter to proceed...

Once the system databases started as shown below... "Please don't close this screen"

4. Open the "SQL Server Management studio" from Start --> Program Files --> ...

5. Login into the Instance with Windows Authentication, The Instance doesn't have windows authentication credential, But we can login through Single user mode...

6. Expand the System Databases --> Right click on Master Database --> Tasks --> Restore --> Database... as shown below

7. Enter as Master in To Database area, Locate the Master database backup file with REPLACE Mode.

8. It may receive any error stating that "Single session is already running..." (or) "A transport-level error has occurred when receiving results from the server", Just click OK and Cancel to proceed further...

9. Now the command prompt can be closed once the restore process completed...

10. Start the SQL Server Instance service.

11. Open the "SQL Server Management studio" from Start --> Program Files --> ...