Wednesday, June 29, 2011

Scripted Backups Example 2

USE master 
GO

DECLARE @theday char(1)
      , @file varchar(128)

   SET @theday = datepart(dw, getdate())

   ALTER DATABASE dbname SET RECOVERY SIMPLE;

   SET @file = 'D:\BACKUPS\dbname_' + @theday + '.bak';

   BACKUP DATABASE dbname TO DISK = @file WITH INIT;

   BACKUP LOG dbname WITH TRUNCATE_ONLY;

 GO


This does a 7 day "rolling backup", overwriting the backup from last week. Set it up on a nightly job.

No comments:

Post a Comment