|
@@ -29,7 +29,7 @@
|
|
USERNAME=postgres
|
|
USERNAME=postgres
|
|
|
|
|
|
# Password
|
|
# Password
|
|
-# create a file $HOME/.pgpass containing a line like this
|
|
|
|
|
|
+# create a file ${HOME}/.pgpass containing a line like this
|
|
# hostname:*:*:dbuser:dbpass
|
|
# hostname:*:*:dbuser:dbpass
|
|
# replace hostname with the value of DBHOST and postgres with
|
|
# replace hostname with the value of DBHOST and postgres with
|
|
# the value of USERNAME
|
|
# the value of USERNAME
|
|
@@ -65,7 +65,7 @@ MAILADDR="user@domain.com"
|
|
#=============================================================
|
|
#=============================================================
|
|
|
|
|
|
# List of DBBNAMES for Monthly Backups.
|
|
# List of DBBNAMES for Monthly Backups.
|
|
-MDBNAMES="template1 $DBNAMES"
|
|
|
|
|
|
+MDBNAMES="template1 ${DBNAMES}"
|
|
|
|
|
|
# List of DBNAMES to EXLUCDE if DBNAMES are set to all (must be in " quotes)
|
|
# List of DBNAMES to EXLUCDE if DBNAMES are set to all (must be in " quotes)
|
|
DBEXCLUDE=""
|
|
DBEXCLUDE=""
|
|
@@ -295,55 +295,48 @@ DOM=`date +%d` # Date of the Month e.g. 27
|
|
M=`date +%B` # Month e.g January
|
|
M=`date +%B` # Month e.g January
|
|
W=`date +%V` # Week Number e.g 37
|
|
W=`date +%V` # Week Number e.g 37
|
|
VER=1.0 # Version Number
|
|
VER=1.0 # Version Number
|
|
-LOGFILE=$BACKUPDIR/${DBHOST//\//_}-`date +%N`.log # Logfile Name
|
|
|
|
-LOGERR=$BACKUPDIR/ERRORS_${DBHOST//\//_}-`date +%N`.log # Logfile Name
|
|
|
|
|
|
+LOGFILE=${BACKUPDIR}/${DBHOST//\//_}-`date +%N`.log # Logfile Name
|
|
|
|
+LOGERR=${BACKUPDIR}/ERRORS_${DBHOST//\//_}-`date +%N`.log # Logfile Name
|
|
BACKUPFILES=""
|
|
BACKUPFILES=""
|
|
|
|
|
|
-# Add --compress pg_dump option to $OPT
|
|
|
|
-if [ "$COMMCOMP" -gt 0 ];
|
|
|
|
- then
|
|
|
|
- OPT="$OPT --compress=$COMMCOMP"
|
|
|
|
|
|
+# Add --compress pg_dump option to ${OPT}
|
|
|
|
+if [ "${COMMCOMP}" -gt 0 ]; then
|
|
|
|
+ OPT="${OPT} --compress=${COMMCOMP}"
|
|
fi
|
|
fi
|
|
|
|
|
|
# Create required directories
|
|
# Create required directories
|
|
-if [ ! -e "$BACKUPDIR" ] # Check Backup Directory exists.
|
|
|
|
- then
|
|
|
|
- mkdir -p "$BACKUPDIR"
|
|
|
|
|
|
+if [ ! -e "${BACKUPDIR}" ]; then # Check Backup Directory exists.
|
|
|
|
+ mkdir -p "${BACKUPDIR}"
|
|
fi
|
|
fi
|
|
|
|
|
|
-if [ ! -e "$BACKUPDIR/daily" ] # Check Daily Directory exists.
|
|
|
|
- then
|
|
|
|
- mkdir -p "$BACKUPDIR/daily"
|
|
|
|
|
|
+if [ ! -e "${BACKUPDIR}/daily" ]; then # Check Daily Directory exists.
|
|
|
|
+ mkdir -p "${BACKUPDIR}/daily"
|
|
fi
|
|
fi
|
|
|
|
|
|
-if [ ! -e "$BACKUPDIR/weekly" ] # Check Weekly Directory exists.
|
|
|
|
- then
|
|
|
|
- mkdir -p "$BACKUPDIR/weekly"
|
|
|
|
|
|
+if [ ! -e "${BACKUPDIR}/weekly" ]; then # Check Weekly Directory exists.
|
|
|
|
+ mkdir -p "${BACKUPDIR}/weekly"
|
|
fi
|
|
fi
|
|
|
|
|
|
-if [ ! -e "$BACKUPDIR/monthly" ] # Check Monthly Directory exists.
|
|
|
|
- then
|
|
|
|
- mkdir -p "$BACKUPDIR/monthly"
|
|
|
|
|
|
+if [ ! -e "${BACKUPDIR}/monthly" ]; then # Check Monthly Directory exists.
|
|
|
|
+ mkdir -p "${BACKUPDIR}/monthly"
|
|
fi
|
|
fi
|
|
|
|
|
|
-if [ "$LATEST" = "yes" ]
|
|
|
|
-then
|
|
|
|
- if [ ! -e "$BACKUPDIR/latest" ] # Check Latest Directory exists.
|
|
|
|
- then
|
|
|
|
- mkdir -p "$BACKUPDIR/latest"
|
|
|
|
|
|
+if [ "${LATEST}" = "yes" ]; then
|
|
|
|
+ if [ ! -e "${BACKUPDIR}/latest" ]; then # Check Latest Directory exists.
|
|
|
|
+ mkdir -p "${BACKUPDIR}/latest"
|
|
fi
|
|
fi
|
|
-rm -f "$BACKUPDIR"/latest/*
|
|
|
|
|
|
+ rm -f "${BACKUPDIR}"/latest/*
|
|
fi
|
|
fi
|
|
|
|
|
|
# IO redirection for logging.
|
|
# IO redirection for logging.
|
|
-touch $LOGFILE
|
|
|
|
|
|
+touch ${LOGFILE}
|
|
exec 6>&1 # Link file descriptor #6 with stdout.
|
|
exec 6>&1 # Link file descriptor #6 with stdout.
|
|
# Saves stdout.
|
|
# Saves stdout.
|
|
-exec > $LOGFILE # stdout replaced with file $LOGFILE.
|
|
|
|
-touch $LOGERR
|
|
|
|
|
|
+exec > ${LOGFILE} # stdout replaced with file ${LOGFILE}.
|
|
|
|
+touch ${LOGERR}
|
|
exec 7>&2 # Link file descriptor #7 with stderr.
|
|
exec 7>&2 # Link file descriptor #7 with stderr.
|
|
# Saves stderr.
|
|
# Saves stderr.
|
|
-exec 2> $LOGERR # stderr replaced with file $LOGERR.
|
|
|
|
|
|
+exec 2> ${LOGERR} # stderr replaced with file ${LOGERR}.
|
|
|
|
|
|
|
|
|
|
# Functions
|
|
# Functions
|
|
@@ -352,19 +345,19 @@ exec 2> $LOGERR # stderr replaced with file $LOGERR.
|
|
dbdump () {
|
|
dbdump () {
|
|
rm -f $2
|
|
rm -f $2
|
|
touch $2
|
|
touch $2
|
|
- chmod $PERM $2
|
|
|
|
|
|
+ chmod ${PERM} $2
|
|
for db in $1 ; do
|
|
for db in $1 ; do
|
|
- if [ -n "$SU_USERNAME" ]; then
|
|
|
|
- if [ "$db" = "$GLOBALS_OBJECTS" ]; then
|
|
|
|
- su - $SU_USERNAME -l -c "pg_dumpall $PGHOST --globals-only" >> $2
|
|
|
|
|
|
+ if [ -n "${SU}_USERNAME" ]; then
|
|
|
|
+ if [ "${db}" = "${GLOBALS}_OBJECTS" ]; then
|
|
|
|
+ su - ${SU}_USERNAME -l -c "pg_dumpall ${PGHOST} --globals-only" >> $2
|
|
else
|
|
else
|
|
- su - $SU_USERNAME -l -c "pg_dump $PGHOST $OPT $db" >> $2
|
|
|
|
|
|
+ su - ${SU}_USERNAME -l -c "pg_dump ${PGHOST} ${OPT} ${db}" >> $2
|
|
fi
|
|
fi
|
|
else
|
|
else
|
|
- if [ "$db" = "$GLOBALS_OBJECTS" ]; then
|
|
|
|
- pg_dumpall --username=$USERNAME $PGHOST --globals-only >> $2
|
|
|
|
|
|
+ if [ "${db}" = "${GLOBALS}_OBJECTS" ]; then
|
|
|
|
+ pg_dumpall --username=${USERNAME} ${PGHOST} --globals-only >> $2
|
|
else
|
|
else
|
|
- pg_dump --username=$USERNAME $PGHOST $OPT $db >> $2
|
|
|
|
|
|
+ pg_dump --username=${USERNAME} ${PGHOST} ${OPT} ${db} >> $2
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
done
|
|
done
|
|
@@ -373,18 +366,18 @@ dbdump () {
|
|
|
|
|
|
# Encryption function
|
|
# Encryption function
|
|
encryption() {
|
|
encryption() {
|
|
- ENCRYPTED_FILE="$1$ENCRYPTION_SUFFIX"
|
|
|
|
|
|
+ ENCRYPTED_FILE="$1${ENCRYPTION}_SUFFIX"
|
|
# Encrypt as needed
|
|
# Encrypt as needed
|
|
- if [ "$ENCRYPTION" = "yes" ]; then
|
|
|
|
|
|
+ if [ "${ENCRYPTION}" = "yes" ]; then
|
|
echo
|
|
echo
|
|
echo "Encrypting $1"
|
|
echo "Encrypting $1"
|
|
- echo " to $ENCRYPTED_FILE"
|
|
|
|
- echo " using cypher $ENCRYPTION_CIPHER and public key $ENCRYPTION_PUBLIC_KEY"
|
|
|
|
- if openssl smime -encrypt -$ENCRYPTION_CIPHER -binary -outform DEM \
|
|
|
|
- -out "$ENCRYPTED_FILE" \
|
|
|
|
- -in "$1" "$ENCRYPTION_PUBLIC_KEY" ; then
|
|
|
|
|
|
+ echo " to ${ENCRYPTED}_FILE"
|
|
|
|
+ echo " using cypher ${ENCRYPTION}_CIPHER and public key ${ENCRYPTION}_PUBLIC_KEY"
|
|
|
|
+ if openssl smime -encrypt -${ENCRYPTION}_CIPHER -binary -outform DEM \
|
|
|
|
+ -out "${ENCRYPTED}_FILE" \
|
|
|
|
+ -in "$1" "${ENCRYPTION}_PUBLIC_KEY" ; then
|
|
echo " and remove $1"
|
|
echo " and remove $1"
|
|
- chmod $PERM "$ENCRYPTED_FILE"
|
|
|
|
|
|
+ chmod ${PERM} "${ENCRYPTED}_FILE"
|
|
rm -f "$1"
|
|
rm -f "$1"
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
@@ -394,18 +387,18 @@ encryption() {
|
|
# Compression (and encrypt) function plus latest copy
|
|
# Compression (and encrypt) function plus latest copy
|
|
SUFFIX=""
|
|
SUFFIX=""
|
|
compression () {
|
|
compression () {
|
|
- if [ "$COMP" = "gzip" ]; then
|
|
|
|
|
|
+ if [ "${COMP}" = "gzip" ]; then
|
|
gzip -f "$1"
|
|
gzip -f "$1"
|
|
echo
|
|
echo
|
|
echo Backup Information for "$1"
|
|
echo Backup Information for "$1"
|
|
gzip -l "$1.gz"
|
|
gzip -l "$1.gz"
|
|
SUFFIX=".gz"
|
|
SUFFIX=".gz"
|
|
echo
|
|
echo
|
|
- elif [ "$COMP" = "bzip2" ]; then
|
|
|
|
|
|
+ elif [ "${COMP}" = "bzip2" ]; then
|
|
echo Compression information for "$1.bz2"
|
|
echo Compression information for "$1.bz2"
|
|
bzip2 -f -v $1 2>&1
|
|
bzip2 -f -v $1 2>&1
|
|
SUFFIX=".bz2"
|
|
SUFFIX=".bz2"
|
|
- elif [ "$COMP" = "xz" ]; then
|
|
|
|
|
|
+ elif [ "${COMP}" = "xz" ]; then
|
|
xz -9 $1 2>&1
|
|
xz -9 $1 2>&1
|
|
echo Backup information for "$1.xz"
|
|
echo Backup information for "$1.xz"
|
|
xz -l "$1.xz"
|
|
xz -l "$1.xz"
|
|
@@ -414,207 +407,198 @@ compression () {
|
|
echo "No compression option set, check advanced settings"
|
|
echo "No compression option set, check advanced settings"
|
|
fi
|
|
fi
|
|
|
|
|
|
- encryption $1$SUFFIX
|
|
|
|
|
|
+ encryption $1${SUFFIX}
|
|
|
|
|
|
- if [ "$LATEST" = "yes" ]; then
|
|
|
|
- cp $1$SUFFIX* "$BACKUPDIR/latest/"
|
|
|
|
|
|
+ if [ "${LATEST}" = "yes" ]; then
|
|
|
|
+ cp $1${SUFFIX}* "${BACKUPDIR}/latest/"
|
|
fi
|
|
fi
|
|
|
|
|
|
return 0
|
|
return 0
|
|
}
|
|
}
|
|
|
|
|
|
# Run command before we begin
|
|
# Run command before we begin
|
|
-if [ "$PREBACKUP" ]
|
|
|
|
|
|
+if [ "${PREBACKUP}" ]
|
|
then
|
|
then
|
|
echo ======================================================================
|
|
echo ======================================================================
|
|
echo "Prebackup command output."
|
|
echo "Prebackup command output."
|
|
echo
|
|
echo
|
|
- $PREBACKUP
|
|
|
|
|
|
+ ${PREBACKUP}
|
|
echo
|
|
echo
|
|
echo ======================================================================
|
|
echo ======================================================================
|
|
echo
|
|
echo
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
|
|
-if [ "$SEPDIR" = "yes" ]; then # Check if CREATE DATABSE should be included in Dump
|
|
|
|
- if [ "$CREATE_DATABASE" = "no" ]; then
|
|
|
|
- OPT="$OPT"
|
|
|
|
|
|
+if [ "${SEPDIR}" = "yes" ]; then # Check if CREATE DATABSE should be included in Dump
|
|
|
|
+ if [ "${CREATE}_DATABASE" = "no" ]; then
|
|
|
|
+ OPT="${OPT}"
|
|
else
|
|
else
|
|
- OPT="$OPT --create"
|
|
|
|
|
|
+ OPT="${OPT} --create"
|
|
fi
|
|
fi
|
|
else
|
|
else
|
|
- OPT="$OPT"
|
|
|
|
|
|
+ OPT="${OPT}"
|
|
fi
|
|
fi
|
|
|
|
|
|
# Hostname for LOG information
|
|
# Hostname for LOG information
|
|
-if [ "$DBHOST" = "localhost" ]; then
|
|
|
|
|
|
+if [ "${DBHOST}" = "localhost" ]; then
|
|
HOST=`hostname`
|
|
HOST=`hostname`
|
|
PGHOST=""
|
|
PGHOST=""
|
|
else
|
|
else
|
|
- HOST=$DBHOST
|
|
|
|
- PGHOST="-h $DBHOST"
|
|
|
|
|
|
+ HOST=${DBHOST}
|
|
|
|
+ PGHOST="-h ${DBHOST}"
|
|
fi
|
|
fi
|
|
|
|
|
|
# If backing up all DBs on the server
|
|
# If backing up all DBs on the server
|
|
-if [ "$DBNAMES" = "all" ]; then
|
|
|
|
- if [ -n "$SU_USERNAME" ]; then
|
|
|
|
- DBNAMES="$(su - $SU_USERNAME -l -c "LANG=C psql -U $USERNAME $PGHOST -l -A -F: | sed -ne '/:/ { /Name:Owner/d; /template0/d; s/:.*$//; p }'")"
|
|
|
|
|
|
+if [ "${DBNAMES}" = "all" ]; then
|
|
|
|
+ if [ -n "${SU}_USERNAME" ]; then
|
|
|
|
+ DBNAMES="$(su - ${SU}_USERNAME -l -c "LANG=C psql -U ${USERNAME} ${PGHOST} -l -A -F: | sed -ne '/:/ { /Name:Owner/d; /template0/d; s/:.*$//; p }'")"
|
|
else
|
|
else
|
|
- DBNAMES="`LANG=C psql -U $USERNAME $PGHOST -l -A -F: | sed -ne "/:/ { /Name:Owner/d; /template0/d; s/:.*$//; p }"`"
|
|
|
|
|
|
+ DBNAMES="`LANG=C psql -U ${USERNAME} ${PGHOST} -l -A -F: | sed -ne "/:/ { /Name:Owner/d; /template0/d; s/:.*$//; p }"`"
|
|
fi
|
|
fi
|
|
|
|
|
|
# If DBs are excluded
|
|
# If DBs are excluded
|
|
- for exclude in $DBEXCLUDE
|
|
|
|
- do
|
|
|
|
- DBNAMES=`echo $DBNAMES | sed "s/\b$exclude\b//g"`
|
|
|
|
|
|
+ for exclude in ${DBEXCLUDE} ; do
|
|
|
|
+ DBNAMES=`echo ${DBNAMES} | sed "s/\b${exclude}\b//g"`
|
|
done
|
|
done
|
|
- DBNAMES="$(echo $DBNAMES| tr '\n' ' ')"
|
|
|
|
- MDBNAMES=$DBNAMES
|
|
|
|
|
|
+ DBNAMES="$(echo ${DBNAMES}| tr '\n' ' ')"
|
|
|
|
+ MDBNAMES=${DBNAMES}
|
|
fi
|
|
fi
|
|
|
|
|
|
# Include global objects (users, tablespaces)
|
|
# Include global objects (users, tablespaces)
|
|
-DBNAMES="$GLOBALS_OBJECTS $DBNAMES"
|
|
|
|
-MDBNAMES="$GLOBALS_OBJECTS $MDBNAMES"
|
|
|
|
|
|
+DBNAMES="${GLOBALS}_OBJECTS ${DBNAMES}"
|
|
|
|
+MDBNAMES="${GLOBALS}_OBJECTS ${MDBNAMES}"
|
|
|
|
|
|
echo ======================================================================
|
|
echo ======================================================================
|
|
-echo AutoPostgreSQLBackup VER $VER
|
|
|
|
|
|
+echo AutoPostgreSQLBackup VER ${VER}
|
|
echo http://autopgsqlbackup.frozenpc.net/
|
|
echo http://autopgsqlbackup.frozenpc.net/
|
|
echo
|
|
echo
|
|
-echo Backup of Database Server - $HOST
|
|
|
|
|
|
+echo Backup of Database Server - ${HOST}
|
|
echo ======================================================================
|
|
echo ======================================================================
|
|
|
|
|
|
# Test is seperate DB backups are required
|
|
# Test is seperate DB backups are required
|
|
-if [ "$SEPDIR" = "yes" ]; then
|
|
|
|
-echo Backup Start Time `date`
|
|
|
|
-echo ======================================================================
|
|
|
|
|
|
+if [ "${SEPDIR}" = "yes" ]; then
|
|
|
|
+ echo Backup Start Time `date`
|
|
|
|
+ echo ======================================================================
|
|
# Monthly Full Backup of all Databases
|
|
# Monthly Full Backup of all Databases
|
|
- if [ "$DOM" = "01" ]; then
|
|
|
|
- for MDB in $MDBNAMES
|
|
|
|
- do
|
|
|
|
-
|
|
|
|
- # Prepare $DB for using
|
|
|
|
- MDB="`echo $MDB | sed 's/%/ /g'`"
|
|
|
|
-
|
|
|
|
- if [ ! -e "$BACKUPDIR/monthly/$MDB" ] # Check Monthly DB Directory exists.
|
|
|
|
- then
|
|
|
|
- mkdir -p "$BACKUPDIR/monthly/$MDB"
|
|
|
|
|
|
+ if [ "${DOM}" = "01" ]; then
|
|
|
|
+ for MDB in ${MDBNAMES} ; do
|
|
|
|
+ # Prepare ${DB} for using
|
|
|
|
+ MDB="`echo ${MDB} | sed 's/%/ /g'`"
|
|
|
|
+ if [ ! -e "${BACKUPDIR}/monthly/${MDB}" ]; then # Check Monthly DB Directory exists.
|
|
|
|
+ mkdir -p "${BACKUPDIR}/monthly/${MDB}"
|
|
fi
|
|
fi
|
|
- echo Monthly Backup of $MDB...
|
|
|
|
- dbdump "$MDB" "$BACKUPDIR/monthly/$MDB/${MDB}_$DATE.$M.$MDB.$EXT"
|
|
|
|
- compression "$BACKUPDIR/monthly/$MDB/${MDB}_$DATE.$M.$MDB.$EXT"
|
|
|
|
- BACKUPFILES="$BACKUPFILES $BACKUPDIR/monthly/$MDB/${MDB}_$DATE.$M.$MDB.$EXT$SUFFIX*"
|
|
|
|
|
|
+ echo Monthly Backup of ${MDB}...
|
|
|
|
+ dbdump "${MDB}" "${BACKUPDIR}/monthly/${MDB}/${MDB}_${DATE}.${M}.${MDB}.${EXT}"
|
|
|
|
+ compression "${BACKUPDIR}/monthly/${MDB}/${MDB}_${DATE}.${M}.${MDB}.${EXT}"
|
|
|
|
+ BACKUPFILES="${BACKUPFILES} ${BACKUPDIR}/monthly/${MDB}/${MDB}_${DATE}.${M}.${MDB}.${EXT}${SUFFIX}*"
|
|
echo ----------------------------------------------------------------------
|
|
echo ----------------------------------------------------------------------
|
|
done
|
|
done
|
|
fi
|
|
fi
|
|
|
|
|
|
- for DB in $DBNAMES
|
|
|
|
- do
|
|
|
|
- # Prepare $DB for using
|
|
|
|
- DB="`echo $DB | sed 's/%/ /g'`"
|
|
|
|
|
|
+ for DB in ${DBNAMES} ; do
|
|
|
|
+ # Prepare ${DB} for using
|
|
|
|
+ DB="`echo ${DB} | sed 's/%/ /g'`"
|
|
|
|
|
|
- # Create Seperate directory for each DB
|
|
|
|
- if [ ! -e "$BACKUPDIR/daily/$DB" ] # Check Daily DB Directory exists.
|
|
|
|
- then
|
|
|
|
- mkdir -p "$BACKUPDIR/daily/$DB"
|
|
|
|
- fi
|
|
|
|
|
|
+ # Create Seperate directory for each DB
|
|
|
|
+ if [ ! -e "${BACKUPDIR}/daily/${DB}" ]; then # Check Daily DB Directory exists.
|
|
|
|
+ mkdir -p "${BACKUPDIR}/daily/${DB}"
|
|
|
|
+ fi
|
|
|
|
|
|
- if [ ! -e "$BACKUPDIR/weekly/$DB" ] # Check Weekly DB Directory exists.
|
|
|
|
- then
|
|
|
|
- mkdir -p "$BACKUPDIR/weekly/$DB"
|
|
|
|
- fi
|
|
|
|
|
|
+ if [ ! -e "${BACKUPDIR}/weekly/${DB}" ]; then # Check Weekly DB Directory exists.
|
|
|
|
+ mkdir -p "${BACKUPDIR}/weekly/${DB}"
|
|
|
|
+ fi
|
|
|
|
|
|
- # Weekly Backup
|
|
|
|
- if [ "$DNOW" = "$DOWEEKLY" ]; then
|
|
|
|
- echo Weekly Backup of Database \( $DB \)
|
|
|
|
- echo Rotating 5 weeks Backups...
|
|
|
|
- if [ "$W" -le 05 ];then
|
|
|
|
- REMW=`expr 48 + $W`
|
|
|
|
- elif [ "$W" -lt 15 ];then
|
|
|
|
- REMW=0`expr $W - 5`
|
|
|
|
|
|
+ # Weekly Backup
|
|
|
|
+ if [ "${DNOW}" = "${DOWEEKLY}" ]; then
|
|
|
|
+ echo Weekly Backup of Database \( ${DB} \)
|
|
|
|
+ echo Rotating 5 weeks Backups...
|
|
|
|
+ if [ "${W}" -le 05 ];then
|
|
|
|
+ REMW=`expr 48 + ${W}`
|
|
|
|
+ elif [ "${W}" -lt 15 ];then
|
|
|
|
+ REMW=0`expr ${W} - 5`
|
|
else
|
|
else
|
|
- REMW=`expr $W - 5`
|
|
|
|
|
|
+ REMW=`expr ${W} - 5`
|
|
fi
|
|
fi
|
|
- rm -fv "$BACKUPDIR/weekly/$DB/${DB}_week.$REMW".*
|
|
|
|
- echo
|
|
|
|
- dbdump "$DB" "$BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.$EXT"
|
|
|
|
- compression "$BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.$EXT"
|
|
|
|
- BACKUPFILES="$BACKUPFILES $BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.$EXT$SUFFIX*"
|
|
|
|
- echo ----------------------------------------------------------------------
|
|
|
|
-
|
|
|
|
- # Daily Backup
|
|
|
|
- else
|
|
|
|
- echo Daily Backup of Database \( $DB \)
|
|
|
|
- echo Rotating last weeks Backup...
|
|
|
|
- rm -fv "$BACKUPDIR/daily/$DB"/*."$DOW".$EXT*
|
|
|
|
- echo
|
|
|
|
- dbdump "$DB" "$BACKUPDIR/daily/$DB/${DB}_$DATE.$DOW.$EXT"
|
|
|
|
- compression "$BACKUPDIR/daily/$DB/${DB}_$DATE.$DOW.$EXT"
|
|
|
|
- BACKUPFILES="$BACKUPFILES $BACKUPDIR/daily/$DB/${DB}_$DATE.$DOW.$EXT$SUFFIX*"
|
|
|
|
- echo ----------------------------------------------------------------------
|
|
|
|
- fi
|
|
|
|
|
|
+ rm -fv "${BACKUPDIR}/weekly/${DB}/${DB}_week.${REMW}".*
|
|
|
|
+ echo
|
|
|
|
+ dbdump "${DB}" "${BACKUPDIR}/weekly/${DB}/${DB}_week.${W}.${DATE}.${EXT}"
|
|
|
|
+ compression "${BACKUPDIR}/weekly/${DB}/${DB}_week.${W}.${DATE}.${EXT}"
|
|
|
|
+ BACKUPFILES="${BACKUPFILES} ${BACKUPDIR}/weekly/${DB}/${DB}_week.${W}.${DATE}.${EXT}${SUFFIX}*"
|
|
|
|
+ echo ----------------------------------------------------------------------
|
|
|
|
+ # Daily Backup
|
|
|
|
+ else
|
|
|
|
+ echo Daily Backup of Database \( ${DB} \)
|
|
|
|
+ echo Rotating last weeks Backup...
|
|
|
|
+ rm -fv "${BACKUPDIR}/daily/${DB}"/*."${DOW}".${EXT}*
|
|
|
|
+ echo
|
|
|
|
+ dbdump "${DB}" "${BACKUPDIR}/daily/${DB}/${DB}_${DATE}.${DOW}.${EXT}"
|
|
|
|
+ compression "${BACKUPDIR}/daily/${DB}/${DB}_${DATE}.${DOW}.${EXT}"
|
|
|
|
+ BACKUPFILES="${BACKUPFILES} ${BACKUPDIR}/daily/${DB}/${DB}_${DATE}.${DOW}.${EXT}${SUFFIX}*"
|
|
|
|
+ echo ----------------------------------------------------------------------
|
|
|
|
+ fi
|
|
done
|
|
done
|
|
-echo Backup End `date`
|
|
|
|
-echo ======================================================================
|
|
|
|
-
|
|
|
|
|
|
+ echo Backup End `date`
|
|
|
|
+ echo ======================================================================
|
|
|
|
|
|
else # One backup file for all DBs
|
|
else # One backup file for all DBs
|
|
-echo Backup Start `date`
|
|
|
|
-echo ======================================================================
|
|
|
|
|
|
+
|
|
|
|
+ echo Backup Start `date`
|
|
|
|
+ echo ======================================================================
|
|
# Monthly Full Backup of all Databases
|
|
# Monthly Full Backup of all Databases
|
|
- if [ "$DOM" = "01" ]; then
|
|
|
|
- echo Monthly full Backup of \( $MDBNAMES \)...
|
|
|
|
- dbdump "$MDBNAMES" "$BACKUPDIR/monthly/$DATE.$M.all-databases.$EXT"
|
|
|
|
- compression "$BACKUPDIR/monthly/$DATE.$M.all-databases.$EXT"
|
|
|
|
- BACKUPFILES="$BACKUPFILES $BACKUPDIR/monthly/$DATE.$M.all-databases.$EXT$SUFFIX*"
|
|
|
|
|
|
+ if [ "${DOM}" = "01" ]; then
|
|
|
|
+ echo Monthly full Backup of \( ${MDBNAMES} \)...
|
|
|
|
+ dbdump "${MDBNAMES}" "${BACKUPDIR}/monthly/${DATE}.${M}.all-databases.${EXT}"
|
|
|
|
+ compression "${BACKUPDIR}/monthly/${DATE}.${M}.all-databases.${EXT}"
|
|
|
|
+ BACKUPFILES="${BACKUPFILES} ${BACKUPDIR}/monthly/${DATE}.${M}.all-databases.${EXT}${SUFFIX}*"
|
|
echo ----------------------------------------------------------------------
|
|
echo ----------------------------------------------------------------------
|
|
fi
|
|
fi
|
|
|
|
|
|
# Weekly Backup
|
|
# Weekly Backup
|
|
- if [ "$DNOW" = "$DOWEEKLY" ]; then
|
|
|
|
- echo Weekly Backup of Databases \( $DBNAMES \)
|
|
|
|
|
|
+ if [ "${DNOW}" = "${DOWEEKLY}" ]; then
|
|
|
|
+ echo Weekly Backup of Databases \( ${DBNAMES} \)
|
|
echo
|
|
echo
|
|
echo Rotating 5 weeks Backups...
|
|
echo Rotating 5 weeks Backups...
|
|
- if [ "$W" -le 05 ];then
|
|
|
|
- REMW=`expr 48 + $W`
|
|
|
|
- elif [ "$W" -lt 15 ];then
|
|
|
|
- REMW=0`expr $W - 5`
|
|
|
|
- else
|
|
|
|
- REMW=`expr $W - 5`
|
|
|
|
- fi
|
|
|
|
- rm -fv "$BACKUPDIR/weekly/week.$REMW".*
|
|
|
|
|
|
+ if [ "${W}" -le 05 ];then
|
|
|
|
+ REMW=`expr 48 + ${W}`
|
|
|
|
+ elif [ "${W}" -lt 15 ];then
|
|
|
|
+ REMW=0`expr ${W} - 5`
|
|
|
|
+ else
|
|
|
|
+ REMW=`expr ${W} - 5`
|
|
|
|
+ fi
|
|
|
|
+ rm -fv "${BACKUPDIR}/weekly/week.${REMW}".*
|
|
echo
|
|
echo
|
|
- dbdump "$DBNAMES" "$BACKUPDIR/weekly/week.$W.$DATE.$EXT"
|
|
|
|
- compression "$BACKUPDIR/weekly/week.$W.$DATE.$EXT"
|
|
|
|
- BACKUPFILES="$BACKUPFILES $BACKUPDIR/weekly/week.$W.$DATE.$EXT$SUFFIX*"
|
|
|
|
|
|
+ dbdump "${DBNAMES}" "${BACKUPDIR}/weekly/week.${W}.${DATE}.${EXT}"
|
|
|
|
+ compression "${BACKUPDIR}/weekly/week.${W}.${DATE}.${EXT}"
|
|
|
|
+ BACKUPFILES="${BACKUPFILES} ${BACKUPDIR}/weekly/week.${W}.${DATE}.${EXT}${SUFFIX}*"
|
|
echo ----------------------------------------------------------------------
|
|
echo ----------------------------------------------------------------------
|
|
# Daily Backup
|
|
# Daily Backup
|
|
else
|
|
else
|
|
- echo Daily Backup of Databases \( $DBNAMES \)
|
|
|
|
|
|
+ echo Daily Backup of Databases \( ${DBNAMES} \)
|
|
echo
|
|
echo
|
|
echo Rotating last weeks Backup...
|
|
echo Rotating last weeks Backup...
|
|
- rm -fv "$BACKUPDIR"/daily/*."$DOW".$EXT*
|
|
|
|
|
|
+ rm -fv "${BACKUPDIR}"/daily/*."${DOW}".${EXT}*
|
|
echo
|
|
echo
|
|
- dbdump "$DBNAMES" "$BACKUPDIR/daily/$DATE.$DOW.$EXT"
|
|
|
|
- compression "$BACKUPDIR/daily/$DATE.$DOW.$EXT"
|
|
|
|
- BACKUPFILES="$BACKUPFILES $BACKUPDIR/daily/$DATE.$DOW.$EXT$SUFFIX*"
|
|
|
|
|
|
+ dbdump "${DBNAMES}" "${BACKUPDIR}/daily/${DATE}.${DOW}.${EXT}"
|
|
|
|
+ compression "${BACKUPDIR}/daily/${DATE}.${DOW}.${EXT}"
|
|
|
|
+ BACKUPFILES="${BACKUPFILES} ${BACKUPDIR}/daily/${DATE}.${DOW}.${EXT}${SUFFIX}*"
|
|
echo ----------------------------------------------------------------------
|
|
echo ----------------------------------------------------------------------
|
|
fi
|
|
fi
|
|
-echo Backup End Time `date`
|
|
|
|
-echo ======================================================================
|
|
|
|
|
|
+ echo Backup End Time `date`
|
|
|
|
+ echo ======================================================================
|
|
fi
|
|
fi
|
|
|
|
+
|
|
echo Total disk space used for backup storage..
|
|
echo Total disk space used for backup storage..
|
|
echo Size - Location
|
|
echo Size - Location
|
|
-echo `du -hs "$BACKUPDIR"`
|
|
|
|
|
|
+echo `du -hs "${BACKUPDIR}"`
|
|
echo
|
|
echo
|
|
|
|
|
|
-
|
|
|
|
# Run command when we're done
|
|
# Run command when we're done
|
|
-if [ "$POSTBACKUP" ]
|
|
|
|
|
|
+if [ "${POSTBACKUP}" ]
|
|
then
|
|
then
|
|
echo ======================================================================
|
|
echo ======================================================================
|
|
echo "Postbackup command output."
|
|
echo "Postbackup command output."
|
|
echo
|
|
echo
|
|
- $POSTBACKUP
|
|
|
|
|
|
+ ${POSTBACKUP}
|
|
echo
|
|
echo
|
|
echo ======================================================================
|
|
echo ======================================================================
|
|
fi
|
|
fi
|
|
@@ -623,77 +607,64 @@ fi
|
|
exec 1>&6 6>&- # Restore stdout and close file descriptor #6.
|
|
exec 1>&6 6>&- # Restore stdout and close file descriptor #6.
|
|
exec 2>&7 7>&- # Restore stdout and close file descriptor #7.
|
|
exec 2>&7 7>&- # Restore stdout and close file descriptor #7.
|
|
|
|
|
|
-if [ "$MAILCONTENT" = "files" ]
|
|
|
|
-then
|
|
|
|
- if [ -s "$LOGERR" ]
|
|
|
|
- then
|
|
|
|
|
|
+if [ "${MAILCONTENT}" = "files" ]; then
|
|
|
|
+ if [ -s "${LOGERR}" ]; then
|
|
# Include error log if is larger than zero.
|
|
# Include error log if is larger than zero.
|
|
- BACKUPFILES="$BACKUPFILES $LOGERR"
|
|
|
|
|
|
+ BACKUPFILES="${BACKUPFILES} ${LOGERR}"
|
|
ERRORNOTE="WARNING: Error Reported - "
|
|
ERRORNOTE="WARNING: Error Reported - "
|
|
fi
|
|
fi
|
|
#Get backup size
|
|
#Get backup size
|
|
- ATTSIZE=`du -c $BACKUPFILES | grep "[[:digit:][:space:]]total$" |sed s/\s*total//`
|
|
|
|
- if [ $MAXATTSIZE -ge $ATTSIZE ]
|
|
|
|
- then
|
|
|
|
- if which biabam >/dev/null 2>&1
|
|
|
|
- then
|
|
|
|
- BACKUPFILES=$(echo $BACKUPFILES | sed -r -e 's#\s+#,#g')
|
|
|
|
- biabam -s "PostgreSQL Backup Log and SQL Files for $HOST - $DATE" $BACKUPFILES $MAILADDR < $LOGFILE
|
|
|
|
- elif which heirloom-mailx >/dev/null 2>&1
|
|
|
|
- then
|
|
|
|
- BACKUPFILES=$(echo $BACKUPFILES | sed -e 's# # -a #g')
|
|
|
|
- heirloom-mailx -s "PostgreSQL Backup Log and SQL Files for $HOST - $DATE" $BACKUPFILES $MAILADDR < $LOGFILE
|
|
|
|
- elif which neomutt >/dev/null 2>&1
|
|
|
|
- then
|
|
|
|
- BACKUPFILES=$(echo $BACKUPFILES | sed -e 's# # -a #g')
|
|
|
|
- neomutt -s "PostgreSQL Backup Log and SQL Files for $HOST - $DATE" -a $BACKUPFILES -- $MAILADDR < $LOGFILE
|
|
|
|
- elif which mutt >/dev/null 2>&1
|
|
|
|
- then
|
|
|
|
- BACKUPFILES=$(echo $BACKUPFILES | sed -e 's# # -a #g')
|
|
|
|
- mutt -s "PostgreSQL Backup Log and SQL Files for $HOST - $DATE" -a $BACKUPFILES -- $MAILADDR < $LOGFILE
|
|
|
|
|
|
+ ATTSIZE=`du -c ${BACKUPFILES} | grep "[[:digit:][:space:]]total$" |sed s/\s*total//`
|
|
|
|
+ if [ ${MAXATTSIZE} -ge ${ATTSIZE} ]; then
|
|
|
|
+ if which biabam >/dev/null 2>&1; then
|
|
|
|
+ BACKUPFILES=$(echo ${BACKUPFILES} | sed -r -e 's#\s+#,#g')
|
|
|
|
+ biabam -s "PostgreSQL Backup Log and SQL Files for ${HOST} - ${DATE}" ${BACKUPFILES} ${MAILADDR} < ${LOGFILE}
|
|
|
|
+ elif which heirloom-mailx >/dev/null 2>&1; then
|
|
|
|
+ BACKUPFILES=$(echo ${BACKUPFILES} | sed -e 's# # -a #g')
|
|
|
|
+ heirloom-mailx -s "PostgreSQL Backup Log and SQL Files for ${HOST} - ${DATE}" ${BACKUPFILES} ${MAILADDR} < ${LOGFILE}
|
|
|
|
+ elif which neomutt >/dev/null 2>&1; then
|
|
|
|
+ BACKUPFILES=$(echo ${BACKUPFILES} | sed -e 's# # -a #g')
|
|
|
|
+ neomutt -s "PostgreSQL Backup Log and SQL Files for ${HOST} - ${DATE}" -a ${BACKUPFILES} -- ${MAILADDR} < ${LOGFILE}
|
|
|
|
+ elif which mutt >/dev/null 2>&1; then
|
|
|
|
+ BACKUPFILES=$(echo ${BACKUPFILES} | sed -e 's# # -a #g')
|
|
|
|
+ mutt -s "PostgreSQL Backup Log and SQL Files for ${HOST} - ${DATE}" -a ${BACKUPFILES} -- ${MAILADDR} < ${LOGFILE}
|
|
else
|
|
else
|
|
- cat "$LOGFILE" | mail -s "WARNING! - Enable to send PostgreSQL Backup dumps, no suitable mail client found on $HOST - $DATE" $MAILADDR
|
|
|
|
|
|
+ cat "${LOGFILE}" | mail -s "WARNING! - Enable to send PostgreSQL Backup dumps, no suitable mail client found on ${HOST} - ${DATE}" ${MAILADDR}
|
|
fi
|
|
fi
|
|
else
|
|
else
|
|
- cat "$LOGFILE" | mail -s "WARNING! - PostgreSQL Backup exceeds set maximum attachment size on $HOST - $DATE" $MAILADDR
|
|
|
|
|
|
+ cat "${LOGFILE}" | mail -s "WARNING! - PostgreSQL Backup exceeds set maximum attachment size on ${HOST} - ${DATE}" ${MAILADDR}
|
|
fi
|
|
fi
|
|
-elif [ "$MAILCONTENT" = "log" ]
|
|
|
|
-then
|
|
|
|
- cat "$LOGFILE" | mail -s "PostgreSQL Backup Log for $HOST - $DATE" $MAILADDR
|
|
|
|
- if [ -s "$LOGERR" ]
|
|
|
|
- then
|
|
|
|
- cat "$LOGERR" | mail -s "ERRORS REPORTED: PostgreSQL Backup error Log for $HOST - $DATE" $MAILADDR
|
|
|
|
|
|
+elif [ "${MAILCONTENT}" = "log" ]; then
|
|
|
|
+ cat "${LOGFILE}" | mail -s "PostgreSQL Backup Log for ${HOST} - ${DATE}" ${MAILADDR}
|
|
|
|
+ if [ -s "${LOGERR}" ]; then
|
|
|
|
+ cat "${LOGERR}" | mail -s "ERRORS REPORTED: PostgreSQL Backup error Log for ${HOST} - ${DATE}" ${MAILADDR}
|
|
fi
|
|
fi
|
|
-elif [ "$MAILCONTENT" = "quiet" ]
|
|
|
|
-then
|
|
|
|
- if [ -s "$LOGERR" ]
|
|
|
|
- then
|
|
|
|
- cat "$LOGERR" | mail -s "ERRORS REPORTED: PostgreSQL Backup error Log for $HOST - $DATE" $MAILADDR
|
|
|
|
- cat "$LOGFILE" | mail -s "PostgreSQL Backup Log for $HOST - $DATE" $MAILADDR
|
|
|
|
|
|
+elif [ "${MAILCONTENT}" = "quiet" ]; then
|
|
|
|
+ if [ -s "${LOGERR}" ]; then
|
|
|
|
+ cat "${LOGERR}" | mail -s "ERRORS REPORTED: PostgreSQL Backup error Log for ${HOST} - ${DATE}" ${MAILADDR}
|
|
|
|
+ cat "${LOGFILE}" | mail -s "PostgreSQL Backup Log for ${HOST} - ${DATE}" ${MAILADDR}
|
|
fi
|
|
fi
|
|
else
|
|
else
|
|
- if [ -s "$LOGERR" ]
|
|
|
|
- then
|
|
|
|
- cat "$LOGFILE"
|
|
|
|
- echo
|
|
|
|
- echo "###### WARNING ######"
|
|
|
|
- echo "Errors reported during AutoPostgreSQLBackup execution.. Backup failed"
|
|
|
|
- echo "Error log below.."
|
|
|
|
- cat "$LOGERR"
|
|
|
|
|
|
+ if [ -s "${LOGERR}" ]; then
|
|
|
|
+ cat "${LOGFILE}"
|
|
|
|
+ echo
|
|
|
|
+ echo "###### WARNING ######"
|
|
|
|
+ echo "Errors reported during AutoPostgreSQLBackup execution.. Backup failed"
|
|
|
|
+ echo "Error log below.."
|
|
|
|
+ cat "${LOGERR}"
|
|
else
|
|
else
|
|
- cat "$LOGFILE"
|
|
|
|
|
|
+ cat "${LOGFILE}"
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
|
|
-if [ -s "$LOGERR" ]
|
|
|
|
- then
|
|
|
|
- STATUS=1
|
|
|
|
- else
|
|
|
|
- STATUS=0
|
|
|
|
|
|
+if [ -s "${LOGERR}" ]; then
|
|
|
|
+ STATUS=1
|
|
|
|
+else
|
|
|
|
+ STATUS=0
|
|
fi
|
|
fi
|
|
|
|
|
|
# Clean up Logfile
|
|
# Clean up Logfile
|
|
-rm -f "$LOGFILE"
|
|
|
|
-rm -f "$LOGERR"
|
|
|
|
|
|
+rm -f "${LOGFILE}"
|
|
|
|
+rm -f "${LOGERR}"
|
|
|
|
|
|
-exit $STATUS
|
|
|
|
|
|
+exit ${STATUS}
|