DECLARE @backupID int
DECLARE @mediaID int
DECLARE @restoreID int
DECLARE @year char(4)
DECLARE @month char(2)
DECLARE @day char(2)
DECLARE @deleteday char(10)
SET @year = year(getdate())-2 -- 2년전
SET @month = month(getdate())
SET @day = day(getdate())
IF len(@month) = 1
SET @month = '0'+ @month
IF len(@day) = 1
SET @day = '0'+ @day
SET @deleteday = @year +'-'+ @month +'-'+ @day
SELECT TOP 1 @backupID = backup_set_id, @mediaID = media_set_id from msdb..backupset
where
backup_finish_date > @deleteday
SELECT TOP 1 @restoreID = restore_history_id From msdb..restorehistory
Where
restore_date > @deleteday
delete from msdb..restorefile where restore_history_id < @restoreID
delete from msdb..restorefilegroup where restore_history_id < @restoreID
delete from msdb..restorehistory where restore_history_id < @restoreID or backup_set_id < @backupID
delete from msdb..backupfile where backup_set_id < @backupID
delete from msdb..backupmediafamily where media_set_id < @mediaID
delete from msdb..backupset where backup_set_id < @backupID
use msdb
DBCC SHOWCONTIG
DBCC DBREINDEX (restorefile, '', 100)
DBCC DBREINDEX (restorefilegroup, '', 100)
DBCC DBREINDEX (restorehistory, '', 100)
DBCC DBREINDEX (backupfile, '', 100)
DBCC DBREINDEX (backupmediafamily, '', 100)
DBCC DBREINDEX (backupset, '', 100)
'컴퓨터' 카테고리의 다른 글
데이터베이스 간략정보 추출 쿼리 (0) | 2010.01.28 |
---|---|
UTC 시간을 확인하기 위한 스크립트 (0) | 2010.01.28 |
WebDAV 인증 우회에 대한 취약점 (0) | 2010.01.27 |
IIS 파일확장자 우회취약점은 IIS6 에서만 동작합니다. (1) | 2009.12.30 |
커맨드라인의 활용 - 변수를 쓰자 (0) | 2009.12.15 |