The following script is a simple way to backup all databases in SQL Server

DECLARE @name VARCHAR(250)         -- database name
DECLARE @path VARCHAR(250)          -- path for backup files
DECLARE @fileName VARCHAR(250)   -- filename for backup
DECLARE @fileDate VARCHAR(20)       -- used for file name

SET @path = 'E:\SQLBackups\'

SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112)

DECLARE db_cursor CURSOR FOR
SELECT name
FROM master.dbo.sysdatabases
WHERE name NOT IN ('master','model','msdb','tempdb')

OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name

WHILE @@FETCH_STATUS = 0
BEGIN
       SET @fileName = @path + @name + '_' + @fileDate + '.BAK'
       BACKUP DATABASE @name TO DISK = @fileName

       FETCH NEXT FROM db_cursor INTO @name
END

CLOSE db_cursor
DEALLOCATE db_cursor

SqlBackupAll (last edited 2013-07-16 12:29:58 by 24-151-197-61)