Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Script to Restore Entire database from a directory

By sathish NS,

Script gives the autommatted SQL script's on Restore FileListonly, Restore Headeronly and Backup Restore script from the backup drive(ie Gets the restore script for all the available backup files from the specified drive).

Contains two stored procedures,need to create both the stored procedures and run the first procedure to get the restore scripts from the available backup files,
1. USP_DatabaseRestorewithPhysicalPath - Gives the restore script including Headeronly, FileListonly,  and inturn calls Stored procedure "restoreDB" to actual Restore Database script. Need
2. restoreDB - Called from the above stored procedure to produce Restore database script.

Execute Stored procedure with the backup path parameters,

Execute USP_DatabaseRestorewithPhysicalPath 'D:\MSSQL\Backup'

Sample Outputs from the available backup file directory,

--D:\MSSQL\Backup\BACKUPDEMO_DIFF.BAK

RESTORE FILELISTONLY FROM DISK = 'D:\MSSQL\Backup\BACKUPDEMO_DIFF.BAK'

RESTORE HEADERONLY FROM DISK = 'D:\MSSQL\Backup\BACKUPDEMO_DIFF.BAK'

Exec [restoreDB] 'BACKUPDEMO','BACKUPDEMO','D:\MSSQL\Backup\BACKUPDEMO_DIFF.BAK'

GO

----------------------------------------------------------------------------

--D:\MSSQL\Backup\BACKUPDEMO_FULL.BAK

RESTORE FILELISTONLY FROM DISK = 'D:\MSSQL\Backup\BACKUPDEMO_FULL.BAK'

RESTORE HEADERONLY FROM DISK = 'D:\MSSQL\Backup\BACKUPDEMO_FULL.BAK'

Exec [restoreDB] 'BACKUPDEMO','BACKUPDEMO','D:\MSSQL\Backup\BACKUPDEMO_FULL.BAK'

GO

Total article views: 2816 | Views in the last 30 days: 20
 
Related Articles
SCRIPT

Backup & Restoration Script

This script provides very useful information about database backup and restoration.

SCRIPT

Restore script for Ola Hallengren backup

Create a restore script based on backup files in a directory

FORUM

Script to restore red gate backups automatically from a folder.

Restore of red gate backup files using a SQL Script

SCRIPT

Restore Script Generator

Create restore script from a SQL Backup file. A must have for your DBA Tool Belt.

BLOG

Generate restore script automatically by backup history table

I wrote a store procedure which could generate restore script automatically by backup history table....

Tags
restore    
 
Contribute