I get the following error when I execute SP in SQL Server 2008 Management Studio:
Msg 208, Level 16, State 6, Procedure BackupDB, Line 36
Invalid object name 'dbo.BackupDB'.
use [Master];
go
alter procedure dbo.BackupDB
@dbName varchar(128),
@path varchar(256)
as
begin
declare @device1 varchar(256);
declare @device2 varchar(256);
declare @path1 varchar(256);
declare @path2 varchar(256);
declare @sql varchar(500);
if @dbName is null or @path is null
raiserror('Error: Database name and/or Path missing', 10, 1);
if not exists(select * from sys.databases where name = @dbName)
raiserror('Database %s does not exist', 10, 1, @dbName);
begin
set @sql = 'ALTER DATABASE ' + @dbName + '; SET RECOVERY FULL;';
exec(@sql);
set @device1 = @dbName + '_Data';
set @device2 = @dbname + '_Log';
set @path1 = @path + '\' + @dbname + '_Data.bak';
set @path2 = @path + '\' + @dbname + '_Log.bak';
print 'path :' + @path1;
print 'path :' + @path2;
exec sp_addumpdevice 'disk', @device1, @path1;
exec sp_addumpdevice 'disk', @device2, @path2;
backup database @dbName TO @device1;
backup log @dbName TO @device2;
end
end
go