sql Backup Databases Stored Procedure

CREATE PROCEDURE Backup_UserDB
AS
BEGIN

	SET NOCOUNT ON;

	Declare @Date varchar(20)

	Declare @BackupFolder varchar(100)
	Declare @DBName varchar(100)
	Declare @BackupPath varchar(300)
	
	Set @BackupFolder = '\\server\share\'
	Set @Date = REPLACE(CONVERT(varchar, GETDATE(), 111), '/', '-')

	Set @DBName = 'db1'
	Set @BackupPath = @BackupFolder + @DBName + '_' + @Date + '.bak'
	BACKUP DATABASE @DBName TO DISK = @BackupPath
	
	Set @DBName = 'db2'
	Set @BackupPath = @BackupFolder + @DBName + '_' + @Date + '.bak'
	BACKUP DATABASE @DBName TO DISK = @BackupPath

END
GO
A Stored Procedure for backing up user databases.

Updated: Saturday 9th October 2010, 11:02pm

There are 0 comments

Leave a comment of your own

Comments are currently closed.