| Author |
Topic |
|
GRAYWOLF
Posting Yak Master
106 Posts |
Posted - 2008-11-29 : 03:27:43
|
| I am trying to set up a daily restore to a dev server. This is being done from a 3 file SQL Backup backup.Exec master..sqlbackup N'-SQL "RESTORE DATABASE [thedb] FROM DISK = '@filename1', DISK = '@filename2', DISK = '@filename3' WITH RECOVERY, The filenames are assigned just fine, but when I add this to the The job runs fine with the full path in place of the variables. The above code is giving a Syntax error at @filename1.Using double apostrophe gives me a syntax error at FROM---------------------------Working until "the morning sun sets the midnight sky on fire"! |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-29 : 03:56:46
|
| TryDECLARE @sql varchar(1000)SET @sql='Exec master..sqlbackup N''-SQL "RESTORE DATABASE [thedb] FROM DISK = '''+@filename1+''', DISK = '''+@filename2+''', DISK = '''+@filename3+''' WITH RECOVERY'EXEC(SQL)MadhivananFailing to plan is Planning to fail |
 |
|
|
GRAYWOLF
Posting Yak Master
106 Posts |
Posted - 2008-11-29 : 04:25:53
|
| It looked like it was going to work and then threw this:Msg 102, Level 15, State 1, Line 2Incorrect syntax near '\'.Msg 105, Level 15, State 1, Line 7Unclosed quotation mark after the character string '"'.---------------------------Working until "the morning sun sets the midnight sky on fire"! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-29 : 04:28:10
|
| Post the result ofDECLARE @sql varchar(1000)SET @sql='Exec master..sqlbackup N''-SQL "RESTORE DATABASE [thedb] FROM DISK = '''+@filename1+''', DISK = '''+@filename2+''', DISK = '''+@filename3+''' WITH RECOVERY'PRINT SQLMadhivananFailing to plan is Planning to fail |
 |
|
|
GRAYWOLF
Posting Yak Master
106 Posts |
Posted - 2008-11-29 : 04:34:59
|
| Exec master..sqlbackup N'-SQL "RESTORE DATABASE [theDB] FROM DISK = '\\server\SQL_Backups\Database\anotherfolder\backupfile01.sqb', DISK = '\\server\SQL_Backups\Database\anotherfolder\backupfile02.sqb', DISK = '\\server\SQL_Backups\Database\anotherfolder\backupfile03.sqb' WITH RECOVERY, PASSWORD = '**********'""Database" is the actual name of one of the dir in the path to the backup files.---------------------------Working until "the morning sun sets the midnight sky on fire"! |
 |
|
|
GRAYWOLF
Posting Yak Master
106 Posts |
Posted - 2008-11-29 : 04:38:17
|
| The status bar states "Query executed successfully" when I got the errors under Exec---------------------------Working until "the morning sun sets the midnight sky on fire"! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-29 : 05:01:39
|
| DECLARE @sql varchar(1000)SET @sql='Exec master..sqlbackup N''''-SQL "RESTORE DATABASE [thedb] FROM DISK = '''+@filename1+''', DISK = '''+@filename2+''', DISK = '''+@filename3+''' WITH RECOVERY,PASSWORD = ''**********'''EXEC(SQL)MadhivananFailing to plan is Planning to fail |
 |
|
|
GRAYWOLF
Posting Yak Master
106 Posts |
Posted - 2008-11-29 : 05:17:41
|
| Msg 102, Level 15, State 1, Line 2Incorrect syntax near '-'.Msg 103, Level 15, State 4, Line 2The identifier that starts with 'RESTORE DATABASE [theDB] FROM DISK = '\\server\SQL_Backups\Database\anotherfolder\backupfile0' is too long. Maximum length is 128. Exec master..sqlbackup N''-SQL "RESTORE DATABASE [theDB] FROM DISK = '\\server\SQL_Backups\Database\anotherfolder\backupfile01.sqb', DISK = '\\server\SQL_Backups\Database\anotherfolder\backupfile02.sqb', DISK = '\\server\SQL_Backups\Database\anotherfolder\backupfile03.sqb' WITH RECOVERY, PASSWORD = '**********'"It errored on the missing close " so I added it '**********''"'---------------------------Working until "the morning sun sets the midnight sky on fire"! |
 |
|
|
GRAYWOLF
Posting Yak Master
106 Posts |
Posted - 2008-11-29 : 05:18:23
|
| that is hard to see...it should look more like ' ' " '---------------------------Working until "the morning sun sets the midnight sky on fire"! |
 |
|
|
GRAYWOLF
Posting Yak Master
106 Posts |
Posted - 2008-11-29 : 05:27:49
|
| Also, my declaration is:DECLARE @sql nvarchar(4000)---------------------------Working until "the morning sun sets the midnight sky on fire"! |
 |
|
|
GRAYWOLF
Posting Yak Master
106 Posts |
Posted - 2008-12-03 : 02:36:01
|
| In case anyone stumbles across this thread later.I resolved it:set @restorecmd = 'exec master..sqlbackup N''-SQL "RESTORE DATABASE [myDB]' + ' FROM DISK = ''''' + @filename1 + ''''',' + 'DISK = ''''' + @filename2 + ''''',' + 'DISK = ''''' + @filename3 + '''''' + ' WITH RECOVERY,' + 'REPLACE, PASSWORD = ''''thepassword''''"'''Exec(@restorecmd)Thanks for your help, madhivanan...I just needed more '''''''''''---------------------------Working until "the morning sun sets the midnight sky on fire"! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|