Thursday, February 16, 2012

Backup - filename

Heillo
I want to get a timestamp in my filename when I take a backup
I have tried the following syntax
=== S T A R T ==
BACKUP DATABASE databas
TO DISK
SELECT 'C:\Backup\database\
+ (CONVERT(char(4), Year(GetDate()))
+ (CONVERT(char(2), Month(GetDate()))
+ (CONVERT(char(2), Day(GetDate()))
+ (CONVERT(char(2), DATEPART(hh, GetDate()))
+ (CONVERT(char(2), DATEPART(hh, GetDate()))
+ '.bak
=== S T A R T ==
When I try to run this I get Incorrect syntax near the keyword 'SELECT'
Anyone who have an idea how to automatic get date and time in the filename
Please reply to may E-mail address so that I don't need to read the news for reply ;-
regard
JohnTry this ir works from Query Anyliser!
declare @.sFile varchar(150);
set @.sFile = 'p:\desktop\test'
+ (CONVERT(char(4), Year(GetDate())))
+ (CONVERT(char(2), Month(GetDate())))
+ (CONVERT(char(2), Day(GetDate())))
+ (CONVERT(char(2), DATEPART(hh, GetDate())))
+ (CONVERT(char(2), DATEPART(hh, GetDate())))
+ '.bak'
BACKUP DATABASE test TO DISK = @.sFile
Cheers!
"John A. Horve" <John.Horve@.kristiansand.kommune.no> wrote in message
news:1EF8E895-AEA1-4DC2-B6EE-57535614C349@.microsoft.com...
> Heillo,
> I want to get a timestamp in my filename when I take a backup.
> I have tried the following syntax:
> === S T A R T ===> BACKUP DATABASE database
> TO DISK => SELECT 'C:\Backup\database\'
> + (CONVERT(char(4), Year(GetDate())))
> + (CONVERT(char(2), Month(GetDate())))
> + (CONVERT(char(2), Day(GetDate())))
> + (CONVERT(char(2), DATEPART(hh, GetDate())))
> + (CONVERT(char(2), DATEPART(hh, GetDate())))
> + '.bak'
> === S T A R T ===> When I try to run this I get Incorrect syntax near the keyword 'SELECT'.
> Anyone who have an idea how to automatic get date and time in the
filename?
> Please reply to may E-mail address so that I don't need to read the news
for reply ;-)
> regards
> John

No comments:

Post a Comment