How can we help you today? How can we help you today?

Using variables with Restore command

I want to automate the restore of a database from the latest backup file in a directory with multiple backup files. I can determine the name of this file from msdb but I need to pass the name of the file to the restore command as a variable. The following syntax works with MSSQL restore but not SQL Backup restore:

restore database TEST from disk = @BackupFileName ....
OK

EXEC master..sqlbackup N'-SQL "RESTORE DATABASE [TEST] FROM DISK = @BackupFileName ....
SQL Backup v4.5.704
Syntax error: '@BackupFileName' after '='

Thanks.
Betelgeuse
0

Comments

2 comments

  • petey
    Something like this?

    DECLARE @command nvarchar(1024)
    DECLARE @filename nvarchar(260)

    SET @filename = N'e:\temp\pubs.sqb'
    SET @command = '-sql "RESTORE DATABASE pubs FROM DISK = "'

    SELECT @command -- to verify

    EXEC master..sqlbackup @command
    petey
    0
  • Betelgeuse
    Success. ~thanks!
    Betelgeuse
    0

Add comment

Please sign in to leave a comment.