Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

MS SQL

Posted Aug 18, 2004

Restoring a SQL Database

By Muthusamy Anantha Kumar aka The MAK

When we create a backup maintenance plan with one Full backup and transaction log backups for every 15 minutes, it is sometimes necessary to restore the FULL backup and all the corresponding transactional backups sequentially. This may happen if the production box goes down or if you want to have the same database restored to another Server, etc. It is tiresome to locate all the transaction log backups and restore them one by one.

In this article, I would like to guide SQL Server DBAs to use a procedure, which can:

1.  Generate the script for restoring a full backup and all corresponding transaction log backups.

2.  Restore a full backup and all corresponding transaction log backups along with generated scripts.

3.  Restore the latest full backup and all corresponding transaction log backups as a different database.

This procedure uses xp_cmdshell and the MS-DOS 'DIR' command to find the backup and transactions log sequence based on the file date.

Let us simulate the whole backup and restore process.

Step 1

Create a database, "Inventory," in FULL recovery mode. (You can use the below script):

Use master
Go
CREATE DATABASE [inventory]  
  ON (NAME = N'inventory', 
  FILENAME = N'D:\Program Files\Microsoft SQL Server\MSSQL\data\inventory.mdf' , 
  SIZE = 1, FILEGROWTH = 10%) 
LOG ON (NAME = N'inventory_log', 
  FILENAME = N'D:\Program Files\Microsoft SQL Server\MSSQL\data\Inventory_log.LDF' , 
  FILEGROWTH = 10%)
Go
Alter DATABASE [inventory]  set recovery FULL
GO

Step 2

Create a maintenance plan with one full backup, (as shown in figure Fig 1.0), and transaction log backup for every 5 minutes, (as shown in figure Fig 2.0).


Fig 1.0


Fig 2.0

When this maintenance plan runs, it creates .BAK and .TRN files as shown in the figure Fig 3.0.


Fig 3.0



MS SQL Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
SQL 2005: SSIS: Error using SQL Server credentials poverty 3 August 17th, 07:43 AM
Need help changing table contents nkawtg 1 August 17th, 03:02 AM
SQL Server Memory confifuration bhosalenarayan 2 August 14th, 05:33 AM
SQL Server Primary Key and a Unique Key katty.jonh 2 July 25th, 10:36 AM