Need a script to backup DB and delete old backups

  • I need a script for SQL Server 2000 which can backup the database as well as delete the backup files older than 2 days.

    I know I can do it with Maintenance plans but this is a special requirement.

    Can someone help me please

  • I managed to modify a script which will take backup with time frame.

    --Full backup using datetime file name

    DECLARE @devname varchar(256)

    DECLARE @DirLocationPre varchar(256)

    DECLARE @DatabaseName varchar(256)

    SET @DirLocationPre = 'D:\DBName\'

    SET @DatabaseName = 'DBName'

    SELECT @devname = @DirLocationPre + @DatabaseName + '_' + 'db' + '_' + REPLACE(REPLACE(REPLACE(CONVERT(Varchar(40), GETDATE(), 120),'-',''),':',''), ' ', '') + '.bak';

    BACKUP DATABASE @DatabaseName to DISK = @devname

    GO

    Now, i need a script which can delete backups older than 2 days. Can someone help me please

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply