I've managed to get this far building a restore SP using great tips from this forum:
Now, is it possible to take the @file parameter one step further - I would like to have the SP automatically select the most recent .bak file in the server directory. Right now, the directory contains several .bak files, like so:
Basel_db_200606222030.BAK
Basel_db_200606232030.BAK
Basel_db_200606242030.BAK
Basel_db_200606252030.BAK
Basel_db_200606262030.BAK
Instead of coding the following paramter to get yesterday's:
I would like to declare @file to look for the most recent backup file. This is for a DR process and we may not be able to restore the database for a few days, thus eliminating the "getdate() - 1"
Joe
Code:
CREATE PROCEDURE [dbo].[DBS_restore_Basel_database]
AS
/*restore database */
declare @file nvarchar(4000)
select @file = 'D:\MSSQL\BACKUP\Basel\Basel_db_' + CONVERT(varchar(30),getdate() - 1,112) + '2030' + '.BAK'
Restore Database Basel
from disk = @file
with move 'Basel_data' to 'd:\mssql\data\Basel_db.mdf',
move 'Basel_log' to 'd:\mssql\data\Basel_db.ldf',
replace
GO
Now, is it possible to take the @file parameter one step further - I would like to have the SP automatically select the most recent .bak file in the server directory. Right now, the directory contains several .bak files, like so:
Basel_db_200606222030.BAK
Basel_db_200606232030.BAK
Basel_db_200606242030.BAK
Basel_db_200606252030.BAK
Basel_db_200606262030.BAK
Instead of coding the following paramter to get yesterday's:
Code:
declare @file nvarchar(4000)
select @file = 'D:\MSSQL\BACKUP\Basel\Basel_db_' + CONVERT(varchar(30),getdate() - 1,112) + '2030' + '.BAK'
I would like to declare @file to look for the most recent backup file. This is for a DR process and we may not be able to restore the database for a few days, thus eliminating the "getdate() - 1"
Joe