Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Backup not workin with %date% Expand / Collapse
Author
Message
Posted Saturday, April 13, 2013 9:15 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, April 18, 2013 11:42 PM
Points: 1, Visits: 12
Hello,

I have question regarding backup SQL'05.
Please look ta my script :

sqlcmd -S srv_name -U sa -P pass -Q "BACKUP DATABASE Database_name TO DISK = 'D:\Backup\%date%_Database_name.bak' WITH NAME = 'Database_name_backup', FORMAT"

If i remove %Date% backup process will be completed successfully. But with %Date% I ahve folowing error:

Cannot open backup device 'D:\Backup\%date%_Database_name.bak' Date is repleaced by system time...

Please tell me what is wrong...

Thx for help
michal
Post #1442036
Posted Saturday, April 13, 2013 4:41 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 10:17 AM
Points: 20,739, Visits: 32,524
mjarosz (4/13/2013)
Hello,

I have question regarding backup SQL'05.
Please look ta my script :

sqlcmd -S srv_name -U sa -P pass -Q "BACKUP DATABASE Database_name TO DISK = 'D:\Backup\%date%_Database_name.bak' WITH NAME = 'Database_name_backup', FORMAT"

If i remove %Date% backup process will be completed successfully. But with %Date% I ahve folowing error:

Cannot open backup device 'D:\Backup\%date%_Database_name.bak' Date is repleaced by system time...

Please tell me what is wrong...

Thx for help
michal


That is because SQL Server doesn't know what %date% is. It sees it as a string. If you are attempting to write your backups to a directory named with a date value (such as 20130413) you have put that in there by building the string needed for the backup command.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1442062
Posted Saturday, April 13, 2013 6:44 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 5:32 PM
Points: 1,796, Visits: 5,801
If you are running this as an operating system command (dos), then try %date:/=_% instead of %date%, this will output dates with the "/" replaced by "_" making for a valid filename.

MM


  • MMGrid Addin
  • MMNose Addin


  • Forum Etiquette: How to post Reporting Services problems
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • How to Post Performance Problems - by Gail Shaw

  • Post #1442071
    « Prev Topic | Next Topic »

    Add to briefcase

    Permissions Expand / Collapse