Quantcast
Channel: SQL Server High Availability and Disaster Recovery forum
Viewing all articles
Browse latest Browse all 4689

maintenance plan overwrites backups

$
0
0

I am in SQL Server 2005 SP2 64 bit Standard Edition and created a maintenance plan to delete backup files that are older than 24 hours.  It looks in a particular folder for the bak extension to do this.  The second task in the plan is to write the backup.  Below is the code for that.  The problem I am having is that the plan is overwriting the differential backups every time it runs.  What I am trying to do is have it write the back 24 times, once each hour, and then delete the file when it is over 24 hours old and write a new backup.  This allows me to keep one full backup, running from a different SQL Agent job and 24 differentials.  Why is my maintenance plan over writing the differential every time?

declare @f sysname
set @f=N'\\stlbackup01\SQLBackups\InstanceName\InstanceName_diffbackup_'+replace(convert(nvarchar,getdate(),100), ':', '_')+N'.bak'

BACKUP DATABASE [MyDB] TO  DISK =@f
WITH DIFFERENTIAL
,NOFORMAT
, INIT
,  NAME = N'MyDB-Differential Database Backup'
, SKIP
, NOREWIND
, NOUNLOAD
,  STATS = 10


Lee Markum


Viewing all articles
Browse latest Browse all 4689

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>