September 19, 2008 at 3:23 pm
I'm trying to get a job to make a simple backup of a database with current date so that it doesn't overwrite or append to previous bak files. Like:
BACKUP DATABASE CE10 to disk = 'd:\mssql\BACKUP\ce10_db_yyyyMMddhhmm.BAK'
How do I get the current date in there each day?
Thanks very much for any help.
September 19, 2008 at 3:37 pm
Are you doing the backup from a SQL script? If you are then you could use dynamic SQL, convert getdate() to a varchar and append that to the static part of the file name.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
September 22, 2008 at 9:19 am
Yes I'm using a SQL script. Maybe I just can't get the right syntax:
BACKUP DATABASE CE10 to disk =
'c:\mssql\BACKUP\ce10_db_convert(getdate()).BAK' WITH NOINIT
How do I append/convert correctly? I'll try looking up some examples. Thanks very much.
September 22, 2008 at 9:32 am
Assuming that "_db_convert" was supposed to be part of the file name, try replacing the getdate() with ' + convert(varchar(8), getdate(), 112)) + '
Note, include both single quotes in the replacement.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
September 22, 2008 at 11:29 am
Yes it's part of the file name. I'm still struggling with the syntax. Can you see what's wrong with this:
BACKUP DATABASE CE10 to disk = 'c:\mssql\backup\ce10_db_ '+ convert(varchar(8), getdate(), 112) +'.BAK' WITH NOINIT
Thanks very much for all ideas.
September 23, 2008 at 3:48 pm
Denise McMillan (9/22/2008)
Yes it's part of the file name. I'm still struggling with the syntax. Can you see what's wrong with this:BACKUP DATABASE CE10 to disk = 'c:\mssql\backup\ce10_db_ '+ convert(varchar(8), getdate(), 112) +'.BAK' WITH NOINIT
Thanks very much for all ideas.
You cant pass a string in the manner you're trying to for the DISK statement...
DECLARE @DISKSTRING varchar(255)
SET @DISKSTRING = 'C:\mssql\backup\ce10_db_' + convert(char(8),getdate(),112) + '.BAK'
BACKUP DATABASE CE10
TO DISK = @DISKSTRING
WITH NOINIT
Your friendly High-Tech Janitor...
September 24, 2008 at 6:13 am
I have it working now.
Thanks very much for all the help!
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy