initial commit of a *whole bunch* of old Egressive shell scripts, used to make many people redundant.
This commit is contained in:
commit
43e0f5b59e
329 changed files with 31937 additions and 0 deletions
19
egpgdbbackup/daily/osl.conf
Normal file
19
egpgdbbackup/daily/osl.conf
Normal file
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
# backup directory
|
||||
BU_DIR=/storage/pgsql/daily
|
||||
# server
|
||||
SERVER=localhost
|
||||
# user info
|
||||
USER=osl
|
||||
PASSWORD=bigtime
|
||||
# a list of databases to backup
|
||||
DBS="osl"
|
||||
# email address to send reports to, and subject
|
||||
EMAIL=backup-reports@lists.openstrategies.net
|
||||
EMAIL_SUBJ="OslUK Postgres Daily OSL Backup Report"
|
||||
# backup Identifier
|
||||
BU_IDENT=daily
|
||||
# number of backups for each db to keep
|
||||
BU_TO_KEEP=7
|
||||
# output for debugging...
|
||||
VERBOSE=1
|
19
egpgdbbackup/daily/osltest.conf
Normal file
19
egpgdbbackup/daily/osltest.conf
Normal file
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
# backup directory
|
||||
BU_DIR=/storage/pgsql/daily
|
||||
# server
|
||||
SERVER=localhost
|
||||
# user info
|
||||
USER=osltest
|
||||
PASSWORD=testbigtime
|
||||
# a list of databases to backup
|
||||
DBS="osltest"
|
||||
# email address to send reports to, and subject
|
||||
EMAIL=backup-reports@lists.openstrategies.net
|
||||
EMAIL_SUBJ="OslUK Postgres Daily OSL Devel Backup Report"
|
||||
# backup Identifier
|
||||
BU_IDENT=daily-devel
|
||||
# number of backups for each db to keep
|
||||
BU_TO_KEEP=7
|
||||
# output for debugging...
|
||||
VERBOSE=1
|
200
egpgdbbackup/egpgdbbackup
Executable file
200
egpgdbbackup/egpgdbbackup
Executable file
|
@ -0,0 +1,200 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# This script dumps the osl db on new.egressive.com
|
||||
# and pipes the results into an appropriately named/dated
|
||||
# file...
|
||||
#
|
||||
# The following options must be specified in .conf files
|
||||
# in a directory designated with the -c switch.
|
||||
#
|
||||
# # backup directory
|
||||
# BU_DIR=/storage/warhol/pgsql/daily
|
||||
# # the database details
|
||||
# SERVER=localhost
|
||||
# USER=root
|
||||
# PASSWORD=
|
||||
# # names of the databases to backup
|
||||
# DBS="osl osltest egressive seradigm egressive_accounts"
|
||||
# # email address to send reports to, and subject
|
||||
# EMAIL=dlane@egressive.com
|
||||
# EMAIL_SUBJ="Postgres daily OSL Backup Report"
|
||||
# # backup identifier
|
||||
# BU_IDENT=daily
|
||||
# # number of backups for each db to keep
|
||||
# BU_TO_KEEP=7
|
||||
# # output for debugging...
|
||||
VERBOSE=0
|
||||
#
|
||||
# Stuff that should be universal for this install...
|
||||
# where we can find this app...
|
||||
MAIN_DIR=/etc/egscripts/egpgdbbackup
|
||||
# determine today's date
|
||||
DATE=`date '+%Y-%m-%d-%a'`
|
||||
# determine today's date
|
||||
TIME=`date '+%H-%M-%S'`
|
||||
# temporary holding point for email
|
||||
TMP_EMAIL=/tmp/tmp_egpgdbbackup_email.$DATE_$TIME
|
||||
# log file
|
||||
LOG=/var/log/egpgdbbackup.log
|
||||
#
|
||||
# Commands
|
||||
# gzip command
|
||||
GZIP=`which gzip`
|
||||
# grep command
|
||||
GREP=`which grep`
|
||||
# email program
|
||||
MAIL=`which mail`
|
||||
# database dump utility
|
||||
PGDUMP=`which pg_dump`
|
||||
DEF_ARGS="-C -d -O -x"
|
||||
#
|
||||
# pattern for "ls" command to build list of
|
||||
# pruneable backup files...
|
||||
# -1t = 1 column, ordered by time of last mod
|
||||
PRUNEABLES_CMD="ls -1t"
|
||||
# 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 $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 "" >> $LOG
|
||||
verbose ""
|
||||
}
|
||||
# function to direct a message...
|
||||
verbose() {
|
||||
if test $VERBOSE = 1 ; then
|
||||
echo "$@"
|
||||
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`
|
||||
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"
|
||||
rm $PRUNEABLE 2>&1 > /dev/null
|
||||
else
|
||||
message "keeping $PRUNEABLE"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
else
|
||||
message "keeping older backups, missing backup_root_filename..."
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# cycle through the command line options
|
||||
while test $# -ne 0 ; do
|
||||
case $1 in
|
||||
--config|-c)
|
||||
shift # shift from the flag to the value
|
||||
verbose "setting configuration directory to $1"
|
||||
BU_CONFDIR=$1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
#
|
||||
#
|
||||
# create the blank email report
|
||||
create_tmp_email
|
||||
#
|
||||
# run through the various configuration files
|
||||
message "looking for configuration files in $BU_CONFDIR"
|
||||
if test -d $MAIN_DIR/$BU_CONFDIR ; then
|
||||
CONFS=`ls -1 $MAIN_DIR/$BU_CONFDIR/*.conf`
|
||||
message "found these config files: $CONFS"
|
||||
for CONF in $CONFS
|
||||
do
|
||||
if test -f $CONF ; then
|
||||
message "processing $CONF configuration file"
|
||||
# source the configuration file
|
||||
source $CONF
|
||||
# go to the backup directory
|
||||
cd $BU_DIR
|
||||
# set up database access info
|
||||
export PGUSER=$USER
|
||||
export PGPASSWORD=$PASSWORD
|
||||
message "starting backup of databases $DBS"
|
||||
#
|
||||
# dump the database
|
||||
for DB in $DBS
|
||||
do
|
||||
# a timestamp for logging purposes
|
||||
STAMP=`date '+%Y-%m-%d_%H-%M-%S'`
|
||||
# create a root filename
|
||||
BU_FROOT=$DB-$BU_IDENT
|
||||
# delete stale backups
|
||||
delete_old
|
||||
# generate the filename
|
||||
FILENAME=$BU_FROOT-$STAMP.sql
|
||||
message "backing up database '$DB' into file $FILENAME"
|
||||
# dump the data into the file
|
||||
$PGDUMP $DEF_ARGS -h $SERVER -f $FILENAME $DB
|
||||
message "completed backup of '$DB'"
|
||||
# compress the backup
|
||||
message "compressing $FILENAME"
|
||||
$GZIP $FILENAME
|
||||
# vaccuum the database
|
||||
done
|
||||
message "completed backup of databases: $DBS"
|
||||
# return to where you started from...
|
||||
cd $OLDPWD
|
||||
fi
|
||||
done
|
||||
message "read config files in $BU_CONF directory"
|
||||
else
|
||||
message "config directory $BU_CONF doesn't exist!"
|
||||
exit 1
|
||||
fi
|
||||
# sent resulting email report
|
||||
send_email_report
|
||||
exit 0
|
18
egpgdbbackup/egpgdbbackup-cron
Normal file
18
egpgdbbackup/egpgdbbackup-cron
Normal file
|
@ -0,0 +1,18 @@
|
|||
#
|
||||
# run system backups
|
||||
#
|
||||
# hourly - at 5 minutes past mon-sat
|
||||
05 * * * * root /etc/egscripts/egpgdbbackup/egpgdbbackup -c hourly
|
||||
#
|
||||
# daily - at 7:30 pm, mon-sat
|
||||
30 19 * * * root /etc/egscripts/egpgdbbackup/egpgdbbackup -c daily
|
||||
#
|
||||
# weekly - at 7:30 pm, sun
|
||||
#30 19 * * sun root /etc/egscripts/egpgdbbackup/egpgdbbackup -c weekly
|
||||
#
|
||||
# monthly - at 8:30 pm, on the first of the last of the month
|
||||
#30 20 1 * * root /etc/egscripts/egpgdbbackup/egpgdbbackup -c monthly
|
||||
#
|
||||
# yearly - at 8:30 pm, on the first of January.
|
||||
#30 20 1 1 * root /etc/egscripts/egpgdbbackup/egpgdbbackup -c yearly
|
||||
|
18
egpgdbbackup/egpgdbbackup.cron
Normal file
18
egpgdbbackup/egpgdbbackup.cron
Normal file
|
@ -0,0 +1,18 @@
|
|||
#
|
||||
# run system backups
|
||||
#
|
||||
# hourly - at 5 minutes past mon-sat
|
||||
05 * * * * root /etc/egscripts/egpgdbbackup/egpgdbbackup -c hourly
|
||||
#
|
||||
# daily - at 7:30 pm, mon-sat
|
||||
30 19 * * * root /etc/egscripts/egpgdbbackup/egpgdbbackup -c daily
|
||||
#
|
||||
# weekly - at 7:30 pm, sun
|
||||
30 19 * * sun root /etc/egscripts/egpgdbbackup/egpgdbbackup -c weekly
|
||||
#
|
||||
# monthly - at 8:30 pm, on the first of the last of the month
|
||||
30 20 1 * * root /etc/egscripts/egpgdbbackup/egpgdbbackup -c monthly
|
||||
#
|
||||
# yearly - at 8:30 pm, on the first of January.
|
||||
30 20 1 1 * root /etc/egscripts/egpgdbbackup/egpgdbbackup -c yearly
|
||||
|
19
egpgdbbackup/hourly/osl.conf
Normal file
19
egpgdbbackup/hourly/osl.conf
Normal file
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
# backup directory
|
||||
BU_DIR=/storage/pgsql/hourly
|
||||
# server
|
||||
SERVER=localhost
|
||||
# user info
|
||||
USER=osl
|
||||
PASSWORD=bigtime
|
||||
# a list of databases to backup
|
||||
DBS="osl"
|
||||
# email address to send reports to, and subject
|
||||
EMAIL=backup-reports@lists.openstrategies.net
|
||||
EMAIL_SUBJ="OslUK Postgres Hourly OSL Backup Report"
|
||||
# backup Identifier
|
||||
BU_IDENT=hourly
|
||||
# number of backups for each db to keep
|
||||
BU_TO_KEEP=24
|
||||
# output for debugging...
|
||||
VERBOSE=1
|
19
egpgdbbackup/monthly/osl.conf
Normal file
19
egpgdbbackup/monthly/osl.conf
Normal file
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
# backup directory
|
||||
BU_DIR=/storage/pgsql/monthly
|
||||
# server
|
||||
SERVER=localhost
|
||||
# user info
|
||||
USER=osl
|
||||
PASSWORD=bigtime
|
||||
# a list of databases to backup
|
||||
DBS="osl"
|
||||
# email address to send reports to, and subject
|
||||
EMAIL=backup-reports@lists.openstrategies.net
|
||||
EMAIL_SUBJ="OslUK Postgres Monthly OSL Backup Report"
|
||||
# backup Identifier
|
||||
BU_IDENT=monthly
|
||||
# number of backups for each db to keep
|
||||
BU_TO_KEEP=12
|
||||
# output for debugging...
|
||||
VERBOSE=0
|
20
egpgdbbackup/test.conf
Normal file
20
egpgdbbackup/test.conf
Normal 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="test"
|
||||
CURRENT_LINK="Current-test"
|
||||
#
|
||||
# directory in which to save the backups...
|
||||
BU_DIR=/backup/server/daily
|
||||
#
|
||||
# directories to back up
|
||||
FILES="/etc"
|
||||
#
|
||||
# directories/files to exclude
|
||||
EXCLUDE="*.log"
|
||||
#
|
||||
# removal all but the $BU_TO_KEEP most recent
|
||||
# backups.
|
||||
BU_TO_KEEP=1
|
19
egpgdbbackup/weekly/osl.conf
Normal file
19
egpgdbbackup/weekly/osl.conf
Normal file
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
# backup directory
|
||||
BU_DIR=/storage/pgsql/weekly
|
||||
# server
|
||||
SERVER=localhost
|
||||
# user info
|
||||
USER=osl
|
||||
PASSWORD=bigtime
|
||||
# a list of databases to backup
|
||||
DBS="osl"
|
||||
# email address to send reports to, and subject
|
||||
EMAIL=backup-reports@lists.openstrategies.net
|
||||
EMAIL_SUBJ="OslUK Postgres Weekly OSL Backup Report"
|
||||
# backup Identifier
|
||||
BU_IDENT=weekly
|
||||
# number of backups for each db to keep
|
||||
BU_TO_KEEP=4
|
||||
# output for debugging...
|
||||
VERBOSE=0
|
19
egpgdbbackup/yearly/osl.conf
Normal file
19
egpgdbbackup/yearly/osl.conf
Normal file
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
# backup directory
|
||||
BU_DIR=/storage/pgsql/yearly
|
||||
# server
|
||||
SERVER=localhost
|
||||
# user info
|
||||
USER=osl
|
||||
PASSWORD=bigtime
|
||||
# a list of databases to backup
|
||||
DBS="osl"
|
||||
# email address to send reports to, and subject
|
||||
EMAIL=backup-reports@lists.openstrategies.net
|
||||
EMAIL_SUBJ="OslUK Postgres Yearly OSL Backup Report"
|
||||
# backup Identifier
|
||||
BU_IDENT=yearly
|
||||
# number of backups for each db to keep
|
||||
BU_TO_KEEP=6
|
||||
# output for debugging...
|
||||
VERBOSE=0
|
Loading…
Add table
Add a link
Reference in a new issue