Using variables with Restore command
Betelgeuse
Posts: 9
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.
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.
Comments
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
SQL Backup Consultant Developer
Associate, Yohz Software
Beyond compression - SQL Backup goodies under the hood, updated for version 8