Author |
Topic |
5pirates
Starting Member
4 Posts |
Posted - 2010-10-05 : 10:41:10
|
I have a basic backup script (below) that keeps skipping one of the databases. The select from sys.databases returns the record but does not backup. There are no errors in the log. Does anyone have any ideas?DECLARE @dbname sysnameDECLARE @dbid intDECLARE @backupsql varchar(500)DECLARE db_cursor CURSOR FOR SELECT name, database_id FROM sys.databases where database_id > 4 ORDER BY database_idOPEN db_cursorFETCH NEXT FROM db_cursor INTO @dbname, @dbidWHILE (@@FETCH_STATUS = 0) BEGIN IF (@dbid > 4) BEGIN SELECT @backupsql = 'BACKUP DATABASE ' + @dbname + ' TO DISK = ' + CHAR(39) + '\\serverIP\sqlbackups$\servername\' + @dbname + '.BAK' + CHAR(39) + ' WITH INIT' EXEC(@backupsql) END FETCH NEXT FROM db_cursor INTO @dbname, @dbid ENDCLOSE db_cursorDEALLOCATE db_cursorRETURN |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-10-05 : 10:53:54
|
What is the name of the skipped database? No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
5pirates
Starting Member
4 Posts |
Posted - 2010-10-05 : 11:16:38
|
The database name is SLX_IMPORTS and the databaseid is 8 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-10-05 : 11:35:09
|
if you do a print @backupsql instead of EXEC(@backupsql), is there a statement shown for that database?ORAre you testing on a different server where that database is present but not on the server where the cursor is running? No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
5pirates
Starting Member
4 Posts |
Posted - 2010-10-05 : 11:47:41
|
I tested on the same server and the 'print' shows the statement. If I run the procedure in QA all databases get backed up. It's just when the procedure is executed from a job. BACKUP DATABASE SLX_IMPORTS TO DISK = '\\serverIP\sqlbackups$\servername\SLX_IMPORTS.BAK' WITH INIT |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-10-05 : 12:10:14
|
does this work?DECLARE @dbname sysnameDECLARE @dbid intDECLARE @backupsql varchar(500)DECLARE db_cursor CURSOR FOR SELECT name, database_id FROM sys.databaseswhere database_id > 4 ORDER BY database_idOPEN db_cursorFETCH NEXT FROM db_cursor INTO @dbname, @dbidWHILE (@@FETCH_STATUS = 0)BEGINIF (@dbid > 4)BEGIN SELECT @backupsql = 'BACKUP DATABASE [' + @dbname + '] TO DISK = ' + CHAR(39) + '\\serverIP\sqlbackups$\servername\' + @dbname + '.BAK' + CHAR(39) + ' WITH INIT; GO' print(@backupsql)ENDFETCH NEXT FROM db_cursor INTO @dbname, @dbidENDCLOSE db_cursorDEALLOCATE db_cursorRETURN |
|
|
5pirates
Starting Member
4 Posts |
Posted - 2010-10-05 : 12:24:14
|
Ran successfully on the single database. I will try this tonight in the job. Thanks for the help. |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-10-05 : 12:29:46
|
Welcome let us know how it turns outdon't forget to change my PRINT to EXEC b4 you plug it into your job, else you won't have backups tonight! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-10-05 : 13:46:43
|
quote: Originally posted by tkizer If russell's change works, I'll be shocked.
me too lol. actually, i was thinking that maybe it's a db just b4 the one in question that might be stopping the script. since i can't see 'em...it was a shot |
|
|
|