Sauvegarder par script toutes les bases de donnees d un serveur SQL 2000

le code est on ne peut plus simple :

  • Creation d'un fichier backup.bat avec :

"C:\Program Files\Microsoft SQL Server\80\Tools\Binn\osql.exe " -E --i C:\sauvegarde.sql

  • Et dans sauvegarde.sql :
DECLARE @OutputPath as varchar(200)
DECLARE @Database as varchar(200)
DECLARE @SQLStr as varchar(500)

-- Set this location to a directory where the SQL Server user context has
-- rights to write. Don't append a '\' to the path name, as it's being
-- appended below when the path is used.
SET @OutputPath = 'C:\Windows\temp'

-- Only get databases that do not have the following flags set:
-- 32 = loading.
-- 64 = pre recovery.
-- 128 = recovering.
-- 256 = not recovered.
-- 512 = offline; set with ALTER DATABASE.
-- 2048 = dbo use only; set with ALTER DATABASE RESTRICTED_USER.
-- 32768 = emergency mode.
DECLARE @Database_cur CURSOR
SET @Database_cur = CURSOR FOR
SELECT name FROM sysdatabases WHERE (status & 35808) = 0

OPEN @Database_cur
FETCH NEXT FROM @Database_cur INTO @Database

WHILE (@@fetch_status <> -1)
BEGIN
SET @SQLStr = 'BACKUP DATABASE [' + @Database + '] 
TO DISK = ''' + @OutputPath + '\' + @Database + '.BAK''' PRINT @SQLStr EXEC(@SQLStr) FETCH NEXT FROM @Database_cur INTO @Database END CLOSE @Database_cur DEALLOCATE @Database_cur