From: | SCassidy(at)overlandstorage(dot)com |
---|---|
To: | alexandre - aldeia digital <alexandre(at)ad2(dot)com(dot)br> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: pg_dump error codes |
Date: | 2006-01-03 17:06:38 |
Message-ID: | OF0F7B6F71.21567424-ON882570EB.005DD915-882570EB.005DFE1A@overlandstorage.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Here is a simple one, that keeps 2 copies (one for odd-numbered days and
one for even-numbered days), and emails the admin with the status:
#!/bin/sh
#This script is to back up the production databases
DBLIST="db1 proddb1 proddb2"
PGUSER=dbusername
DUMPDIR=/disk1/database/backups
MAILCMD=/bin/mail
ADMIN_EMAIL='adminemail(at)mycompany(dot)com'
MAILLOG=/tmp/maillog$$
MAIL_SUBJECT="Database Backup Process"
LOGFILE=/disk1/homedir/database/db_backup.log
function MAILERROR {
$MAILCMD -s "$1" "$ADMIN_EMAIL" <$MAILLOG
rm $MAILLOG
exit 1
}
if ! cd $DUMPDIR ; then
echo "Cannot cd into $DUMPDIR for backup process" >>$LOGFILE
MAILERROR "$MAIL_SUBJECT - Error during cd into $DUMPDIR"
fi
#=== we are going to create 2 sets of dump files, for odd and even days ===
#get the day of the year
NUM=`date '+%j'`
#if we don't delete the leading 0, the shell thinks it is an octal number
NUM=${NUM##0}
RES=$(( $NUM % 2 ))
for DBNAME in $DBLIST; do
echo "Backup of $DBNAME started at $(date)" >>$MAILLOG
DUMPFILE=dump_${DBNAME}_${RES}
echo -e "\nStarting backup of $DBNAME to $DUMPFILE at $(date)" >>$LOGFILE
echo -e "\nStarting backup of $DBNAME to $DUMPFILE at $(date)" >>$MAILLOG
#delete the old file(s)
if [ -e $DUMPFILE ]; then
/bin/rm $DUMPFILE* 2>>$LOGFILE
fi
#using postgresql custom dump format, with compression; allows selective
restore
if ! /usr/local/pgsql/bin/pg_dump -Fc -U $PGUSER $DBNAME >${DUMPFILE}
2>>$LOGFILE ; then
echo "Error during pg_dump of $DBNAME" >> $LOGFILE
echo "Error during pg_dump; see $LOGFILE for details" >> $MAILLOG
MAILERROR "$MAIL_SUBJECT - Error during pg_dump of $DBNAME"
fi
#record process success
echo -e "Backup of $DBNAME complete at $(date)\n" >>$LOGFILE
echo -e "Backup of $DBNAME succeeded $(date)\n\n" >>$MAILLOG
done
MAIL_SUBJECT="$MAIL_SUBJECT - Backup of databases succeeded"
$MAILCMD -s "$MAIL_SUBJECT" "$ADMIN_EMAIL" <$MAILLOG
rm $MAILLOG
exit 0
Hope this helps.
Susan
alexandre - aldeia
digital To: pgsql-general(at)postgresql(dot)org
<alexandre(at)ad2(dot)com(dot)br> cc:
Sent by: Subject: [GENERAL] pg_dump error codes
|-------------------|
pgsql-general-owner(at)pos | [ ] Expand Groups |
tgresql.org |-------------------|
01/02/2006 02:45
AM
Hi,
(maybe an idiot question)
In my Linux bash backup scripts, I wish to send an e-mail when an error
occurs in pg_dump proccess. And if possible, I want to send the error
output via e-mail.
Anybody knows how to capture the output and send this to an e-mail ONLY
if an error occurs ?
Thanks
Alexandre
---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings
----------------------------------------------------------------------------------------------
Simply protected storage solutions ensure that your information is
automatically safe, readily available and always there, visit us at http://www.overlandstorage.com
----------------------------------------------------------------------------------------------
From | Date | Subject | |
---|---|---|---|
Next Message | MargaretGillon | 2006-01-03 17:06:52 | Re: Visual FoxPro 9 ODBC errors |
Previous Message | Marc Munro | 2006-01-03 16:55:16 | bit/integer operations in postgres |