I experienced into one issues for database backups were failed. And this was due to space issues on disk drive. This disk drive is spacific to allocated for the database backups only.
The space was eaten by this database backups and this drive contains so many old backups. I have manually deleted all files and continue this activity so many days.If you create a maintenance plans then it have option to delete old backups files. But i have the stored procedure for the database backups. So i do not have option to delete old and unused database backup files.
Finally, I have created a script to clean those old backups. I have created one stored procedure in which you need to pass there parameters, One is Backup type as want to delete full, differential or transaction log backups. Second is From days and third one is End day.
Please make sure XP_CMDSHELL is enabled in database instance as thisis require to enable it to delete database backup files to be deleted physically.
Here id query to enable it.
I have already told you as i have created script to delete the old DATABASEPROPERTY backups, please find below SP for the same.
Finally after creating a stored procedures , it is time to run and clean the old database backups. After running it will remove all the old database baclups as per specified parameters. Like we have passed 'D',3 and 10 with SP, So i will delete Full database backups whicl are older then 3 days ago and 10 days before created.
Which method you are using for old databsee backup maintenance? You can read my earlier posts for delete files using File System Task and Script Task in SSIS.
The space was eaten by this database backups and this drive contains so many old backups. I have manually deleted all files and continue this activity so many days.If you create a maintenance plans then it have option to delete old backups files. But i have the stored procedure for the database backups. So i do not have option to delete old and unused database backup files.
Finally, I have created a script to clean those old backups. I have created one stored procedure in which you need to pass there parameters, One is Backup type as want to delete full, differential or transaction log backups. Second is From days and third one is End day.
Please make sure XP_CMDSHELL is enabled in database instance as thisis require to enable it to delete database backup files to be deleted physically.
Here id query to enable it.
USE MASTER GO EXEC SP_CONFIGURE 'show advanced options',1 GO EXEC SP_CONFIGURE 'XP_CMDSHELL',1 GO RECONFIGURE GO
I have already told you as i have created script to delete the old DATABASEPROPERTY backups, please find below SP for the same.
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[DeleteDBBackupOldFiles] @BackupType char(1) = 'D', -- 'D'-Full, 'I'-Differential, 'L'-Log backup type @StartDayFromToday int, @EndDayFromToday int AS BEGIN SET NOCOUNT ON DECLARE @IsFileExists int DECLARE @DeletedFile VARCHAR(500) DECLARE @OldFiles VARCHAR(500) DECLARE OldFiles CURSOR FAST_FORWARD FOR SELECT bmf.physical_device_name from msdb.dbo.backupset bs INNER JOIN msdb.dbo.backupmediafamily bmf ON (bs.media_set_id=bmf.media_set_id) WHERE DEVICE_TYPE = 2 AND TYPE = @BackupType AND BACKUP_START_DATE < = GETDATE() - @StartDayFromToday AND BACKUP_START_DATE > = GETDATE() - @EndDayFromToday -- AND DATEDIFF(DAY,BACKUP_START_DATE,GETDATE()) > BETWEEN @StartDayFromToday and @EndDayFromToday OPEN OldFiles FETCH NEXT FROM OldFiles INTO @OldFiles WHILE @@FETCH_STATUS =0 BEGIN EXEC XP_FILEEXIST @OldFiles,@IsFileExists OUTPUT IF @IsFileExists=1 BEGIN PRINT 'Deleted File : ' + @DeletedFile SET @DeletedFile = 'DEL ' + @OldFiles EXEC XP_CMDSHELL @DeletedFile END FETCH NEXT FROM OldFiles INTO @OldFiles END CLOSE OldFiles DEALLOCATE OldFiles END
Finally after creating a stored procedures , it is time to run and clean the old database backups. After running it will remove all the old database baclups as per specified parameters. Like we have passed 'D',3 and 10 with SP, So i will delete Full database backups whicl are older then 3 days ago and 10 days before created.
EXEC [DeleteDBBackupOldFiles] @BackupType = 'D', @StartDayFromToday = 3, @EndDayFromToday = 10
Which method you are using for old databsee backup maintenance? You can read my earlier posts for delete files using File System Task and Script Task in SSIS.
0 comments:
Post a Comment