initial commit of a *whole bunch* of old Egressive shell scripts, used to make many people redundant.

This commit is contained in:
Dave Lane 2016-03-16 13:43:31 +13:00
commit 43e0f5b59e
329 changed files with 31937 additions and 0 deletions

20
ebu/conf/daily.conf Normal file
View file

@ -0,0 +1,20 @@
#
# configuration file for /etc/ebu/ebu, a simple script for doing
# tar-based backups.
#
# base filename for the backups...
BU_FROOT="daily"
CURRENT_LINK="Current"
#
# directory in which to save the backups...
BU_DIR=/extra/apu
#
# directories to back up
FILES="/home /etc /var/www /var/spool/mail"
#
# directories/files to exclude
EXCLUDE=" home/sites/subversion home/vmware home/server *.log *Cache* *cache* *~ */tmp *nobackup*"
#
# removal all but the $BU_TO_KEEP most recent
# backups.
BU_TO_KEEP=2

20
ebu/conf/weekly.conf Normal file
View file

@ -0,0 +1,20 @@
#
# configuration file for /etc/ebu/ebu, a simple script for doing
# tar-based backups.
#
# base filename for the backups...
BU_FROOT="weekly"
CURRENT_LINK="Current"
#
# directory in which to save the backups...
BU_DIR=/extra/apu
#
# directories to back up
FILES="/home /etc /var/www /var/spool/mail"
#
# directories/files to exclude
EXCLUDE=" home/sites/subversion home/vmware home/server *.log *Cache* *cache* *~ */tmp *nobackup*"
#
# removal all but the $BU_TO_KEEP most recent
# backups.
BU_TO_KEEP=2

349
ebu/ebu Executable file
View file

@ -0,0 +1,349 @@
#!/bin/bash
#
# Simple script to do a comprehensive regular tar backup of build.egressive.com
# Copyright 1999-2003, David Lane for Egressive Limited, www.egressive.com
#
#
VERSION=0.7.0
NAME=ebu
#
# Defaults
#
# default email address to which to send backup reports
DEF_EMAIL=root@localhost
#
# default email subject
DEF_EMAIL_SUBJ="Default Backup report"
#
# default configuration file
DEF_BU_CONF=/etc/egscripts/ebu/ebu.conf
#
# default log file
DEF_LOG=/var/log/ebu.log
#
# default filename root
DEF_BU_FROOT="defaultname"
#
#
DEF_STAT_DIR=/var/log/stats
#
# for pruning old backups
#
# build list of possible pruning candidates
BU_SUFFIX="tgz"
LIST_SUFFIX="list"
#
# pattern for "ls" command to build list of
# pruneable backup files...
# -1t = 1 column, ordered by time of last mod
PRUNEABLES_CMD="ls -1t"
#
# Commands
#
# tar command
TAR=/bin/tar
# tar command options
FLAGS=" cvfz "
# grep command
GREP=/bin/grep
# wc (word count) command
WC=/usr/bin/wc
# awk command
AWK=/bin/awk
# don't worry, this is just used to determine if the
# disk is installed - it's not going to change the partition table!
FDISK=/sbin/fdisk
# determine today's date
DATE=`date '+%Y-%m-%d-%a'`
# determine today's date
TIME=`date '+%H-%M-%S'`
# email program
MAIL=/bin/mail
#
# temporary holding point for email
TMP_EMAIL=/tmp/tmp_email.$DATE_$TIME
#
# function to direct a message...
message() {
#
# a timestamp for logging purposes
TIMESTAMP=`date '+%Y-%m-%d %H:%M.%S'`
echo "$0: $TIMESTAMP $@" >> $LOG
if test -f $TMP_EMAIL ; then
echo "$0: $TIMESTAMP $@" >> $TMP_EMAIL
fi
verbose "$TIMESTAMP $@"
}
#
# create the temporary email file
create_tmp_email() {
touch $TMP_EMAIL
if test -f $TMP_EMAIL ; then
message "created temporary email file: $TMP_EMAIL"
else
message "failed to create temporary email file: $TMP_EMAIL"
fi
}
#
# send the contents of the temporary file to the
# designated report recipient
send_email_report() {
if test -f $TMP_EMAIL ; then
message "sending email report to $EMAIL"
$MAIL -s "$EMAIL_SUBJ" $EMAIL < $TMP_EMAIL
rm $TMP_EMAIL
if test -f $TMP_EMAIL ; then
message "failed to remove temporary email file: $TMP_EMAIL"
else
message "successfully removed temporary email file: $TMP_EMAIL"
fi
message "email report successfully sent"
fi
}
#
# insert a blank line into the log and on the console
insert_blank() {
echo "" >> $LOG
verbose ""
}
#
# function to direct a message...
verbose() {
if test $VERBOSE = 1 ; then
echo "$@"
fi
}
#
# build excludes list
build_excludes() {
message "building excludes"
for PAT in $EXCLUDE
do
EXCLUDES="$EXCLUDES --exclude $PAT"
done
}
#
# function to initiate backup
backup() {
build_excludes
EBU_NAME=`basename $0`
BU_CONF_NAME=`basename $BU_CONF`
echo "CURRENT_LINK = $CURRENT_LINK"
if test ! $CURRENT_LINK = "none" ; then
message "removing link: $BU_DIR/$CURRENT_LINK"
# first remove any existing link
rm $BU_DIR/$CURRENT_LINK.$BU_SUFFIX
fi
BU_CMD="$TAR $FLAGS $BU_DIR/$BU_FILE $FILES $EXCLUDES"
message "Executing backup command: $BU_CMD"
$BU_CMD > $BU_DIR/$BU_LIST
if test "$?" -ne "0" ; then
MSGCONF=`basename $BU_CONF`
message "-------Backup ended with error, error: $? ----------"
echo "error: $?" > $STAT_DIR/$NAME-$MSGCONF
else
message "+++++++Backup $BU_FILE successfully finished++++++++"
NUM_FILES=`$WC $BU_DIR/$BU_LIST | $AWK '{print $1}'`
message "Backed up $NUM_FILES files..."
message "Backup size: `ls -l $BU_DIR/$BU_FILE | $AWK '{print $5;}'` bytes"
echo "success: $NUM_FILES backed up (`ls -l $BU_DIR/$BU_FILE | $AWK '{print $5;}'` bytes)" > $STAT_DIR/$NAME-$MSGCONF
# if the variable $CURRENT_LINK is defined in the .conf file, make
# a link to it.
if test ! $CURRENT_LINK = "none" ; then
message "Linking $BU_DIR/$CURRENT_LINK to $BU_DIR/$BU_FILE..."
# create a new link to the current archive
ln -f $BU_DIR/$BU_FILE $BU_DIR/$CURRENT_LINK.$BU_SUFFIX
fi
if [ -e "$BU_DIR/$BU_LIST.gz" ]; then
rm $BU_DIR/$BU_LIST.gz
fi
gzip $BU_DIR/$BU_LIST
fi
}
#
# delete old backups
delete_old() {
#
if test -n $BU_FROOT && test -n $BU_TO_KEEP ; then
# pattern to search for to build the list...
PATTERN="$BU_DIR/$BU_FROOT.*"
# build the list, with the suffix...
PRUNEABLES=`$PRUNEABLES_CMD $PATTERN.$BU_SUFFIX`
if test "$?" -eq "0" ; then
message "pruning older files based on $PATTERN.$BU_SUFFIX"
message "keeping last $BU_TO_KEEP backups"
#
# set counter
NUM=0
# go through the list of files and remove those we don't want
for PRUNEABLE in $PRUNEABLES
do
NUM=$(($NUM + 1))
if test $NUM -gt $BU_TO_KEEP ; then
message "deleting $PRUNEABLE and associated list files"
BASE=`basename $PRUNEABLE .$BU_SUFFIX`
rm $BU_DIR/$BASE.$BU_SUFFIX 2>&1 > /dev/null
rm $BU_DIR/$BASE.$LIST_SUFFIX 2>&1 > /dev/null
rm $BU_DIR/$BASE.$LIST_SUFFIX.gz 2>&1 > /dev/null
else
message "keeping $PRUNEABLE"
fi
done
fi
else
message "keeping older backups, missing backup_root_filename..."
fi
}
#
# control loop, using external arguments
#
# process command line arguments
#
# set some default values, so that we can test if they've
# been set in the configuration file...
VERBOSE=0
BU_CONF=0
CURRENT_LINK="none"
LOG=""
TMP_EMAIL=/dev/null
#
# set the default mode in case somebody figures out how to get
# past the options below...
MODE=help
#
# cycle through the commandline options
while test $# -ne 0 ; do # while there are arguments
case $1 in
--fileroot|-r)
shift
verbose "setting file root to $1"
BU_FROOT=$1
;;
--config|-c)
shift # shift from the flag to the value
verbose "setting configuration file to $1"
BU_CONF=$1 # record the value
;;
--email|-e)
shift # shift from the flag to the value
verbose "setting temporary email file to $1"
TMP_EMAIL=$1 # record the value
;;
--log|-l)
shift # shift from the flag to the value
verbose "setting log file to $1"
LOG=$1 # record the value
;;
--verbose|-v)
VERBOSE=1
verbose "setting verbosity to true"
;;
--backup|-b)
MODE=backup
verbose "setting mode to $MODE"
;;
--delete_old|-d)
MODE=delete_old
verbose "setting mode to $MODE"
;;
--help|-?|?|-h)
MODE=help
verbose "setting mode to $MODE"
;;
esac
shift
done
#
# read in config info, from the config
# file provided, or, if none is provided
# from the default file...
if test -f $BU_CONF ; then
. $BU_CONF
verbose "reading config file: $BU_CONF"
elif test -f "$DEF_BU_CONF" ; then
verbose "reading default config file: $DEF_BU_CONF"
. "$DEF_BU_CONF"
else
verbose "config file $DEF_BU_CONF does not exist!"
exit 1
fi
#
# set the email address to mail results to
#
if test -z $EMAIL ; then
EMAIL=$DEF_EMAIL
fi
#
# set the email subject for results
#
if test -z "$EMAIL_SUBJ" ; then
EMAIL_SUBJ="$DEF_EMAIL_SUBJ"
fi
#
# whack the date on there
EMAIL_SUBJ="$EMAIL_SUBJ for $DATE"
#
# set the log file appropriately
#
if test -z $LOG ; then
LOG=$DEF_LOG
fi
#
# set the log file appropriately
#
if test -z $STAT_DIR ; then
STAT_DIR=$DEF_STAT_DIR
fi
#
# if a file root form wasn't specified use
# a default
if test -z $BU_FROOT ; then
BU_FROOT=$DEF_BU_FROOT
verbose "using default file rootname: $BU_FROOT"
fi
#
# use it to build a filename list for the backup
BU_FILE="$BU_FROOT.$DATE.$TIME.$BU_SUFFIX"
BU_LIST="$BU_FROOT.$DATE.$TIME.$LIST_SUFFIX"
message "backup files: $BU_FILE, $BU_LIST"
#
# Now actually try to do the job we've been asked to do...
#
case $MODE in
backup)
# create_tmp_email
delete_old
backup
# send_email_report
insert_blank
;;
delete_old)
delete_old
insert_blank
;;
help)
echo ""
echo "$0 version $VERSION, copyright 1999-2001 Egressive Limited, www.egressive.com"
echo ""
echo "Use tar to backup up a series of paths (excluding some files if desired) onto"
echo "a filesystem (optionally removable), recording the list of files "
echo "in a gzipped file alongside the tar archive"
echo ""
echo "Usage: $0 {-b|-d} [tarfile_root]"
echo "-b or --backup - initiates tar of"
echo " files listed in $DEF_BU_CONF - optionally takes"
echo " a backup file rootname, e.g. weekly-backup"
echo "-d or --delete_old - removes backups older than cutoffs"
echo " specified in $DEF_BU_CONF"
echo "-v or --verbose - give extra feedback on progress to stdout"
echo "-c or --config config_filename - use an alternate configuration file"
echo "-e or --email - filename of the temporary email file to pump backup into into"
echo "-l or --log log_filename - use an alternate log file"
echo "-r or --fileroot tarfile_root - optional parameter specifies the"
echo " root filename for the tar and log files"
echo "-? or --help - display this help information"
echo ""
exit 1
;;
esac
exit 0

15
ebu/ebu.cron Executable file
View file

@ -0,0 +1,15 @@
#
# run system backups
#
# daily - at 2:30 am, mon-sat
30 2 * * mon,tue,wed,thu,fri,sat root /etc/egscripts/ebu/run_daily
#
# weekly - at 2:30 am, sun
#30 2 * * sun root /etc/egscripts/ebu/run_weekly
#
# monthly - at 3:30 am, on the first of the last of the month
#30 3 1 * * root /etc/egscripts/ebu/run_monthly
#
# yearly - at 1:30 am, on the last day of the year
#30 1 1 1 * root /etc/egscripts/ebu/run_yearly

100
ebu/run_daily Executable file
View file

@ -0,0 +1,100 @@
#!/bin/bash
#
# this script runs a series of daily backup files, one after another
#
#-------------
#-- EGAlert --
EGALERT=/etc/egalert/egalert
EGALERT_DAYSTAMP=`date '+%Y-%m-%d'`
$EGALERT run "$EGALERT_DAYSTAMP-ebu"
#-- EGAlert --
#-------------
# These should be the only parameters requiring alteration
# the root filename for the appropriate configuration files
# in $EBU_CONF_DIR
CONF_ROOT="daily"
# the email subject for report emails - to have date added
EMAIL_SUBJ="Warhol Daily Backup Report"
# the email address (or addresses with comma separation) to send it to
EMAIL=dlane@egressive.com
#
# directories...
EBU_DIR=/etc/ebu
EBU_CMD=$EBU_DIR/ebu
EBU_CONF_DIR=$EBU_DIR/conf
LOGS=/var/log
LOG=$LOGS/ebu.log
# determine today's date
DATE=`date '+%Y-%m-%d-%a'`
# determine today's date
TIME=`date '+%H-%M-%S'`
# email program
MAIL=/bin/mail
# a timestamp for logging purposes
TIMESTAMP=`date '+%Y-%m-%d %H:%M.%S'`
# temporary holding point for email
TMP_EMAIL=/tmp/tmp_email_$DATE.$TIME
# build list of backup configuration files
CONFS=`ls -1 $EBU_CONF_DIR/$CONF_ROOT*.conf`
#
# function to direct a message...
message() {
echo "$0: $TIMESTAMP $@" >> $LOG
if test -f $TMP_EMAIL ; then
echo "$0: $TIMESTAMP $@" >> $TMP_EMAIL
fi
}
#
# create the temporary email file
create_tmp_email() {
touch $TMP_EMAIL
if test -f $TMP_EMAIL ; then
message "created temporary email $TMP_EMAIL"
else
message "failed to create temporary email $TMP_EMAIL"
fi
}
#
# send the contents of the temporary file to the
# designated report recipient
send_email_report() {
if test -f $TMP_EMAIL ; then
message "sending email report to $EMAIL"
$MAIL -s "$EMAIL_SUBJ" $EMAIL < $TMP_EMAIL
rm $TMP_EMAIL
if test -f $TMP_EMAIL ; then
message "failed to remove temporary email $TMP_EMAIL"
else
message "successfully removed temporary email $TMP_EMAIL"
fi
message "email report successfully sent"
fi
}
#
# insert a blank line into the log and on the console
insert_blank() {
echo "" >> $TMP_EMAIL
}
#
# The Functional Part of the Script
#
# build the email for the report
create_tmp_email
# run backup for each file
for CONF in $CONFS
do
$EBU_CMD -b -c $CONF -e $TMP_EMAIL
# $EBU_CMD -d -c $CONF -e $TMP_EMAIL
# put a space in the email to separate tasks
insert_blank
done
#
# send the resulting email
send_email_report
#-------------
#-- EGAlert --
$EGALERT success "$EGALERT_DAYSTAMP-ebu"
#-- EGAlert --
#-------------

86
ebu/run_monthly Executable file
View file

@ -0,0 +1,86 @@
#!/bin/bash
#
# this script runs a series of daily backup files, one after another
#
# These should be the only parameters requiring alteration
# the root filename for the appropriate configuration files
# in $EBU_CONF_DIR
CONF_ROOT="monthly"
# the email subject for report emails - to have date added
EMAIL_SUBJ="Avatar Monthly Backup Report"
# the email address (or addresses with comma separation) to send it to
EMAIL=dlane@egressive.com
#
# directories...
EBU_DIR=/etc/ebu
EBU_CMD=$EBU_DIR/ebu
EBU_CONF_DIR=$EBU_DIR/conf
LOGS=/var/log
LOG=$LOGS/ebu.log
# determine today's date
DATE=`date '+%Y-%m-%d-%a'`
# determine today's date
TIME=`date '+%H-%M-%S'`
# email program
MAIL=/bin/mail
# a timestamp for logging purposes
TIMESTAMP=`date '+%Y-%m-%d %H:%M.%S'`
# temporary holding point for email
TMP_EMAIL=/tmp/tmp_email_$DATE.$TIME
# build list of backup configuration files
CONFS=`ls -1 $EBU_CONF_DIR/$CONF_ROOT*.conf`
#
# function to direct a message...
message() {
echo "$0: $TIMESTAMP $@" >> $LOG
if test -f $TMP_EMAIL ; then
echo "$0: $TIMESTAMP $@" >> $TMP_EMAIL
fi
}
#
# create the temporary email file
create_tmp_email() {
touch $TMP_EMAIL
if test -f $TMP_EMAIL ; then
message "created temporary email $TMP_EMAIL"
else
message "failed to create temporary email $TMP_EMAIL"
fi
}
#
# send the contents of the temporary file to the
# designated report recipient
send_email_report() {
if test -f $TMP_EMAIL ; then
message "sending email report to $EMAIL"
$MAIL -s "$EMAIL_SUBJ" $EMAIL < $TMP_EMAIL
rm $TMP_EMAIL
if test -f $TMP_EMAIL ; then
message "failed to remove temporary email $TMP_EMAIL"
else
message "successfully removed temporary email $TMP_EMAIL"
fi
message "email report successfully sent"
fi
}
#
# insert a blank line into the log and on the console
insert_blank() {
echo "" >> $TMP_EMAIL
}
#
# The Functional Part of the Script
#
# build the email for the report
create_tmp_email
# run backup for each file
for CONF in $CONFS
do
$EBU_CMD -b -c $CONF -e $TMP_EMAIL
# put a space in the email to separate tasks
insert_blank
done
#
# send the resulting email
send_email_report

86
ebu/run_weekly Executable file
View file

@ -0,0 +1,86 @@
#!/bin/bash
#
# this script runs a series of daily backup files, one after another
#
# These should be the only parameters requiring alteration
# the root filename for the appropriate configuration files
# in $EBU_CONF_DIR
CONF_ROOT="weekly"
# the email subject for report emails - to have date added
EMAIL_SUBJ="Avatar Weekly Backup Report"
# the email address (or addresses with comma separation) to send it to
EMAIL=dlane@egressive.com
#
# directories...
EBU_DIR=/etc/ebu
EBU_CMD=$EBU_DIR/ebu
EBU_CONF_DIR=$EBU_DIR/conf
LOGS=/var/log
LOG=$LOGS/ebu.log
# determine today's date
DATE=`date '+%Y-%m-%d-%a'`
# determine today's date
TIME=`date '+%H-%M-%S'`
# email program
MAIL=/bin/mail
# a timestamp for logging purposes
TIMESTAMP=`date '+%Y-%m-%d %H:%M.%S'`
# temporary holding point for email
TMP_EMAIL=/tmp/tmp_email_$DATE.$TIME
# build list of backup configuration files
CONFS=`ls -1 $EBU_CONF_DIR/$CONF_ROOT*.conf`
#
# function to direct a message...
message() {
echo "$0: $TIMESTAMP $@" >> $LOG
if test -f $TMP_EMAIL ; then
echo "$0: $TIMESTAMP $@" >> $TMP_EMAIL
fi
}
#
# create the temporary email file
create_tmp_email() {
touch $TMP_EMAIL
if test -f $TMP_EMAIL ; then
message "created temporary email $TMP_EMAIL"
else
message "failed to create temporary email $TMP_EMAIL"
fi
}
#
# send the contents of the temporary file to the
# designated report recipient
send_email_report() {
if test -f $TMP_EMAIL ; then
message "sending email report to $EMAIL"
$MAIL -s "$EMAIL_SUBJ" $EMAIL < $TMP_EMAIL
rm $TMP_EMAIL
if test -f $TMP_EMAIL ; then
message "failed to remove temporary email $TMP_EMAIL"
else
message "successfully removed temporary email $TMP_EMAIL"
fi
message "email report successfully sent"
fi
}
#
# insert a blank line into the log and on the console
insert_blank() {
echo "" >> $TMP_EMAIL
}
#
# The Functional Part of the Script
#
# build the email for the report
create_tmp_email
# run backup for each file
for CONF in $CONFS
do
$EBU_CMD -b -c $CONF -e $TMP_EMAIL
# put a space in the email to separate tasks
insert_blank
done
#
# send the resulting email
send_email_report

86
ebu/run_yearly Executable file
View file

@ -0,0 +1,86 @@
#!/bin/bash
#
# this script runs a series of daily backup files, one after another
#
# These should be the only parameters requiring alteration
# the root filename for the appropriate configuration files
# in $EBU_CONF_DIR
CONF_ROOT="yearly"
# the email subject for report emails - to have date added
EMAIL_SUBJ="Avatar Yearly Backup Report"
# the email address (or addresses with comma separation) to send it to
EMAIL=dlane@egressive.com
#
# directories...
EBU_DIR=/etc/ebu
EBU_CMD=$EBU_DIR/ebu
EBU_CONF_DIR=$EBU_DIR/conf
LOGS=/var/log
LOG=$LOGS/ebu.log
# determine today's date
DATE=`date '+%Y-%m-%d-%a'`
# determine today's date
TIME=`date '+%H-%M-%S'`
# email program
MAIL=/bin/mail
# a timestamp for logging purposes
TIMESTAMP=`date '+%Y-%m-%d %H:%M.%S'`
# temporary holding point for email
TMP_EMAIL=/tmp/tmp_email_$DATE.$TIME
# build list of backup configuration files
CONFS=`ls -1 $EBU_CONF_DIR/$CONF_ROOT*.conf`
#
# function to direct a message...
message() {
echo "$0: $TIMESTAMP $@" >> $LOG
if test -f $TMP_EMAIL ; then
echo "$0: $TIMESTAMP $@" >> $TMP_EMAIL
fi
}
#
# create the temporary email file
create_tmp_email() {
touch $TMP_EMAIL
if test -f $TMP_EMAIL ; then
message "created temporary email $TMP_EMAIL"
else
message "failed to create temporary email $TMP_EMAIL"
fi
}
#
# send the contents of the temporary file to the
# designated report recipient
send_email_report() {
if test -f $TMP_EMAIL ; then
message "sending email report to $EMAIL"
$MAIL -s "$EMAIL_SUBJ" $EMAIL < $TMP_EMAIL
rm $TMP_EMAIL
if test -f $TMP_EMAIL ; then
message "failed to remove temporary email $TMP_EMAIL"
else
message "successfully removed temporary email $TMP_EMAIL"
fi
message "email report successfully sent"
fi
}
#
# insert a blank line into the log and on the console
insert_blank() {
echo "" >> $TMP_EMAIL
}
#
# The Functional Part of the Script
#
# build the email for the report
create_tmp_email
# run backup for each file
for CONF in $CONFS
do
$EBU_CMD -b -c $CONF -e $TMP_EMAIL
# put a space in the email to separate tasks
insert_blank
done
#
# send the resulting email
send_email_report