Quick Script – Finding Most Recent Backup

Recently I have had to restore a number of databases into our training environment.   Looking up each backup individually would be time consuming and I prefer to save time whenever possible.  So, instead of lookup up the backup for each database I needed, I thought a quick script would be handy.  Of course, there are multiple ways to gather this information, but this is my way.

I like scripts that generate commands for me, I find it makes things easier.  Therefore this query will generate a generic restore command with some options already supplied.  Feel free to modify the query to include whatever options you need.

Note: this query will only find the last full backup of the database.

Disclaimer:  Do not execute code you find on the internet blindly on Production servers.  Test the script first and then decide if it is appropriate to execute in Production.  

As you can see, the script will give you the last backup and restore command for all of the databases on the instance.  You could easily modify the WHERE clause to only select a single database or multiple if you desire.

I have also used this against linked servers (I know, I know.  Linked servers) to get backup information on databases that reside on other servers that need to be restored.


© 2016, John Morehouse. All rights reserved.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.