Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2013
    Posts
    1

    Unanswered: SQL '05 Backup + %Date%

    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

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Describe "system time" in more detail. Does it have forbidden characters like colons?

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Mar 2012
    Location
    Somewhere In Europe
    Posts
    24
    Hi Michasio

    Below is an example script to add the current date to the file name:

    Code:
    --bck.sql
    DECLARE @DbPath nvarchar(255);
    SET @DbPath = 'D:\Backup\' + REPLACE(CONVERT(char(10), GETDATE(), 103), '/','_' ) + '_Database_name.bak';
    BACKUP DATABASE Database_name TO  DISK = @DbPath WITH NOFORMAT, INIT,  NAME = N'Database_name_backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
    GO
    Run command: sqlcmd -S srv_name -U sa -P pass -i [drive letter]:\[path]\bck.sql

    Regards
    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •