autopostgresqlbackup 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. #!/bin/bash
  2. #
  3. # PostgreSQL Backup Script Ver 1.0
  4. # http://autopgsqlbackup.frozenpc.net
  5. # Copyright (c) 2005 Aaron Axelsen <axelseaa@amadmax.com>
  6. #
  7. # This script is based of the AutoMySQLBackup Script Ver 2.2
  8. # It can be found at http://sourceforge.net/projects/automysqlbackup/
  9. #
  10. # The PostgreSQL changes are based on a patch agaisnt AutoMySQLBackup 1.9
  11. # created by Friedrich Lobenstock <fl@fl.priv.at>
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # (at your option) any later version.
  17. #
  18. # This program is distributed in the hope that it will be useful,
  19. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. # GNU General Public License for more details.
  22. #
  23. # You should have received a copy of the GNU General Public License
  24. # along with this program; if not, write to the Free Software
  25. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. #
  27. #=====================================================================
  28. # Set the following variables to your system needs
  29. # (Detailed instructions below variables)
  30. #=====================================================================
  31. # Username to access the PostgreSQL server e.g. dbuser
  32. USERNAME=postgres
  33. # Password
  34. # create a file $HOME/.pgpass containing a line like this
  35. # hostname:*:*:dbuser:dbpass
  36. # replace hostname with the value of DBHOST and postgres with
  37. # the value of USERNAME
  38. # Host name (or IP address) of PostgreSQL server e.g localhost
  39. DBHOST=localhost
  40. # List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3"
  41. DBNAMES="all"
  42. # Backup directory location e.g /backups
  43. BACKUPDIR="/backups"
  44. # Mail setup
  45. # What would you like to be mailed to you?
  46. # - log : send only log file
  47. # - files : send log file and sql files as attachments (see docs)
  48. # - stdout : will simply output the log to the screen if run manually.
  49. # - quiet : Only send logs if an error occurs to the MAILADDR.
  50. MAILCONTENT="stdout"
  51. # Set the maximum allowed email size in k. (4000 = approx 5MB email [see docs])
  52. MAXATTSIZE="4000"
  53. # Email Address to send mail to? (user@domain.com)
  54. MAILADDR="user@domain.com"
  55. # ============================================================
  56. # === ADVANCED OPTIONS ( Read the doc's below for details )===
  57. #=============================================================
  58. # List of DBBNAMES for Monthly Backups.
  59. MDBNAMES="template1 $DBNAMES"
  60. # List of DBNAMES to EXLUCDE if DBNAMES are set to all (must be in " quotes)
  61. DBEXCLUDE=""
  62. # Include CREATE DATABASE in backup?
  63. CREATE_DATABASE=yes
  64. # Separate backup directory and file for each DB? (yes or no)
  65. SEPDIR=yes
  66. # Which day do you want weekly backups? (1 to 7 where 1 is Monday)
  67. DOWEEKLY=6
  68. # Choose Compression type. (gzip or bzip2)
  69. COMP=gzip
  70. # Compress communications between backup server and PostgreSQL server?
  71. # set compression level from 0 to 9 (0 means no compression)
  72. COMMCOMP=0
  73. # Additionally keep a copy of the most recent backup in a seperate directory.
  74. LATEST=no
  75. # Command to run before backups (uncomment to use)
  76. #PREBACKUP="/etc/postgresql-backup-pre"
  77. # Command run after backups (uncomment to use)
  78. #POSTBACKUP="/etc/postgresql-backup-post"
  79. #=====================================================================
  80. # Options documentation
  81. #=====================================================================
  82. # Set USERNAME and PASSWORD of a user that has at least SELECT permission
  83. # to ALL databases.
  84. #
  85. # Set the DBHOST option to the server you wish to backup, leave the
  86. # default to backup "this server".(to backup multiple servers make
  87. # copies of this file and set the options for that server)
  88. #
  89. # Put in the list of DBNAMES(Databases)to be backed up. If you would like
  90. # to backup ALL DBs on the server set DBNAMES="all".(if set to "all" then
  91. # any new DBs will automatically be backed up without needing to modify
  92. # this backup script when a new DB is created).
  93. #
  94. # If the DB you want to backup has a space in the name replace the space
  95. # with a % e.g. "data base" will become "data%base"
  96. # NOTE: Spaces in DB names may not work correctly when SEPDIR=no.
  97. #
  98. # You can change the backup storage location from /backups to anything
  99. # you like by using the BACKUPDIR setting..
  100. #
  101. # The MAILCONTENT and MAILADDR options and pretty self explanitory, use
  102. # these to have the backup log mailed to you at any email address or multiple
  103. # email addresses in a space seperated list.
  104. # (If you set mail content to "log" you will require access to the "mail" program
  105. # on your server. If you set this to "files" you will have to have mutt installed
  106. # on your server. If you set it to "stdout" it will log to the screen if run from
  107. # the console or to the cron job owner if run through cron. If you set it to "quiet"
  108. # logs will only be mailed if there are errors reported. )
  109. #
  110. # MAXATTSIZE sets the largest allowed email attachments total (all backup files) you
  111. # want the script to send. This is the size before it is encoded to be sent as an email
  112. # so if your mail server will allow a maximum mail size of 5MB I would suggest setting
  113. # MAXATTSIZE to be 25% smaller than that so a setting of 4000 would probably be fine.
  114. #
  115. # Finally copy autopostgresqlbackup.sh to anywhere on your server and make sure
  116. # to set executable permission. You can also copy the script to
  117. # /etc/cron.daily to have it execute automatically every night or simply
  118. # place a symlink in /etc/cron.daily to the file if you wish to keep it
  119. # somwhere else.
  120. # NOTE:On Debian copy the file with no extention for it to be run
  121. # by cron e.g just name the file "autopostgresqlbackup"
  122. #
  123. # Thats it..
  124. #
  125. #
  126. # === Advanced options doc's ===
  127. #
  128. # The list of MDBNAMES is the DB's to be backed up only monthly. You should
  129. # always include "template1" in this list to backup the default database
  130. # template used to create new databases.
  131. # NOTE: If DBNAMES="all" then MDBNAMES has no effect as all DBs will be backed
  132. # up anyway.
  133. #
  134. # If you set DBNAMES="all" you can configure the option DBEXCLUDE. Other
  135. # wise this option will not be used.
  136. # This option can be used if you want to backup all dbs, but you want
  137. # exclude some of them. (eg. a db is to big).
  138. #
  139. # Set CREATE_DATABASE to "yes" (the default) if you want your SQL-Dump to create
  140. # a database with the same name as the original database when restoring.
  141. # Saying "no" here will allow your to specify the database name you want to
  142. # restore your dump into, making a copy of the database by using the dump
  143. # created with autopostgresqlbackup.
  144. # NOTE: Not used if SEPDIR=no
  145. #
  146. # The SEPDIR option allows you to choose to have all DBs backed up to
  147. # a single file (fast restore of entire server in case of crash) or to
  148. # seperate directories for each DB (each DB can be restored seperately
  149. # in case of single DB corruption or loss).
  150. #
  151. # To set the day of the week that you would like the weekly backup to happen
  152. # set the DOWEEKLY setting, this can be a value from 1 to 7 where 1 is Monday,
  153. # The default is 6 which means that weekly backups are done on a Saturday.
  154. #
  155. # COMP is used to choose the copmression used, options are gzip or bzip2.
  156. # bzip2 will produce slightly smaller files but is more processor intensive so
  157. # may take longer to complete.
  158. #
  159. # COMMCOMP is used to set the compression level (from 0 to 9, 0 means no compression)
  160. # between the client and the server, so it is useful to save bandwidth when backing up
  161. # a remote PostgresSQL server over the network.
  162. #
  163. # LATEST is to store an additional copy of the latest backup to a standard
  164. # location so it can be downloaded bt thrid party scripts.
  165. #
  166. # Use PREBACKUP and POSTBACKUP to specify Per and Post backup commands
  167. # or scripts to perform tasks either before or after the backup process.
  168. #
  169. #
  170. #=====================================================================
  171. # Backup Rotation..
  172. #=====================================================================
  173. #
  174. # Daily Backups are rotated weekly..
  175. # Weekly Backups are run by default on Saturday Morning when
  176. # cron.daily scripts are run...Can be changed with DOWEEKLY setting..
  177. # Weekly Backups are rotated on a 5 week cycle..
  178. # Monthly Backups are run on the 1st of the month..
  179. # Monthly Backups are NOT rotated automatically...
  180. # It may be a good idea to copy Monthly backups offline or to another
  181. # server..
  182. #
  183. #=====================================================================
  184. # Please Note!!
  185. #=====================================================================
  186. #
  187. # I take no resposibility for any data loss or corruption when using
  188. # this script..
  189. # This script will not help in the event of a hard drive crash. If a
  190. # copy of the backup has not be stored offline or on another PC..
  191. # You should copy your backups offline regularly for best protection.
  192. #
  193. # Happy backing up...
  194. #
  195. #=====================================================================
  196. # Restoring
  197. #=====================================================================
  198. # Firstly you will need to uncompress the backup file.
  199. # eg.
  200. # gunzip file.gz (or bunzip2 file.bz2)
  201. #
  202. # Next you will need to use the postgresql client to restore the DB from the
  203. # sql file.
  204. # eg.
  205. # psql --host dbserver --dbname database < /path/file.sql
  206. #
  207. # NOTE: Make sure you use "<" and not ">" in the above command because
  208. # you are piping the file.sql to psql and not the other way around.
  209. #
  210. # Lets hope you never have to use this.. :)
  211. #
  212. #=====================================================================
  213. # Change Log
  214. #=====================================================================
  215. #
  216. # VER 1.0 - (2005-03-25)
  217. # Initial Release - based on AutoMySQLBackup 2.2
  218. #
  219. #=====================================================================
  220. #=====================================================================
  221. #=====================================================================
  222. #
  223. # Should not need to be modified from here down!!
  224. #
  225. #=====================================================================
  226. #=====================================================================
  227. #=====================================================================
  228. PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/postgres/bin:/usr/local/pgsql/bin
  229. DATE=`date +%Y-%m-%d_%Hh%Mm` # Datestamp e.g 2002-09-21
  230. DOW=`date +%A` # Day of the week e.g. Monday
  231. DNOW=`date +%u` # Day number of the week 1 to 7 where 1 represents Monday
  232. DOM=`date +%d` # Date of the Month e.g. 27
  233. M=`date +%B` # Month e.g January
  234. W=`date +%V` # Week Number e.g 37
  235. VER=1.0 # Version Number
  236. LOGFILE=$BACKUPDIR/$DBHOST-`date +%N`.log # Logfile Name
  237. LOGERR=$BACKUPDIR/ERRORS_$DBHOST-`date +%N`.log # Logfile Name
  238. BACKUPFILES=""
  239. OPT="" # OPT string for use with pg_dump ( see man pg_dump )
  240. # Add --compress pg_dump option to $OPT
  241. if [ "$COMMCOMP" -gt 0 ];
  242. then
  243. OPT="$OPT --compress=$COMMCOMP"
  244. fi
  245. # Create required directories
  246. if [ ! -e "$BACKUPDIR" ] # Check Backup Directory exists.
  247. then
  248. mkdir -p "$BACKUPDIR"
  249. fi
  250. if [ ! -e "$BACKUPDIR/daily" ] # Check Daily Directory exists.
  251. then
  252. mkdir -p "$BACKUPDIR/daily"
  253. fi
  254. if [ ! -e "$BACKUPDIR/weekly" ] # Check Weekly Directory exists.
  255. then
  256. mkdir -p "$BACKUPDIR/weekly"
  257. fi
  258. if [ ! -e "$BACKUPDIR/monthly" ] # Check Monthly Directory exists.
  259. then
  260. mkdir -p "$BACKUPDIR/monthly"
  261. fi
  262. if [ "$LATEST" = "yes" ]
  263. then
  264. if [ ! -e "$BACKUPDIR/latest" ] # Check Latest Directory exists.
  265. then
  266. mkdir -p "$BACKUPDIR/latest"
  267. fi
  268. eval rm -f "$BACKUPDIR/latest/*"
  269. fi
  270. # IO redirection for logging.
  271. touch $LOGFILE
  272. exec 6>&1 # Link file descriptor #6 with stdout.
  273. # Saves stdout.
  274. exec > $LOGFILE # stdout replaced with file $LOGFILE.
  275. touch $LOGERR
  276. exec 7>&2 # Link file descriptor #7 with stderr.
  277. # Saves stderr.
  278. exec 2> $LOGERR # stderr replaced with file $LOGERR.
  279. # Functions
  280. # Database dump function
  281. dbdump () {
  282. touch $2
  283. chmod 600 $2
  284. pg_dump --username=$USERNAME $PGHOST $OPT $1 > $2
  285. return 0
  286. }
  287. # Compression function plus latest copy
  288. SUFFIX=""
  289. compression () {
  290. if [ "$COMP" = "gzip" ]; then
  291. gzip -f "$1"
  292. echo
  293. echo Backup Information for "$1"
  294. gzip -l "$1.gz"
  295. SUFFIX=".gz"
  296. elif [ "$COMP" = "bzip2" ]; then
  297. echo Compression information for "$1.bz2"
  298. bzip2 -f -v $1 2>&1
  299. SUFFIX=".bz2"
  300. else
  301. echo "No compression option set, check advanced settings"
  302. fi
  303. if [ "$LATEST" = "yes" ]; then
  304. cp $1$SUFFIX "$BACKUPDIR/latest/"
  305. fi
  306. return 0
  307. }
  308. # Run command before we begin
  309. if [ "$PREBACKUP" ]
  310. then
  311. echo ======================================================================
  312. echo "Prebackup command output."
  313. echo
  314. eval $PREBACKUP
  315. echo
  316. echo ======================================================================
  317. echo
  318. fi
  319. if [ "$SEPDIR" = "yes" ]; then # Check if CREATE DATABSE should be included in Dump
  320. if [ "$CREATE_DATABASE" = "no" ]; then
  321. OPT="$OPT"
  322. else
  323. OPT="$OPT --create"
  324. fi
  325. else
  326. OPT="$OPT"
  327. fi
  328. # Hostname for LOG information
  329. if [ "$DBHOST" = "localhost" ]; then
  330. HOST=`hostname`
  331. PGHOST=""
  332. else
  333. HOST=$DBHOST
  334. PGHOST="-h $DBHOST"
  335. fi
  336. # If backing up all DBs on the server
  337. if [ "$DBNAMES" = "all" ]; then
  338. DBNAMES="`psql -U $USERNAME $PGHOST -l -A -F: | sed -ne "/:/ { /Name:Owner/d; /template0/d; s/:.*$//; p }"`"
  339. # If DBs are excluded
  340. for exclude in $DBEXCLUDE
  341. do
  342. DBNAMES=`echo $DBNAMES | sed "s/\b$exclude\b//g"`
  343. done
  344. MDBNAMES=$DBNAMES
  345. fi
  346. echo ======================================================================
  347. echo AutoPostgreSQLBackup VER $VER
  348. echo http://autopgsqlbackup.frozenpc.net/
  349. echo
  350. echo Backup of Database Server - $HOST
  351. echo ======================================================================
  352. # Test is seperate DB backups are required
  353. if [ "$SEPDIR" = "yes" ]; then
  354. echo Backup Start Time `date`
  355. echo ======================================================================
  356. # Monthly Full Backup of all Databases
  357. if [ "$DOM" = "01" ]; then
  358. for MDB in $MDBNAMES
  359. do
  360. # Prepare $DB for using
  361. MDB="`echo $MDB | sed 's/%/ /g'`"
  362. if [ ! -e "$BACKUPDIR/monthly/$MDB" ] # Check Monthly DB Directory exists.
  363. then
  364. mkdir -p "$BACKUPDIR/monthly/$MDB"
  365. fi
  366. echo Monthly Backup of $MDB...
  367. dbdump "$MDB" "$BACKUPDIR/monthly/$MDB/${MDB}_$DATE.$M.$MDB.sql"
  368. compression "$BACKUPDIR/monthly/$MDB/${MDB}_$DATE.$M.$MDB.sql"
  369. BACKUPFILES="$BACKUPFILES $BACKUPDIR/monthly/$MDB/${MDB}_$DATE.$M.$MDB.sql$SUFFIX"
  370. echo ----------------------------------------------------------------------
  371. done
  372. fi
  373. for DB in $DBNAMES
  374. do
  375. # Prepare $DB for using
  376. DB="`echo $DB | sed 's/%/ /g'`"
  377. # Create Seperate directory for each DB
  378. if [ ! -e "$BACKUPDIR/daily/$DB" ] # Check Daily DB Directory exists.
  379. then
  380. mkdir -p "$BACKUPDIR/daily/$DB"
  381. fi
  382. if [ ! -e "$BACKUPDIR/weekly/$DB" ] # Check Weekly DB Directory exists.
  383. then
  384. mkdir -p "$BACKUPDIR/weekly/$DB"
  385. fi
  386. # Weekly Backup
  387. if [ "$DNOW" = "$DOWEEKLY" ]; then
  388. echo Weekly Backup of Database \( $DB \)
  389. echo Rotating 5 weeks Backups...
  390. if [ "$W" -le 05 ];then
  391. REMW=`expr 48 + $W`
  392. elif [ "$W" -lt 15 ];then
  393. REMW=0`expr $W - 5`
  394. else
  395. REMW=`expr $W - 5`
  396. fi
  397. eval rm -fv "$BACKUPDIR/weekly/$DB/${DB}_week.$REMW.*"
  398. echo
  399. dbdump "$DB" "$BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.sql"
  400. compression "$BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.sql"
  401. BACKUPFILES="$BACKUPFILES $BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.sql$SUFFIX"
  402. echo ----------------------------------------------------------------------
  403. # Daily Backup
  404. else
  405. echo Daily Backup of Database \( $DB \)
  406. echo Rotating last weeks Backup...
  407. eval rm -fv "$BACKUPDIR/daily/$DB/*.$DOW.sql.*"
  408. echo
  409. dbdump "$DB" "$BACKUPDIR/daily/$DB/${DB}_$DATE.$DOW.sql"
  410. compression "$BACKUPDIR/daily/$DB/${DB}_$DATE.$DOW.sql"
  411. BACKUPFILES="$BACKUPFILES $BACKUPDIR/daily/$DB/${DB}_$DATE.$DOW.sql$SUFFIX"
  412. echo ----------------------------------------------------------------------
  413. fi
  414. done
  415. echo Backup End `date`
  416. echo ======================================================================
  417. else # One backup file for all DBs
  418. echo Backup Start `date`
  419. echo ======================================================================
  420. # Monthly Full Backup of all Databases
  421. if [ "$DOM" = "01" ]; then
  422. echo Monthly full Backup of \( $MDBNAMES \)...
  423. dbdump "$MDBNAMES" "$BACKUPDIR/monthly/$DATE.$M.all-databases.sql"
  424. compression "$BACKUPDIR/monthly/$DATE.$M.all-databases.sql"
  425. BACKUPFILES="$BACKUPFILES $BACKUPDIR/monthly/$DATE.$M.all-databases.sql$SUFFIX"
  426. echo ----------------------------------------------------------------------
  427. fi
  428. # Weekly Backup
  429. if [ "$DNOW" = "$DOWEEKLY" ]; then
  430. echo Weekly Backup of Databases \( $DBNAMES \)
  431. echo
  432. echo Rotating 5 weeks Backups...
  433. if [ "$W" -le 05 ];then
  434. REMW=`expr 48 + $W`
  435. elif [ "$W" -lt 15 ];then
  436. REMW=0`expr $W - 5`
  437. else
  438. REMW=`expr $W - 5`
  439. fi
  440. eval rm -fv "$BACKUPDIR/weekly/week.$REMW.*"
  441. echo
  442. dbdump "$DBNAMES" "$BACKUPDIR/weekly/week.$W.$DATE.sql"
  443. compression "$BACKUPDIR/weekly/week.$W.$DATE.sql"
  444. BACKUPFILES="$BACKUPFILES $BACKUPDIR/weekly/week.$W.$DATE.sql$SUFFIX"
  445. echo ----------------------------------------------------------------------
  446. # Daily Backup
  447. else
  448. echo Daily Backup of Databases \( $DBNAMES \)
  449. echo
  450. echo Rotating last weeks Backup...
  451. eval rm -fv "$BACKUPDIR/daily/*.$DOW.sql.*"
  452. echo
  453. dbdump "$DBNAMES" "$BACKUPDIR/daily/$DATE.$DOW.sql"
  454. compression "$BACKUPDIR/daily/$DATE.$DOW.sql"
  455. BACKUPFILES="$BACKUPFILES $BACKUPDIR/daily/$DATE.$DOW.sql$SUFFIX"
  456. echo ----------------------------------------------------------------------
  457. fi
  458. echo Backup End Time `date`
  459. echo ======================================================================
  460. fi
  461. echo Total disk space used for backup storage..
  462. echo Size - Location
  463. echo `du -hs "$BACKUPDIR"`
  464. echo
  465. # Run command when we're done
  466. if [ "$POSTBACKUP" ]
  467. then
  468. echo ======================================================================
  469. echo "Postbackup command output."
  470. echo
  471. eval $POSTBACKUP
  472. echo
  473. echo ======================================================================
  474. fi
  475. #Clean up IO redirection
  476. exec 1>&6 6>&- # Restore stdout and close file descriptor #6.
  477. exec 1>&7 7>&- # Restore stdout and close file descriptor #7.
  478. if [ "$MAILCONTENT" = "files" ]
  479. then
  480. if [ -s "$LOGERR" ]
  481. then
  482. # Include error log if is larger than zero.
  483. BACKUPFILES="$BACKUPFILES $LOGERR"
  484. ERRORNOTE="WARNING: Error Reported - "
  485. fi
  486. #Get backup size
  487. ATTSIZE=`du -c $BACKUPFILES | grep "[[:digit:][:space:]]total$" |sed s/\s*total//`
  488. if [ $MAXATTSIZE -ge $ATTSIZE ]
  489. then
  490. BACKUPFILES=`echo "$BACKUPFILES" | sed -e "s# # -a #g"` #enable multiple attachments
  491. mutt -s "PostgreSQL Backup Log and SQL Files for $HOST - $DATE" $BACKUPFILES $MAILADDR < $LOGFILE #send via mutt
  492. else
  493. cat "$LOGFILE" | mail -s "WARNING! - PostgreSQL Backup exceeds set maximum attachment size on $HOST - $DATE" $MAILADDR
  494. fi
  495. elif [ "$MAILCONTENT" = "log" ]
  496. then
  497. cat "$LOGFILE" | mail -s "PostgreSQL Backup Log for $HOST - $DATE" $MAILADDR
  498. if [ -s "$LOGERR" ]
  499. then
  500. cat "$LOGERR" | mail -s "ERRORS REPORTED: PostgreSQL Backup error Log for $HOST - $DATE" $MAILADDR
  501. fi
  502. elif [ "$MAILCONTENT" = "quiet" ]
  503. then
  504. if [ -s "$LOGERR" ]
  505. then
  506. cat "$LOGERR" | mail -s "ERRORS REPORTED: PostgreSQL Backup error Log for $HOST - $DATE" $MAILADDR
  507. cat "$LOGFILE" | mail -s "PostgreSQL Backup Log for $HOST - $DATE" $MAILADDR
  508. fi
  509. else
  510. if [ -s "$LOGERR" ]
  511. then
  512. cat "$LOGFILE"
  513. echo
  514. echo "###### WARNING ######"
  515. echo "Errors reported during AutoPostgreSQLBackup execution.. Backup failed"
  516. echo "Error log below.."
  517. cat "$LOGERR"
  518. else
  519. cat "$LOGFILE"
  520. fi
  521. fi
  522. if [ -s "$LOGERR" ]
  523. then
  524. STATUS=1
  525. else
  526. STATUS=0
  527. fi
  528. # Clean up Logfile
  529. eval rm -f "$LOGFILE"
  530. eval rm -f "$LOGERR"
  531. exit $STATUS