I have a stored procedure that will take the most recent backup file from a server and restore it onto another server. With slight modifications, I have this:SET NOCOUNT ONDECLARE @SQL VARCHAR(7000)DECLARE @DBName SYSNAMEDECLARE @BkpFileName NVARCHAR(260)SELECT bs.database_name AS DatabaseName, MAX(bms.physical_device_name) AS FullBackupNameINTO #BackupsFROM msdb.dbo.backupset bsINNER JOIN msdb.dbo.backupmediafamily bms ON bs.media_set_id = bms.media_set_idINNER JOIN master.dbo.sysdatabases s ON bs.database_name = s.nameWHERE CONVERT(VARCHAR(20), bs.backup_finish_date, 101) = CONVERT(VARCHAR(20), GETDATE(), 101) AND s.name NOT IN ('master', 'msdb', 'model', 'pubs', 'Northwind')GROUP BY bs.database_nameWHILE (SELECT COUNT(*) FROM #Backups) <> 0BEGIN SELECT TOP 1 @DBName = DatabaseName, @BkpFileName = FullBackupName FROM #Backups ORDER BY DatabaseName SELECT @SQL = 'xcopy ' + @BkpFileName + ' \\SomeServer\Someshare\' EXEC master.dbo.xp_cmdshell @SQL DELETE FROM #Backups WHERE DatabaseName = @DBNameENDDROP TABLE #Backups
So it actually finds out what the most recent backup files are for the user databases, then copies them over. So in case someone ran a manual backup to a non-standard location, this code will catch those too. Tara