SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


T-SQL Restore Script Generator


T-SQL Restore Script Generator

Author
Message
Paul Brewer
Paul Brewer
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1196 Visits: 1344
Comments posted to this topic are about the item T-SQL Restore Script Generator
Hugo Kornelis
Hugo Kornelis
SSC-Dedicated
SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)

Group: General Forum Members
Points: 34414 Visits: 13121
Thanks for sharing your script, Paul!

I do have a question, though. In SSMS, when I bring up the restore dialog, I can select a point in time and then have SSMS generate the restore statements for me. What are the benefits of using your script over using SSMS to generate them?


Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Paul Brewer
Paul Brewer
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1196 Visits: 1344
The restore dialogue in SSMS has a GUI front end and works for one database at a time. sp_RestoreScriptGenie can build a restore script for all databases in an instance (handy if you have 50 or 60) and can be scheduled as a SQL agent job to, for example, automate development environment refreshes, reinstate log shipping, mirroring, alwayson availability groups and so on.

The functionality available in the ssms restore dialogue and sp_RestoreScriptGenie and very similar (I hope to make it identical by adding file group and page restores) but the circumstances you might use each in are different.

Thanks for the question and best wishes
Paul
Hugo Kornelis
Hugo Kornelis
SSC-Dedicated
SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)

Group: General Forum Members
Points: 34414 Visits: 13121
Thanks for the quick and enlightening reply, Paul!


Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Paul Brewer
Paul Brewer
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1196 Visits: 1344
Thanks for a great question.
Nadrek
Nadrek
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10393 Visits: 2752
Very interesting - though I would have to note that this has the very common limitation that it won't function when trying to restore specific databases to Server B after Server A is completely unavailable (and other similar situations), since there won't be an msdb with valid history.

Likewise, I would be concerned about cases (SQL2005, primarily) where msdb has incorrect path information, i.e. http://connect.microsoft.com/SQLServer/feedback/details/306604/physical-device-name-not-captured-correctly-in-msdb-dbo-backupmediafamily.

Question: did you test it with empty transaction log backups (i.e. LastLSN = FirstLSN) - for instance, a server set to do very frequent T-log backups that, for whatever reason, had no activity during that time. I usually generate those test cases with once-a-minute T-log backups on a development server with absolutely 0 activity.
Paul Brewer
Paul Brewer
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1196 Visits: 1344
At work here we use the Ola Hallengran scripts to run out backups to a dedicated backup server. I have added a final step to the user database and log backup jobs to run sp_RestoreScriptGenie and, basically, save the T-SQL RESTORE script in the same directory as the backups. If disaster strikes we have the recovery scripts saved in the same directory as the backup files.

Regarding LSN's, the checks were added later after I saw the '31 days of disaster recover' series by SQLSoldier. They are basically his checks appended to the procedure. It hasn't been a problem for me during many executions and (I think) worst case scenario is you would need to comment out one of the transaction log restores if it were a problem. It has been tested with empty log file backups though and they are not a problem.

Regarding the incorrect paths, you can override data/log/backup file locations and in the restore commands it builds and it shouldn't matter. I wasn't aware of the SQL Server 2005 connect item to be honest although the procedure has been tested with SQL Server 2005 <-> SQL Server 2012.

Thanks and best wishes
signal runner
signal runner
Old Hand
Old Hand (342 reputation)Old Hand (342 reputation)Old Hand (342 reputation)Old Hand (342 reputation)Old Hand (342 reputation)Old Hand (342 reputation)Old Hand (342 reputation)Old Hand (342 reputation)

Group: General Forum Members
Points: 342 Visits: 203
Hi - thanks for the script, it's great.
I have one (probably rookie) question: It appears to only select from msdb.dbo.backupmediafamily where device_type = 2. We have some backups where the device type = 102 (still disc) Was there any reason for that?

Thanks,
Tim
Paul Brewer
Paul Brewer
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1196 Visits: 1344
Hi Tim,
The WHERE [Device_Type] = 2

could probably be

WHERE [Device_Type] <> 7

All our backups at work are device type 2, same at home in my virtual lab at home. The idea was to ignore Symatec backups or anything that uses volume shadow copy. (I was surprised these even show up in the backup history but they do). I'll take your comments onboard in any new versions of the script.

Many thanks for the feedback and best wishes, pleased you like it.
Paul
signal runner
signal runner
Old Hand
Old Hand (342 reputation)Old Hand (342 reputation)Old Hand (342 reputation)Old Hand (342 reputation)Old Hand (342 reputation)Old Hand (342 reputation)Old Hand (342 reputation)Old Hand (342 reputation)

Group: General Forum Members
Points: 342 Visits: 203
understood - thanks.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search