retensionscript
Table of Contents
Script: Bash: AIX: Retension Scripts
Summary: A collection of file retention scripts on AIX.
Date: 27 June 2011
Refactor: 22 March 2025: Checked links and formatting.
This is a collection of retension scripts I created for different servers.
DATA SYNCHRONIZATION SERVER
#!/bin/bash #This script should run after the backups has been placed on the server ### Script Variables TODAY=`date +%Y%m%d` LOGFILE=/srv/syncdata/retension.log MAIL="sjoerd_ @ _ getshifting.com" FAILMAIL=0 HOST=`hostname -s` ### LDAP Cleanup Variables LDAP_BASE=/srv/syncdata/LDAP LDAP_RETENSION=+7 LDAP_BACKUPFILE="${LDAP_BASE}/frontend.company.local_o=warmetal.nl_${TODAY}0255.ldif.gz" ### Oracle Cleanup Variables ORACLE_BASE=/srv/syncdata/Oracle ORACLE_ARCHIVE_RETENSION=+7 ORACLE_RMAN_RETENSION=+4 ORACLE_APPLICATION_FILE="${ORACLE_BASE}/backend_application/backend_application-RMAN_${TODAY}0131.tgz" ### Create new logfile echo "Start retension on $HOST on $TODAY" > $LOGFILE ### Start Cleanup but only if a backup of today has been created echo >> $LOGFILE if [ -f "${ORACLE_APPLICATION_FILE}" ]; then echo "Start Oracle Schema Quaestor Cleanup" >> $LOGFILE find $ORACLE_BASE/backend_application/. -maxdepth 1 -type f -mtime ${ORACLE_RMAN_RETENSION} -exec rm {} \; >> $LOGFILE find $ORACLE_BASE/backend_application/pfile/. -maxdepth 1 -type f -mtime ${ORACLE_RMAN_RETENSION} -exec rm {} \; >> $LOGFILE find $ORACLE_BASE/backend_application/archive/. -maxdepth 1 -type f -mtime ${ORACLE_ARCHIVE_RETENSION} -exec rm {} \; >> $LOGFILE else echo "No Cleanup of Oracle Schema Quaestor - there's something wrong with the backup file" >> $LOGFILE FAILMAIL=1 fi if [ -f "${LDAP_BACKUPFILE}" ]; then echo >> $LOGFILE echo "Start LDAP Cleanup" >> $LOGFILE find $LDAP_BASE/. -maxdepth 1 -type f -mtime ${LDAP_RETENSION} -exec rm {} \; >> $LOGFILE find $LDAP_BASE/archive/. -maxdepth 1 -type f -mtime ${LDAP_RETENSION} -exec rm {} \; >> $LOGFILE else echo "No Cleanup of LDAP - there's something wrong with the backup file" >> $LOGFILE FAILMAIL=1 fi ### MAIL Results if [ "$FAILMAIL" == 1 ]; then cat $LOGFILE | mail -s "FAILED Retension $HOST" $MAIL else cat $LOGFILE | mail -s "Result Retension $HOST" $MAIL fi ### End of Script exit 0
DATA SYNCHRONIZATION SERVER Start
Root crontab:
# Data retension - start after backup 00 08 * * * /srv/syncdata/retension.sh
APPLICATION SERVER
#!/bin/bash #This script should run after the backups has been placed on the server ### Script Variables TODAY=`date +%Y%m%d` LOGFILE=/opt/Scripts/retension.log MAIL="sjoerd_ @ _ getshifting.com" FAILMAIL=0 HOST=`hostname -s` ### Oracle Cleanup Variables ORACLE_BASE=/var/backup/oracle ORACLE_ARCHIVE_RETENSION=+7 ORACLE_RMAN_RETENSION=+4 ORACLE_APPLICATION_FILE="${ORACLE_BASE}/rman_backupdir/backend_application-RMAN_${TODAY}0131.tgz" ### Report Cleanup Variables REPDIR1="/var/reports/business_reports/*/done" REPDIR2="/var/reports/partner_reports/done" REPORT_RETENSION=+7 ### App Cleanup Variables APPDIR1="/app/eapp/log" APP_RETENSION=+61 ### Create new logfile echo "Start retension on $HOST on $TODAY" > $LOGFILE ### Start Cleanup but only if a backup of today has been created echo >> $LOGFILE if [ -f "${ORACLE_QUAESTOR_FILE}" ]; then echo "Start Oracle Schema Quaestor Cleanup" >> $LOGFILE find $ORACLE_BASE/rman_backupdir/. -type f -mtime ${ORACLE_RMAN_RETENSION} -print -exec rm {} \; >> $LOGFILE find $ORACLE_BASE/pfile/. -type f -mtime ${ORACLE_RMAN_RETENSION} -print -exec rm {} \; >> $LOGFILE find $ORACLE_BASE/10.2/archive/. -type f -mtime ${ORACLE_ARCHIVE_RETENSION} -print -exec rm {} \; >> $LOGFILE else echo "No Cleanup of Oracle Schema Quaestor - there's something wrong with the backup file" >> $LOGFILE FAILMAIL=1 fi ### Start Report Cleanup echo >> $LOGFILE echo "Starting Cleanup of $REPDIR1" >> $LOGFILE find $REPDIR1/. -type f -mtime ${REPORT_RETENSION} -print -exec rm {} \; >> $LOGFILE echo "Starting Cleanup of $REPDIR2" >> $LOGFILE find $REPDIR2/. -type f -mtime ${REPORT_RETENSION} -print -exec rm {} \; >> $LOGFILE ### Start APP Cleanup echo >> $LOGFILE echo "Starting Cleanup of $APPDIR1" >> $LOGFILE find $APPDIR1/. -type f -mtime ${APP_RETENSION} -print -exec rm {} \; >> $LOGFILE ### MAIL Results if [ "$FAILMAIL" == 1 ]; then cat $LOGFILE | mail -s "FAILED Retension $HOST" $MAIL else cat $LOGFILE | mail -s "Result Retension $HOST" $MAIL fi ### End of Script exit 0
APPLICATION SERVER Start
Root crontab:
# Data retension - start after backup 00 08 * * * /opt/Scripts/retension.sh
Simple Retension Script Linux
#!/bin/bash ######################################################################################################################## # Author : Sjoerd Hooft # Date Initial Version: 27 Jun 2011 # Comments: sjoerd_warmetal_nl # # Description: # This is a default retention script for the /tmp directory on SLES linux servers. # # Recommendations: # The script is designed for a 120 column terminal. # The running user must be root. # # Changes: # Please comment on your changes to the script (your name and email address, line number, description): ######################################################################################################################## # Script Variables HOSTNAME_SHORT=`hostname -s` BASEDIR=`dirname $0` WHATAMI=`basename $0` LOGFILE="$BASEDIR/$WHATAMI.log" DATE=`date +%Y%m%d` #TERM=linux #BOLD=`tput bold` #BOLDOFF=`tput sgr0` TOMAIL=sjoerd_warmetal_nl # Send all output to logfile exec > $LOGFILE 2>&1 # Retension Variables RETENSIONTIME=+7 TMP=/tmp # Start Retension find $TMP/. -mtime ${RETENSIONTIME} -print -exec rm -rf {} \; >> $LOGFILE ### MAIL Results cat $LOGFILE | mail -s "Result Retension ${HOSTNAME_SHORT}" $TOMAIL ### End of Script exit 0
retensionscript.txt · Last modified: by 127.0.0.1