Procedure Backup

15/10/2003 - 01:06 por Diego Uribe | Informe spam
Hola todos tengo el siguiente procedure que se totea, alguna idea de porque
estara botando:

Servidor: mensaje 203, nivel 16, estado 2, procedimiento DGU_Backup, línea
32

Gracias desde ya

Diego

/***************************************************************************
**/

CREATE PROCEDURE DGU_Backup
@Path varchar(255)
AS
BEGIN
DECLARE @sql varchar(2000);
DECLARE @pth varchar(50);
DECLARE @bd varchar(50);
DECLARE @cont int;
DECLARE @max int;

SET CONCAT_NULL_YIELDS_NULL OFF;
Set @sql='';
Set @cont=1
Select @max=count(*) From sysdatabases Where dbid >= 7;
DECLARE bd_cur CURSOR FOR
Select sysdatabases.name From sysdatabases Where dbid >= 7;
OPEN bd_cur;
FETCH NEXT FROM bd_cur INTO @bd;
WHILE ( @cont <= @max )
BEGIN
Set @pth = @path + @bd;
Set @sql='BACKUP DATABASE [' + @bd + '] ';
Set @sql=@sql + 'TO DISK = N''' + @pth + ''' WITH INIT , NOUNLOAD , ';
Set @sql=@sql + 'NAME = N''Copia de seguridad ' + @bd + ''', SKIP ,
STATS = 10, NOFORMAT ';
Set @sql=@sql + 'DECLARE @i INT select @i = position from msdb..backupset
';
Set @sql=@sql + 'where database_name=''' + @bd + '''and ';
Set @sql=@sql + 'type!=''F'' and backup_set_id=(select max(backup_set_id)
';
Set @sql=@sql + 'from msdb..backupset ';
Set @sql=@sql + 'where database_name=''' + @bd + ''') ';
Set @sql=@sql + 'RESTORE VERIFYONLY FROM DISK = N''' + @pth + ''' WITH
FILE = @i';
insert into test values (@sql);
Exec @sql;
Set @cont = ( @cont + 1 );
FETCH NEXT FROM bd_cur INTO @bd;
End;
CLOSE bd_cur;
DEALLOCATE bd_cur;
END;

/***************************************************************************
**/

Preguntas similare

Leer las respuestas

#1 Javier Loria
15/10/2003 - 04:58 | Informe spam
Hola Diego:
A mi me corrio bien tu codigo, (excepto que le elimine el INSERT INTO
Test).
Sera posible que tengas algo en particular con las BD, nombres muy
largos o con simbolos especiales incompatibles con el Sistema Operativo?

Saludos,



Javier Loria
Costa Rica
Se aprecia la inclusion de DDL (CREATE, INSERTS, etc.)
que pueda ser copiado y pegado al Query Analizer.
La version de SQL y Service Pack tambien ayuda.

Diego Uribe escribio:
Hola todos tengo el siguiente procedure que se totea, alguna idea de
porque estara botando:

Servidor: mensaje 203, nivel 16, estado 2, procedimiento DGU_Backup,
línea 32

Gracias desde ya

Diego




/***************************************************************************
**/

CREATE PROCEDURE DGU_Backup
@Path varchar(255)
AS
BEGIN
DECLARE @sql varchar(2000);
DECLARE @pth varchar(50);
DECLARE @bd varchar(50);
DECLARE @cont int;
DECLARE @max int;

SET CONCAT_NULL_YIELDS_NULL OFF;
Set @sql='';
Set @cont=1
Select @max=count(*) From sysdatabases Where dbid >= 7;
DECLARE bd_cur CURSOR FOR
Select sysdatabases.name From sysdatabases Where dbid >= 7;
OPEN bd_cur;
FETCH NEXT FROM bd_cur INTO @bd;
WHILE ( @cont <= @max )
BEGIN
Set @pth = @path + @bd;
Set @sql='BACKUP DATABASE [' + @bd + '] ';
Set @sql=@sql + 'TO DISK = N''' + @pth + ''' WITH INIT ,
NOUNLOAD , '; Set @sql=@sql + 'NAME = N''Copia de seguridad ' +
@bd + ''', SKIP ,
STATS = 10, NOFORMAT ';
Set @sql=@sql + 'DECLARE @i INT select @i = position from
msdb..backupset ';
Set @sql=@sql + 'where database_name=''' + @bd + '''and ';
Set @sql=@sql + 'type!=''F'' and backup_set_id=(select
max(backup_set_id) ';
Set @sql=@sql + 'from msdb..backupset ';
Set @sql=@sql + 'where database_name=''' + @bd + ''') ';
Set @sql=@sql + 'RESTORE VERIFYONLY FROM DISK = N''' + @pth + '''
WITH FILE = @i';
insert into test values (@sql);
Exec @sql;
Set @cont = ( @cont + 1 );
FETCH NEXT FROM bd_cur INTO @bd;
End;
CLOSE bd_cur;
DEALLOCATE bd_cur;
END;




/***************************************************************************
**/
Respuesta Responder a este mensaje
#2 Diego Uribe
15/10/2003 - 16:21 | Informe spam
Y que sera:

Servidor: mensaje 203, nivel 16, estado 2 ??



"Javier Loria" escribió en el mensaje
news:
Hola Diego:
A mi me corrio bien tu codigo, (excepto que le elimine el INSERT INTO
Test).
Sera posible que tengas algo en particular con las BD, nombres muy
largos o con simbolos especiales incompatibles con el Sistema Operativo?

Saludos,



Javier Loria
Costa Rica
Se aprecia la inclusion de DDL (CREATE, INSERTS, etc.)
que pueda ser copiado y pegado al Query Analizer.
La version de SQL y Service Pack tambien ayuda.

Diego Uribe escribio:
> Hola todos tengo el siguiente procedure que se totea, alguna idea de
> porque estara botando:
>
> Servidor: mensaje 203, nivel 16, estado 2, procedimiento DGU_Backup,
> línea 32
>
> Gracias desde ya
>
> Diego
>
>



/***************************************************************************
> **/
>
> CREATE PROCEDURE DGU_Backup
> @Path varchar(255)
> AS
> BEGIN
> DECLARE @sql varchar(2000);
> DECLARE @pth varchar(50);
> DECLARE @bd varchar(50);
> DECLARE @cont int;
> DECLARE @max int;
>
> SET CONCAT_NULL_YIELDS_NULL OFF;
> Set @sql='';
> Set @cont=1
> Select @max=count(*) From sysdatabases Where dbid >= 7;
> DECLARE bd_cur CURSOR FOR
> Select sysdatabases.name From sysdatabases Where dbid >= 7;
> OPEN bd_cur;
> FETCH NEXT FROM bd_cur INTO @bd;
> WHILE ( @cont <= @max )
> BEGIN
> Set @pth = @path + @bd;
> Set @sql='BACKUP DATABASE [' + @bd + '] ';
> Set @sql=@sql + 'TO DISK = N''' + @pth + ''' WITH INIT ,
> NOUNLOAD , '; Set @sql=@sql + 'NAME = N''Copia de seguridad ' +
> @bd + ''', SKIP ,
> STATS = 10, NOFORMAT ';
> Set @sql=@sql + 'DECLARE @i INT select @i = position from
> msdb..backupset ';
> Set @sql=@sql + 'where database_name=''' + @bd + '''and ';
> Set @sql=@sql + 'type!=''F'' and backup_set_id=(select
> max(backup_set_id) ';
> Set @sql=@sql + 'from msdb..backupset ';
> Set @sql=@sql + 'where database_name=''' + @bd + ''') ';
> Set @sql=@sql + 'RESTORE VERIFYONLY FROM DISK = N''' + @pth + '''
> WITH FILE = @i';
> insert into test values (@sql);
> Exec @sql;
> Set @cont = ( @cont + 1 );
> FETCH NEXT FROM bd_cur INTO @bd;
> End;
> CLOSE bd_cur;
> DEALLOCATE bd_cur;
> END;
>
>



/***************************************************************************
> **/


Respuesta Responder a este mensaje
#3 Diego Uribe
15/10/2003 - 16:35 | Informe spam
A mi no me funciona!!

Auxilio!!!

Una vez lo ejecuto me dice:


(1 filas afectadas)

Servidor: mensaje 203, nivel 16, estado 2, procedimiento DGU_Backup, línea
32
El nombre 'BACKUP DATABASE [APPDEV] TO DISK = N'd:\bk_sqlsvr\APPDEV' WITH
INIT , NOUNLOAD , NAME = N'Copia de seguridad APPDEV', SKIP , STATS = 10,
NOFORMAT DECLARE @i INT select @i = position from msdb..backupsetwhere
database_name='APPDEV'and type!='F' and backup_set_id=(select
max(backup_set_id)from msdb..backupset where database_name='APPDEV') RESTORE
VERIFYONLY FROM DISK = N'd:\bk_sq...



"Javier Loria" escribió en el mensaje
news:
Hola Diego:
A mi me corrio bien tu codigo, (excepto que le elimine el INSERT INTO
Test).
Sera posible que tengas algo en particular con las BD, nombres muy
largos o con simbolos especiales incompatibles con el Sistema Operativo?

Saludos,



Javier Loria
Costa Rica
Se aprecia la inclusion de DDL (CREATE, INSERTS, etc.)
que pueda ser copiado y pegado al Query Analizer.
La version de SQL y Service Pack tambien ayuda.

Diego Uribe escribio:
> Hola todos tengo el siguiente procedure que se totea, alguna idea de
> porque estara botando:
>
> Servidor: mensaje 203, nivel 16, estado 2, procedimiento DGU_Backup,
> línea 32
>
> Gracias desde ya
>
> Diego
>
>



/***************************************************************************
> **/
>
> CREATE PROCEDURE DGU_Backup
> @Path varchar(255)
> AS
> BEGIN
> DECLARE @sql varchar(2000);
> DECLARE @pth varchar(50);
> DECLARE @bd varchar(50);
> DECLARE @cont int;
> DECLARE @max int;
>
> SET CONCAT_NULL_YIELDS_NULL OFF;
> Set @sql='';
> Set @cont=1
> Select @max=count(*) From sysdatabases Where dbid >= 7;
> DECLARE bd_cur CURSOR FOR
> Select sysdatabases.name From sysdatabases Where dbid >= 7;
> OPEN bd_cur;
> FETCH NEXT FROM bd_cur INTO @bd;
> WHILE ( @cont <= @max )
> BEGIN
> Set @pth = @path + @bd;
> Set @sql='BACKUP DATABASE [' + @bd + '] ';
> Set @sql=@sql + 'TO DISK = N''' + @pth + ''' WITH INIT ,
> NOUNLOAD , '; Set @sql=@sql + 'NAME = N''Copia de seguridad ' +
> @bd + ''', SKIP ,
> STATS = 10, NOFORMAT ';
> Set @sql=@sql + 'DECLARE @i INT select @i = position from
> msdb..backupset ';
> Set @sql=@sql + 'where database_name=''' + @bd + '''and ';
> Set @sql=@sql + 'type!=''F'' and backup_set_id=(select
> max(backup_set_id) ';
> Set @sql=@sql + 'from msdb..backupset ';
> Set @sql=@sql + 'where database_name=''' + @bd + ''') ';
> Set @sql=@sql + 'RESTORE VERIFYONLY FROM DISK = N''' + @pth + '''
> WITH FILE = @i';
> insert into test values (@sql);
> Exec @sql;
> Set @cont = ( @cont + 1 );
> FETCH NEXT FROM bd_cur INTO @bd;
> End;
> CLOSE bd_cur;
> DEALLOCATE bd_cur;
> END;
>
>



/***************************************************************************
> **/


Respuesta Responder a este mensaje
#4 Diego Uribe
15/10/2003 - 16:42 | Informe spam
Lo que me ha pasado es lo siguiente:

Ejecuto el script y me dice:

Servidor: mensaje 203, nivel 16, estado 2, procedimiento DGU_Backup, línea
30
El nombre 'BACKUP DATABASE [APPDEV] TO DISK = N'd:\bk_sqlsvr\APPDEV' WITH
INIT , NOUNLOAD , NAME = N'Copia de seguridad APPDEV', SKIP , STATS = 10,
NOFORMAT; DECLARE @i INT; select @i = position from msdb..backupsetwhere
database_name='APPDEV'and type!='F' and backup_set_id=(select
max(backup_set_id)from msdb..backupset where database_name='APPDEV');
RESTORE VERIFYONLY FROM DISK = N'd:\bk...

Sin embargo lo que me toco hacer es quitarle el "Exec @SQL" y dejar que
insertara las lineas en la tabla test y luego saque los strings uno por uno
y lo fui probando y todos funcionaron.

Es decir, los sqls los arma bien y los sqls independientes funcionan, lo que
no acepta es que les de exec @sql

..

Estoy perdido... no se por donde atacar el problema...




"Javier Loria" escribió en el mensaje
news:
Hola Diego:
A mi me corrio bien tu codigo, (excepto que le elimine el INSERT INTO
Test).
Sera posible que tengas algo en particular con las BD, nombres muy
largos o con simbolos especiales incompatibles con el Sistema Operativo?

Saludos,



Javier Loria
Costa Rica
Se aprecia la inclusion de DDL (CREATE, INSERTS, etc.)
que pueda ser copiado y pegado al Query Analizer.
La version de SQL y Service Pack tambien ayuda.

Diego Uribe escribio:
> Hola todos tengo el siguiente procedure que se totea, alguna idea de
> porque estara botando:
>
> Servidor: mensaje 203, nivel 16, estado 2, procedimiento DGU_Backup,
> línea 32
>
> Gracias desde ya
>
> Diego
>
>



/***************************************************************************
> **/
>
> CREATE PROCEDURE DGU_Backup
> @Path varchar(255)
> AS
> BEGIN
> DECLARE @sql varchar(2000);
> DECLARE @pth varchar(50);
> DECLARE @bd varchar(50);
> DECLARE @cont int;
> DECLARE @max int;
>
> SET CONCAT_NULL_YIELDS_NULL OFF;
> Set @sql='';
> Set @cont=1
> Select @max=count(*) From sysdatabases Where dbid >= 7;
> DECLARE bd_cur CURSOR FOR
> Select sysdatabases.name From sysdatabases Where dbid >= 7;
> OPEN bd_cur;
> FETCH NEXT FROM bd_cur INTO @bd;
> WHILE ( @cont <= @max )
> BEGIN
> Set @pth = @path + @bd;
> Set @sql='BACKUP DATABASE [' + @bd + '] ';
> Set @sql=@sql + 'TO DISK = N''' + @pth + ''' WITH INIT ,
> NOUNLOAD , '; Set @sql=@sql + 'NAME = N''Copia de seguridad ' +
> @bd + ''', SKIP ,
> STATS = 10, NOFORMAT ';
> Set @sql=@sql + 'DECLARE @i INT select @i = position from
> msdb..backupset ';
> Set @sql=@sql + 'where database_name=''' + @bd + '''and ';
> Set @sql=@sql + 'type!=''F'' and backup_set_id=(select
> max(backup_set_id) ';
> Set @sql=@sql + 'from msdb..backupset ';
> Set @sql=@sql + 'where database_name=''' + @bd + ''') ';
> Set @sql=@sql + 'RESTORE VERIFYONLY FROM DISK = N''' + @pth + '''
> WITH FILE = @i';
> insert into test values (@sql);
> Exec @sql;
> Set @cont = ( @cont + 1 );
> FETCH NEXT FROM bd_cur INTO @bd;
> End;
> CLOSE bd_cur;
> DEALLOCATE bd_cur;
> END;
>
>



/***************************************************************************
> **/


Respuesta Responder a este mensaje
#5 Diego Uribe
15/10/2003 - 18:45 | Informe spam
Ya esta

Creo que era mejor hacerlo directo

BACKUP DATABASE @bd TO DISK = @pth WITH INIT, NOUNLOAD, NAME = @tmp, SKIP,
STATS = 10, NOFORMAT;

Gracias de todas maneras

Diego

"Diego Uribe" escribió en el mensaje
news:
Lo que me ha pasado es lo siguiente:

Ejecuto el script y me dice:

Servidor: mensaje 203, nivel 16, estado 2, procedimiento DGU_Backup, línea
30
El nombre 'BACKUP DATABASE [APPDEV] TO DISK = N'd:\bk_sqlsvr\APPDEV' WITH
INIT , NOUNLOAD , NAME = N'Copia de seguridad APPDEV', SKIP , STATS 10,
NOFORMAT; DECLARE @i INT; select @i = position from msdb..backupsetwhere
database_name='APPDEV'and type!='F' and backup_set_id=(select
max(backup_set_id)from msdb..backupset where database_name='APPDEV');
RESTORE VERIFYONLY FROM DISK = N'd:\bk...

Sin embargo lo que me toco hacer es quitarle el "Exec @SQL" y dejar que
insertara las lineas en la tabla test y luego saque los strings uno por


uno
y lo fui probando y todos funcionaron.

Es decir, los sqls los arma bien y los sqls independientes funcionan, lo


que
no acepta es que les de exec @sql

..

Estoy perdido... no se por donde atacar el problema...




"Javier Loria" escribió en el mensaje
news:
> Hola Diego:
> A mi me corrio bien tu codigo, (excepto que le elimine el INSERT


INTO
> Test).
> Sera posible que tengas algo en particular con las BD, nombres muy
> largos o con simbolos especiales incompatibles con el Sistema Operativo?
>
> Saludos,
>
>
>
> Javier Loria
> Costa Rica
> Se aprecia la inclusion de DDL (CREATE, INSERTS, etc.)
> que pueda ser copiado y pegado al Query Analizer.
> La version de SQL y Service Pack tambien ayuda.
>
> Diego Uribe escribio:
> > Hola todos tengo el siguiente procedure que se totea, alguna idea de
> > porque estara botando:
> >
> > Servidor: mensaje 203, nivel 16, estado 2, procedimiento DGU_Backup,
> > línea 32
> >
> > Gracias desde ya
> >
> > Diego
> >
> >
>



/***************************************************************************
> > **/
> >
> > CREATE PROCEDURE DGU_Backup
> > @Path varchar(255)
> > AS
> > BEGIN
> > DECLARE @sql varchar(2000);
> > DECLARE @pth varchar(50);
> > DECLARE @bd varchar(50);
> > DECLARE @cont int;
> > DECLARE @max int;
> >
> > SET CONCAT_NULL_YIELDS_NULL OFF;
> > Set @sql='';
> > Set @cont=1
> > Select @max=count(*) From sysdatabases Where dbid >= 7;
> > DECLARE bd_cur CURSOR FOR
> > Select sysdatabases.name From sysdatabases Where dbid >= 7;
> > OPEN bd_cur;
> > FETCH NEXT FROM bd_cur INTO @bd;
> > WHILE ( @cont <= @max )
> > BEGIN
> > Set @pth = @path + @bd;
> > Set @sql='BACKUP DATABASE [' + @bd + '] ';
> > Set @sql=@sql + 'TO DISK = N''' + @pth + ''' WITH INIT ,
> > NOUNLOAD , '; Set @sql=@sql + 'NAME = N''Copia de seguridad ' +
> > @bd + ''', SKIP ,
> > STATS = 10, NOFORMAT ';
> > Set @sql=@sql + 'DECLARE @i INT select @i = position from
> > msdb..backupset ';
> > Set @sql=@sql + 'where database_name=''' + @bd + '''and ';
> > Set @sql=@sql + 'type!=''F'' and backup_set_id=(select
> > max(backup_set_id) ';
> > Set @sql=@sql + 'from msdb..backupset ';
> > Set @sql=@sql + 'where database_name=''' + @bd + ''') ';
> > Set @sql=@sql + 'RESTORE VERIFYONLY FROM DISK = N''' + @pth + '''
> > WITH FILE = @i';
> > insert into test values (@sql);
> > Exec @sql;
> > Set @cont = ( @cont + 1 );
> > FETCH NEXT FROM bd_cur INTO @bd;
> > End;
> > CLOSE bd_cur;
> > DEALLOCATE bd_cur;
> > END;
> >
> >
>



/***************************************************************************
> > **/
>
>


email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida