I create backups using the same .bak file. I’ve made a script to automagically restore this backup.
RESTORE DATABASE [xxx] FROM DISK = N'xxx.bak'
WITH FILE = 10, NOUNLOAD, REPLACE, STATS = 10
GO
Here, the backup set to restore is explicitly specified. However, I always want to restore the latest set available. By default, it uses the first backup set.
Use the RESTORE HEADERONLY command to locate the particular backup you want, as that result set shows the BackupFinishDate. Note the field named Position; that is the FILE number.
At this point, if you already know the logical names, you can run a RESTORE command using the FILE option in the WITH clause.
You probably already know that you can use the RESTORE FILELISTONLY command to find the logical names.
Tibor Karaszi has posted a similar (but not same) solution here: http://www.karaszi.com/SQLServer/util_restore_all_in_file.asp You can use his CREATE TABLE commands to get the results of RESTORE HEADERONLY into a table. What I’ve pasted in below shows how to get the results of RESTORE FILELISTONLY into a table (also ripped from Tibor).