Solved

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

Posted on 2007-11-20
2
291 Views
Last Modified: 2010-03-19
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

0
Comment
Question by:hexvader
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
imitchie earned 250 total points
ID: 20324142
DECLARE @place varchar(max)
set @place = 'C:\BAckup\cheshire\cheshire_backup_' + replace(replace(replace(convert(varchar(16), getdate(), 20),'-', ''),' ',''),':','') + '.bak'
RESTORE DATABASE cheshire_Reporting
FROM DISK = @place
0
 

Author Comment

by:hexvader
ID: 20327807
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!
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question