Zasfe
Zasfe's memory
Zasfe
전체 방문자
오늘
어제
  • 분류 전체보기 (143)
    • 이야기 (50)
    • 뜻알기 (1)
    • 컴퓨터 (91)

인기 글

최근 글

태그

  • Microsoft Windows 2000 Scripting Guide
  • MSSQL
  • webknight
  • Function
  • 생각
  • VBScript
  • 홈페이지 보안 강화도구
  • 캐슬
  • IIS
  • IIS7
  • error
  • 보안
  • webshell
  • webhacking
  • Autoit
  • 배치파일
  • rsync
  • MSSQL2K
  • webknight 2.2
  • ASP
  • web.config
  • nslookup
  • 저장프로시저
  • webknight2.2
  • webknight2.1
  • cmd
  • Skin
  • Castle
  • backup
  • Security
hELLO · Designed By 정상우.
Zasfe

Zasfe's memory

컴퓨터

2년전 백업 정보 삭제 쿼리(mssql 2000)

2010. 1. 27. 14:00

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
    '컴퓨터' 카테고리의 다른 글
    • 데이터베이스 간략정보 추출 쿼리
    • UTC 시간을 확인하기 위한 스크립트
    • WebDAV 인증 우회에 대한 취약점
    • IIS 파일확장자 우회취약점은 IIS6 에서만 동작합니다.
    Zasfe
    Zasfe
    느낌. 기억

    티스토리툴바