How to use below script to generate restoration script. One of my friend told me that ,
This script will generate a restore script. This could be used for all customers. The server, drives, and paths would all have to be there. Just restore master...then msdb. Then run the script and save the output. You would need to update the path to reflect the current path. Then just kick it off. If all of the drives and paths are there, it will work.
But when i execute this script, i am getting out put just like completed successfully.
Please help me.
SET NOCOUNT ON;DECLARE @databaseName sysname
DECLARE @backupStartDate datetime
DECLARE @backup_set_id_start INT
DECLARE @backup_set_id_end INT
DECLARE db_cursor CURSOR FOR
select distinct database_name
FROM msdb.dbo.backupset
WHERE database_name NOT IN ('master','model','msdb','tempdb')
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @databaseName
WHILE @@FETCH_STATUS = 0
BEGIN
-- set database to be used
SET @databaseName = @databaseName
SELECT @backup_set_id_start = MAX(backup_set_id)
FROM msdb.dbo.backupset
WHERE database_name = @databaseName AND type = 'D'
SELECT @backup_set_id_end = MIN(backup_set_id)
FROM msdb.dbo.backupset
WHERE database_name = @databaseName AND type = 'D'
AND backup_set_id > @backup_set_id_start
IF @backup_set_id_end IS NULL SET @backup_set_id_end = 999999999
SELECT 'RESTORE DATABASE ' + @databaseName + ' FROM DISK = '''
+ mf.physical_device_name + ''' WITH REPLACE'
FROM msdb.dbo.backupset b,
msdb.dbo.backupmediafamily mf
WHERE b.media_set_id = mf.media_set_id
AND b.database_name = @databaseName
AND b.backup_set_id = @backup_set_id_start
FETCH NEXT FROM db_cursor INTO @databaseName
END
CLOSE db_cursor
DEALLOCATE db_cursor