1

We need to backup 40 databases inside a SQL Server instance. We backup each database with the following script:

BACKUP DATABASE [dbname1] TO  DISK = N'J:\SQLBACKUPS\dbname1.bak' WITH NOFORMAT, INIT,  NAME = N'dbname1-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO
declare @backupSetId as int
select @backupSetId = position from msdb..backupset where database_name=N'dbname1' and backup_set_id=(select max(backup_set_id) from msdb..backupset where database_name=N'dbname1' )
if @backupSetId is null begin raiserror(N'Verify failed. Backup information for database ''dbname1'' not found.', 16, 1) end
RESTORE VERIFYONLY FROM  DISK = N'J:\SQLBACKUPS\dbname1.bak' WITH  FILE = @backupSetId,  NOUNLOAD,  NOREWIND
GO

We will like to add to the script the functionality of taking each database and replacing it in the above script. Basically a script that will create and verify each database backup from an engine.

I am looking for something like this:

For each database in database-list
    sp_backup(database) // this is the call to the script above.
End For

any ideas?

1
  • ... and restores; how do you restore with a script? Commented Jun 25, 2014 at 11:10

5 Answers 5

2

Use SqlBackupAndFTP. Select "Backup all non-system databases"

Sign up to request clarification or add additional context in comments.

Comments

1

Maybe you can check the sp_MSForEachDB stored procedure.

EXEC sp_MSForEachDB 'EXEC sp_backup ?'

Where the ? mark stands for the current database on each iteration.

Comments

1

You said "verify" too... This would require a 2nd statement per database (RESTORE VERIFYONLY, as well the other answers offered.

I'd investigate using maintenance plans to include index maintenance too...

Comments

0

Something like:

DECLARE @SQL varchar(max)
SET @SQL = ''

SELECT @SQL = @SQL + 'BACKUP ' + Name + ' To Disk=''c:\' + Name + '.bak'';'
    FROM sys.sysdatabases

EXEC(@SQL)

Comments

0

SQL Backup Master has the ability to back up all databases on a given server instance and then send the backups to Dropbox, FTP, Amazon S3, Google Drive, or local/network folder.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.