use dynamic string for sqlbackup command
dterrie
Posts: 14
Hi,
I need to run sqlbackup nightly to restore a backup using a dynmically constructed string inserting a date in the <AUTO> name string as below so that I can automate the restore process on a secondary server. The backup is from an EE instance and the restore is to an SE instance. What I have below errors out where I try to insert + @dt + into the command. How do I do this? This command, pulled from the script tab and altered to use the correct paths, succeeds with the date hardcoded, so I'm close, I guess.
I need to run sqlbackup nightly to restore a backup using a dynmically constructed string inserting a date in the <AUTO> name string as below so that I can automate the restore process on a secondary server. The backup is from an EE instance and the restore is to an SE instance. What I have below errors out where I try to insert + @dt + into the command. How do I do this? This command, pulled from the script tab and altered to use the correct paths, succeeds with the date hardcoded, so I'm close, I guess.
DECLARE @dt CHAR(8) SET @dt = CONVERT(CHAR(8),GETDATE(),112) EXECUTE master..sqlbackup N'-SQL "RESTORE DATABASE [CaliforniaSE] FROM DISK = ''\\principal\backups\database\FULL_(local)_California_' + @dt + '_030000.sqb'' WITH RECOVERY, MOVE ''California'' TO ''F:\FileGroups\DataSE\CaliforniaSE.mdf'', MOVE ''California _Data'' TO ''F:\FileGroups\DataSE\CaliforniaSE_Data.ndf'', MOVE ''California_Indexes'' TO ''G:\FileGroups\IndexesSE\CaliforniaSE_Indexes.ndf'', MOVE ''California_Log'' TO ''H:\FileGroups\LogsSE\CaliforniaSE_Log.ldf''"'
Comments
SQL Backup Consultant Developer
Associate, Yohz Software
Beyond compression - SQL Backup goodies under the hood, updated for version 8
Thanks for the help. Just to complete the loop, since I've run the command once and created the target db, I need to replace
WITH RECOVERY with WITH RECOVERY, REPLACE
yes?
SQL Backup Consultant Developer
Associate, Yohz Software
Beyond compression - SQL Backup goodies under the hood, updated for version 8