Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools


The following script will show you some powerful technique to script backup task for system/user database. Example also shows how to create one file which contains several backups which can expire at specified date.

Click here to copy the following block
--drop table #tmpDevice

create table #tmpDevice (device_name sysname, physical_name varchar(255), desription varchar(255), status int, cntrltype smallint, size int)

--//get exisitng backup devices
insert into #tmpDevice
   exec sp_helpdevice

--//find 'Daily_Sys_Full_Bak'
declare @count int
select @count = count(*) from #tmpDevice where charindex('Daily_Sys_Full_Bak', device_name) > 0

--select * from #tmpdevice where charindex('Daily_Sys_Full_Bak', device_name) > 0

--//drop 'Daily_Sys_Full_Bak' device if already exists
declare @ret int
if @count > 0
   begin
   exec @ret = sp_dropdevice 'Daily_Sys_Full_Bak'
   end

EXEC  sp_addumpdevice 'disk', 'Daily_Sys_Full_Bak', 'c:\BW_Sys_Full_111705.bak'

--//Following DB backups will be written to Disk dump named "Daily_Sys_Full_Bak".

BACKUP DATABASE master TO Daily_Sys_Full_Bak WITH Name = 'MASTER_FULL' , INIT --//Any new backup overwrites the exisiting backup for master DB
BACKUP DATABASE msdb TO Daily_Sys_Full_Bak WITH Name = 'MSDB_FULL', INIT --//Any new backup overwrites the exisiting backup for msdb DB
--BACKUP DATABASE msdb TO Daily_Sys_Full_Bak WITH Name = 'MSDB_FULL', RETAINDAYS =2 --//This DB backup expires after 2 days
--BACKUP DATABASE msdb TO Daily_Sys_Full_Bak WITH Name = 'MSDB_FULL', EXPIREDATE ='11/19/2005' --//This DB backup expires on 11/19/2005


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.