Friday, October 22, 2010

Create 7 days cycle backup devices

This is the stored procedure that creates 7 days cycle backup devices. The idea is to create a maximum of 7 backup files and recycle it every week. This backup concept is handy when you need a simple backup.

create proc mgt_create_backup_device (
 @db nvarchar(255),
 @folder nvarchar(100) 
)
as

begin

declare @device_name sysname,
 @file_name sysname

 select @device_name = @db + '_mon_bak', 
   @file_name = @folder + @db + '_mon_bak.bak'
 exec sp_addumpdevice 'disk', 
       @device_name, 
       @file_name

 select @device_name = @db + '_tue_bak', 
   @file_name = @folder + @db + '_tue_bak.bak'
 exec sp_addumpdevice 'disk', 
       @device_name, 
       @file_name

 select @device_name = @db + '_wed_bak', 
   @file_name = @folder + @db + '_wed_bak.bak'
 exec sp_addumpdevice 'disk', 
       @device_name, 
       @file_name

 select @device_name = @db + '_thu_bak', 
   @file_name = @folder + @db + '_thu_bak.bak'
 exec sp_addumpdevice 'disk', 
       @device_name, 
       @file_name

 select @device_name = @db + '_fri_bak', 
   @file_name = @folder + @db + '_fri_bak.bak'
 exec sp_addumpdevice 'disk', 
       @device_name, 
       @file_name

 select @device_name = @db + '_sat_bak', 
   @file_name = @folder + @db + '_sat_bak.bak'
 exec sp_addumpdevice 'disk', 
       @device_name, 
       @file_name

 select @device_name = @db + '_sun_bak', 
   @file_name = @folder + @db + '_sun_bak.bak'
 exec sp_addumpdevice 'disk', 
       @device_name, 
       @file_name

end
go

No comments:

Post a Comment