Archive

Archive for May, 2012

Shell Script: delete old files and keep latest N files

#!/bin/ksh

#****************************************************************

# SCRIPT: cleanup_BAK.sh

# PARAMETER: ORACLE_SID ($1)

# PURPOSE: cleanup old backup files

# DEPENDENCIES: <None>

#*****************************************************************

BAK_DIR=/oracle/backups/$1

# How many latest BAK files you want to keep

KEEP_HISTORY=3

# Delete the old BAK files

BAK_FILE_COUNT=`ls -ltr $BAK_DIR | grep $1 | grep BAK | wc -l | awk ‘{ print $1 }’ `

if [ $BAK_FILE_COUNT -gt $KEEP_HISTORY ]

then

DELETE_COUNT=`expr $BAK_FILE_COUNT – $KEEP_HISTORY`

echo "`date`: BAK file count : $BAK_FILE_COUNT"

echo "`date`: Delete count : $DELETE_COUNT"

echo

# Delete the old BAK files

for x in `ls -ltr $BAK_DIR | grep $1 | grep BAK | head -$DELETE_COUNT | awk ‘{ print $9 }’ `

do

echo "`date`: Going to delete old BAK file : $BAK_DIR/$x"

rm $BAK_DIR/$x

echo "`date`: File deleted sucessfully"

echo

done

fi

Categories: Uncategorized

SQL Server: Pin A Table in Memory

DECLARE @db_id int, @tbl_id int

USE DB_NAME

SET @db_id = DB_ID(‘DB_NAME’)

SET @tbl_id = OBJECT_ID(‘SCHEMA_NAME.TABLENAME’)

Categories: Uncategorized

Clear SQL Server cache

Use following commands to clean SQL server cache while testing

CHECKPOINT;

GO

DBCC DROPCLEANBUFFERS;

DBCC FREEPROCCACHE;

GO

Categories: Uncategorized