Restoring a SQL Database

August 18, 2004

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):