Results 1 to 2 of 2

Thread: Deleting old backups

  1. #1
    Tim McElmurry Guest

    Deleting old backups

    I am new to SQL backups but what I have done is created a script sp_BackupProcessor that is used to determine which backup type is run (Full,Differential,Transaction). I am backing up to the local drive and then our tape backup system backs up the files on our local system to tape. I only want to keep 3 days worth of backups on our local machine since the same information is stored on tape. What is the best way to handle this? Any help or ideas would be appreciated. I have included my script for reference.

    Thanks,

    Tim

    CREATE PROCEDURE sp_BackupProcessor
    @Help BIT = 0,
    @Database VARCHAR(30) = NULL,
    @BackupName VARCHAR(50) = NULL,
    @BackupType VARCHAR(4) = NULL,
    @Filename VARCHAR(255) = NULL,
    @Description VARCHAR(255) = NULL
    AS

    Parameters:
    @Database = ''master''
    -- Default = ''master''
    -- Specifies the database to backup.
    @BackupName = ''masterLOG''
    -- Default = ''masterLOG''
    -- Specifies a name for the backup.
    @BackupType = [''FULL'' | ''DIFF'' | ''LOG''],
    -- Default = ''LOG''
    -- ''FULL'' = Full database backup
    -- ''DIFF'' = Differential database backup
    -- ''LOG'' = Transaction Log Backup
    @Filename = ''C: empmasterLOG.TRN''
    -- Defualt = ''C: empmasterLOG.TRN''
    -- Specifies the file to use for the backup.
    -- Provide full path and filename.
    @Description = ''255 cahr max''
    -- Default = ''
    -- Specifies a description to attach to the bakup.
    Usage:
    sp_BackupProcessor
    @Database = ''Database'',
    @BackupName = ''BackupName'',
    @BackupType = [''FULL'' | ''DIFF'' | ''LOG''],
    @Filename = ''FullPathLocalFile'',
    @Description = ''Backup Description (255 max)''
    '
    RETURN 1
    END

    DECLARE @BackupStmt VARCHAR(500)
    SELECT @BackupStmt =
    CASE @BackupType
    WHEN 'FULL' THEN
    'BACKUP DATABASE ' + @Database + ' ' +
    'TO DISK = ''' + @Filename + ''' ' +

    'WITH RETAINDAYS = 2,' +
    'INIT' + ', ' +
    'NAME = ''' + @BackupName + ''', ' +
    'NOSKIP' + ', ' +
    'DESCRIPTION = ''' + @Description + ''', ' +
    'NOFORMAT'
    WHEN 'DIFF' THEN
    'BACKUP DATABASE ' + @Database + ' ' +
    'TO DISK = ''' + @Filename + ''' ' +
    'WITH DIFFERENTIAL' + ', ' +
    'NAME = ''' + @BackupName + ''', ' +
    'NOSKIP' + ', ' +
    'DESCRIPTION = ''' + @Description + ''', ' +
    'NOFORMAT'
    WHEN 'LOG' THEN
    'BACKUP LOG ' + @Database + ' ' +
    'TO DISK = ''' + @Filename + ''' ' +
    'WITH NOINIT' + ', ' +
    'NAME = ''' + @BackupName + ''', ' +
    'NOSKIP' + ', ' +
    'DESCRIPTION = ''' + @Description + ''', ' +
    'NOFORMAT'
    END
    EXECUTE(@BackupStmt)
    GO


  2. #2
    Guest

    Deleting old backups (reply)

    sql server has a backup wizard to let you set up your backup
    criteria easily


    ------------
    Tim McElmurry at 4/17/01 9:28:55 AM

    I am new to SQL backups but what I have done is created a script sp_BackupProcessor that is used to determine which backup type is run (Full,Differential,Transaction). I am backing up to the local drive and then our tape backup system backs up the files on our local system to tape. I only want to keep 3 days worth of backups on our local machine since the same information is stored on tape. What is the best way to handle this? Any help or ideas would be appreciated. I have included my script for reference.

    Thanks,

    Tim

    CREATE PROCEDURE sp_BackupProcessor
    @Help BIT = 0,
    @Database VARCHAR(30) = NULL,
    @BackupName VARCHAR(50) = NULL,
    @BackupType VARCHAR(4) = NULL,
    @Filename VARCHAR(255) = NULL,
    @Description VARCHAR(255) = NULL
    AS

    Parameters:
    @Database = ''master''
    -- Default = ''master''
    -- Specifies the database to backup.
    @BackupName = ''masterLOG''
    -- Default = ''masterLOG''
    -- Specifies a name for the backup.
    @BackupType = [''FULL'' | ''DIFF'' | ''LOG''],
    -- Default = ''LOG''
    -- ''FULL'' = Full database backup
    -- ''DIFF'' = Differential database backup
    -- ''LOG'' = Transaction Log Backup
    @Filename = ''C: empmasterLOG.TRN''
    -- Defualt = ''C: empmasterLOG.TRN''
    -- Specifies the file to use for the backup.
    -- Provide full path and filename.
    @Description = ''255 cahr max''
    -- Default = ''
    -- Specifies a description to attach to the bakup.
    Usage:
    sp_BackupProcessor
    @Database = ''Database'',
    @BackupName = ''BackupName'',
    @BackupType = [''FULL'' | ''DIFF'' | ''LOG''],
    @Filename = ''FullPathLocalFile'',
    @Description = ''Backup Description (255 max)''
    '
    RETURN 1
    END

    DECLARE @BackupStmt VARCHAR(500)
    SELECT @BackupStmt =
    CASE @BackupType
    WHEN 'FULL' THEN
    'BACKUP DATABASE ' + @Database + ' ' +
    'TO DISK = ''' + @Filename + ''' ' +

    'WITH RETAINDAYS = 2,' +
    'INIT' + ', ' +
    'NAME = ''' + @BackupName + ''', ' +
    'NOSKIP' + ', ' +
    'DESCRIPTION = ''' + @Description + ''', ' +
    'NOFORMAT'
    WHEN 'DIFF' THEN
    'BACKUP DATABASE ' + @Database + ' ' +
    'TO DISK = ''' + @Filename + ''' ' +
    'WITH DIFFERENTIAL' + ', ' +
    'NAME = ''' + @BackupName + ''', ' +
    'NOSKIP' + ', ' +
    'DESCRIPTION = ''' + @Description + ''', ' +
    'NOFORMAT'
    WHEN 'LOG' THEN
    'BACKUP LOG ' + @Database + ' ' +
    'TO DISK = ''' + @Filename + ''' ' +
    'WITH NOINIT' + ', ' +
    'NAME = ''' + @BackupName + ''', ' +
    'NOSKIP' + ', ' +
    'DESCRIPTION = ''' + @Description + ''', ' +
    'NOFORMAT'
    END
    EXECUTE(@BackupStmt)
    GO


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •