Total backup

,

Simple bugfixes of another script found on this site.

- bug 1 - Puntuation (dot) in database names made the script fail.

declare @IDENT INT, @sql varchar(1000), @DBNAME VARCHAR(200)

select @IDENT=min(DBID) from SYSDATABASES WHERE [DBID] > 0 AND NAME NOT IN ('PUBS', 'NORTHWIND', 'TEMPDB')
while @IDENT is not null
begin
	SELECT @DBNAME = NAME FROM SYSDATABASES WHERE DBID = @IDENT
/*Change disk location here as required*/
	SELECT @SQL = 'BACKUP DATABASE ['+@DBNAME+'] TO DISK = ''C:\#BACKUP\MSSQL data V2\'+replace(@DBNAME,'.','-') +'.BAK'' WITH INIT'
PRINT @SQL
	EXEC (@SQL)
	select @IDENT=min(DBID) from SYSDATABASES WHERE [DBID] > 0 and DBID>@IDENT AND NAME NOT IN ('PUBS', 'NORTHWIND', 'TEMPDB')
end

Rate

Share

Share

Rate