SHIFT

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


retensionscript
Differences

This shows you the differences between two versions of the page.

Link to this comparison view

retensionscript [2013/05/14 20:47] (current)
sjoerd created
Line 1: Line 1:
 += Script: Bash: AIX: Retension Scripts =
 +
 +This is a collection of retension scripts I created for different servers.
 +
 += DATA SYNCHRONIZATION SERVER =
 +<​code>​
 +#!/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
 +</​code>​
 +
 +== DATA SYNCHRONIZATION SERVER Start ==
 +Root crontab:
 +<​code>​
 +# Data retension - start after backup
 +00 08 * * * /​srv/​syncdata/​retension.sh
 +</​code>​
 +
 += APPLICATION SERVER =
 +<​code>​
 +#!/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
 +</​code>​
 +
 +== APPLICATION SERVER Start ==
 +Root crontab:
 +<​code>​
 +# Data retension - start after backup
 +00 08 * * * /​opt/​Scripts/​retension.sh
 +</​code>​
 +
 += Simple Retension Script Linux =
 +
 +<code bash>
 +#!/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
 +</​code>​
 +
 +{{tag>​scripts linux aix}}
  
retensionscript.txt ยท Last modified: 2013/05/14 20:47 by sjoerd