Link to home
Start Free TrialLog in
Avatar of hexvader
hexvaderFlag for United States of America

asked on

How to change a filename during a swl on the fly.

Some Background:
My company has production servers and on a daily basis we download a database to our lan so we can run reports from it. The code we use to load the database is as follows:

USE master
RESTORE DATABASE cheshire_Reporting
FROM DISK = 'C:\BAckup\cheshire\cheshire_backup_200711190030.bak'
WITH  REPLACE
, MOVE 'cheshire_Data' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\cheshire_reporting_Data.mdf'
, MOVE 'cheshire_Log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\cheshire_reporting_Log.ldf'
, MOVE 'sysft_ft_cheshire' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\sysft_ft_cheshire_reporting'
GO
I created a sql jog with this code and it works with no problems.

Problem:
My production server is set up to save the .bak file as the filename_Backup_Date.bak.
For ex. - cheshire_backup_200711190030.bak
This date changes everyday

Question - Is there a way to create a sql server job that I can set up to run daily that will take this name
change into consideration??

thanks
John

ASKER CERTIFIED SOLUTION
Avatar of imitchie
imitchie
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hexvader

ASKER

We had to manipulate the code slighly to deal with the date actually being 1 day behind the current date but it worked like a charm.
Thanks and happy Thanks!