debian/0000755000000000000000000000000012233226613007166 5ustar debian/watch0000644000000000000000000000010711570143442010216 0ustar version=3 http://sf.net/autopgsqlbackup/autopostgresqlbackup\.sh\.(.+) debian/control0000644000000000000000000000162612220344605010574 0ustar Source: autopostgresqlbackup Section: admin Priority: extra Maintainer: Emmanuel Bouthenot Build-Depends: debhelper (>= 7.0.50~), perl Standards-Version: 3.9.4 Homepage: http://projects.frozenpc.net/autopgsqlbackup/ Vcs-Git: git://anonscm.debian.org/users/kolter/autopostgresqlbackup.git Vcs-Browser: http://anonscm.debian.org/gitweb/?p=users/kolter/autopostgresqlbackup.git Package: autopostgresqlbackup Architecture: all Recommends: mutt Depends: ${misc:Depends}, postgresql-client-common Description: Automated tool to make periodic backups of PostgreSQL databases autopostgresqlbackup is a shell script (usually executed from a cron job) designed to provide a fully automated tool to make periodic backups of PostgreSQL databases. autopostgresqlbackup extract databases into flat files in a daily, weekly or monthly basis. . autopostgresqlbackup is a PostgreSQL port of automysqlbackup. debian/default0000644000000000000000000000554112232725117010544 0ustar # =============================== # === Debian specific options === #================================ # By default, on Debian systems, only 'postgres' user # is allowed to access PostgreSQL databases without password. # In order to dump databases we need to run pg_dump/psql # commands as 'postgres' with su. # # The following setting has been added to workraound this issue. # (if it is set to empty, 'su' usage will be disabled) SU_USERNAME=postgres #===================================================================== # Set the following variables to your system needs # (Detailed instructions below variables) #===================================================================== # Username to access the PostgreSQL server e.g. dbuser USERNAME=postgres # Password # create a file $HOME/.pgpass containing a line like this # hostname:*:*:dbuser:dbpass # replace hostname with the value of DBHOST and postgres with # the value of USERNAME # Host name (or IP address) of PostgreSQL server e.g localhost DBHOST=localhost # List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3" DBNAMES="all" # pseudo database name used to dump global objects (users, roles, tablespaces) GLOBALS_OBJECTS="postgres_globals" # Backup directory location e.g /backups BACKUPDIR="/var/lib/autopostgresqlbackup" # Mail setup # What would you like to be mailed to you? # - log : send only log file # - files : send log file and sql files as attachments (see docs) # - stdout : will simply output the log to the screen if run manually. # - quiet : Only send logs if an error occurs to the MAILADDR. MAILCONTENT="quiet" # Set the maximum allowed email size in k. (4000 = approx 5MB email [see docs]) MAXATTSIZE="4000" # Email Address to send mail to? (user@domain.com) MAILADDR="root" # ============================================================ # === ADVANCED OPTIONS ( Read the doc's below for details )=== #============================================================= # List of DBBNAMES for Monthly Backups. MDBNAMES="template1 $DBNAMES" # List of DBNAMES to EXLUCDE if DBNAMES are set to all (must be in " quotes) DBEXCLUDE="" # Include CREATE DATABASE in backup? CREATE_DATABASE=yes # Separate backup directory and file for each DB? (yes or no) SEPDIR=yes # Which day do you want weekly backups? (1 to 7 where 1 is Monday) DOWEEKLY=6 # Choose Compression type. (gzip or bzip2) COMP=gzip # Compress communications between backup server and PostgreSQL server? # set compression level from 0 to 9 (0 means no compression) COMMCOMP=0 # Additionally keep a copy of the most recent backup in a seperate directory. LATEST=no # OPT string for use with pg_dump ( see man pg_dump ) OPT="" # Backup files extension EXT="sql" # Command to run before backups (uncomment to use) #PREBACKUP="/etc/postgresql-backup-pre" # Command run after backups (uncomment to use) #POSTBACKUP="/etc/postgresql-backup-post" debian/source/0000755000000000000000000000000011570224760010472 5ustar debian/source/format0000644000000000000000000000001411570142371011675 0ustar 3.0 (quilt) debian/install0000644000000000000000000000003711570137230010556 0ustar autopostgresqlbackup /usr/sbin debian/changelog0000644000000000000000000000306412233226315011042 0ustar autopostgresqlbackup (1.0-4) unstable; urgency=low * Add a patch to add additional parameters to pg_dump from default file using $OPT variable. Thanks to Mathias Behrle for the suggestion. (Closes: #726628) * Add a patch to make possible configure the extension of backup files. Thanks to Mathias Behrle for the suggestion. (Closes: #726630) -- Emmanuel Bouthenot Sun, 27 Oct 2013 15:09:04 +0000 autopostgresqlbackup (1.0-3) unstable; urgency=low * Fix Vcs-Browser field. Thanks to Axel Beckert for the notice (Closes: #721613) * Add a patch to fix a bug while restoring STDERR file descriptor. Thanks to Cyprien Devillez for the patch (Closes: #711983) * Add a fix to not use a login shell while invoking su. Thanks to Axel Beckert for the patch (Closes: #706087) * Add a patch to fix a crash while using option SEPDIR=no * Add a patch to also backup "globals" like users, roles, tablespaces, etc. (Closes: #706088) * Fix typo in manpage (Thanks to Vitaliyi) * Bump Standards-Version to 3.9.4 -- Emmanuel Bouthenot Tue, 24 Sep 2013 17:20:15 +0000 autopostgresqlbackup (1.0-2) unstable; urgency=high * Add a patch to fix possible code injection via unsafe database names inside eval. Thanks to Axel Beckert for the patch (Closes: #706095) -- Emmanuel Bouthenot Wed, 24 Apr 2013 22:13:10 +0000 autopostgresqlbackup (1.0-1) unstable; urgency=low * Initial release (Closes: #628400). -- Emmanuel Bouthenot Sat, 28 May 2011 11:21:49 +0200 debian/copyright0000644000000000000000000000250111570237347011130 0ustar Format: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=174 Upstream-Name: autopostgresqlbackup Upstream-Contact: Aaron Axelsen Source: http://sourceforge.net/projects/autopgsqlbackup/ Files: * Copyright: 2002-2005, wipe_out@lycos.co.uk 2005, Friedrich Lobenstock 2005, Aaron Axelsen License: GPL-2+ Files: debian/* Copyright: 2011, Emmanuel Bouthenot License: GPL-2+ License: GPL-2+ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. . This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. . You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. . On Debian systems, the complete text of the GNU General Public License, Version 2 can be found in the file /usr/share/common-licenses/GPL-2 debian/patches/0000755000000000000000000000000012231235651010615 5ustar debian/patches/01_sync_latest_automysqlbackup0000644000000000000000000003102712220121575016674 0ustar Description: Sync with latest automysqlbackup release Author: Emmanuel Bouthenot Forwarded: no Last-Update: 2011-05-28 --- a/autopostgresqlbackup +++ b/autopostgresqlbackup @@ -45,21 +45,21 @@ DBNAMES="all" # Backup directory location e.g /backups -BACKUPDIR="/home/backups/pgsql_backups" +BACKUPDIR="/backups" # Mail setup # What would you like to be mailed to you? # - log : send only log file # - files : send log file and sql files as attachments (see docs) # - stdout : will simply output the log to the screen if run manually. -MAILCONTENT="log" +# - quiet : Only send logs if an error occurs to the MAILADDR. +MAILCONTENT="stdout" # Set the maximum allowed email size in k. (4000 = approx 5MB email [see docs]) MAXATTSIZE="4000" # Email Address to send mail to? (user@domain.com) -MAILADDR="root@localhost" - +MAILADDR="user@domain.com" # ============================================================ # === ADVANCED OPTIONS ( Read the doc's below for details )=== @@ -83,12 +83,18 @@ # Choose Compression type. (gzip or bzip2) COMP=gzip +# Compress communications between backup server and PostgreSQL server? +# set compression level from 0 to 9 (0 means no compression) +COMMCOMP=0 + +# Additionally keep a copy of the most recent backup in a seperate directory. +LATEST=no + # Command to run before backups (uncomment to use) -#PREBACKUP="/etc/pgsql-backup-pre" +#PREBACKUP="/etc/postgresql-backup-pre" # Command run after backups (uncomment to use) -POSTBACKUP="bash /home/backups/scripts/ftp_pgsql" - +#POSTBACKUP="/etc/postgresql-backup-post" #===================================================================== # Options documentation @@ -117,21 +123,22 @@ # email addresses in a space seperated list. # (If you set mail content to "log" you will require access to the "mail" program # on your server. If you set this to "files" you will have to have mutt installed -# on your server. If you set it sto stdout it will log to the screen if run from -# the console or to the cron job owner if run through cron) +# on your server. If you set it to "stdout" it will log to the screen if run from +# the console or to the cron job owner if run through cron. If you set it to "quiet" +# logs will only be mailed if there are errors reported. ) # # MAXATTSIZE sets the largest allowed email attachments total (all backup files) you # want the script to send. This is the size before it is encoded to be sent as an email # so if your mail server will allow a maximum mail size of 5MB I would suggest setting # MAXATTSIZE to be 25% smaller than that so a setting of 4000 would probably be fine. # -# Finally copy automysqlbackup.sh to anywhere on your server and make sure +# Finally copy autopostgresqlbackup.sh to anywhere on your server and make sure # to set executable permission. You can also copy the script to # /etc/cron.daily to have it execute automatically every night or simply # place a symlink in /etc/cron.daily to the file if you wish to keep it # somwhere else. # NOTE:On Debian copy the file with no extention for it to be run -# by cron e.g just name the file "automysqlbackup" +# by cron e.g just name the file "autopostgresqlbackup" # # Thats it.. # @@ -139,10 +146,8 @@ # === Advanced options doc's === # # The list of MDBNAMES is the DB's to be backed up only monthly. You should -# always include "mysql" in this list to backup your user/password -# information along with any other DBs that you only feel need to -# be backed up monthly. (if using a hosted server then you should -# probably remove "mysql" as your provider will be backing this up) +# always include "template1" in this list to backup the default database +# template used to create new databases. # NOTE: If DBNAMES="all" then MDBNAMES has no effect as all DBs will be backed # up anyway. # @@ -155,7 +160,7 @@ # a database with the same name as the original database when restoring. # Saying "no" here will allow your to specify the database name you want to # restore your dump into, making a copy of the database by using the dump -# created with automysqlbackup. +# created with autopostgresqlbackup. # NOTE: Not used if SEPDIR=no # # The SEPDIR option allows you to choose to have all DBs backed up to @@ -171,6 +176,13 @@ # bzip2 will produce slightly smaller files but is more processor intensive so # may take longer to complete. # +# COMMCOMP is used to set the compression level (from 0 to 9, 0 means no compression) +# between the client and the server, so it is useful to save bandwidth when backing up +# a remote PostgresSQL server over the network. +# +# LATEST is to store an additional copy of the latest backup to a standard +# location so it can be downloaded bt thrid party scripts. +# # Use PREBACKUP and POSTBACKUP to specify Per and Post backup commands # or scripts to perform tasks either before or after the backup process. # @@ -201,6 +213,23 @@ # Happy backing up... # #===================================================================== +# Restoring +#===================================================================== +# Firstly you will need to uncompress the backup file. +# eg. +# gunzip file.gz (or bunzip2 file.bz2) +# +# Next you will need to use the postgresql client to restore the DB from the +# sql file. +# eg. +# psql --host dbserver --dbname database < /path/file.sql +# +# NOTE: Make sure you use "<" and not ">" in the above command because +# you are piping the file.sql to psql and not the other way around. +# +# Lets hope you never have to use this.. :) +# +#===================================================================== # Change Log #===================================================================== # @@ -209,22 +238,31 @@ # #===================================================================== #===================================================================== +#===================================================================== # # Should not need to be modified from here down!! # #===================================================================== #===================================================================== +#===================================================================== PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/postgres/bin:/usr/local/pgsql/bin -DATE=`date +%Y-%m-%d` # Datestamp e.g 2002-09-21 +DATE=`date +%Y-%m-%d_%Hh%Mm` # Datestamp e.g 2002-09-21 DOW=`date +%A` # Day of the week e.g. Monday DNOW=`date +%u` # Day number of the week 1 to 7 where 1 represents Monday DOM=`date +%d` # Date of the Month e.g. 27 M=`date +%B` # Month e.g January W=`date +%V` # Week Number e.g 37 -VER=1.0 # Version Number -LOGFILE=$BACKUPDIR/$DBHOST-`date +%N`.log # Logfile Name -OPT="" # OPT string for use with mysqldump ( see man mysqldump ) -BACKUPFILES="" # thh: added for later mailing +VER=1.0 # Version Number +LOGFILE=$BACKUPDIR/$DBHOST-`date +%N`.log # Logfile Name +LOGERR=$BACKUPDIR/ERRORS_$DBHOST-`date +%N`.log # Logfile Name +BACKUPFILES="" +OPT="" # OPT string for use with pg_dump ( see man pg_dump ) + +# Add --compress pg_dump option to $OPT +if [ "$COMMCOMP" -gt 0 ]; + then + OPT="$OPT --compress=$COMMCOMP" +fi # Create required directories if [ ! -e "$BACKUPDIR" ] # Check Backup Directory exists. @@ -247,23 +285,37 @@ mkdir -p "$BACKUPDIR/monthly" fi +if [ "$LATEST" = "yes" ] +then + if [ ! -e "$BACKUPDIR/latest" ] # Check Latest Directory exists. + then + mkdir -p "$BACKUPDIR/latest" + fi +eval rm -f "$BACKUPDIR/latest/*" +fi # IO redirection for logging. touch $LOGFILE exec 6>&1 # Link file descriptor #6 with stdout. # Saves stdout. exec > $LOGFILE # stdout replaced with file $LOGFILE. +touch $LOGERR +exec 7>&2 # Link file descriptor #7 with stderr. + # Saves stderr. +exec 2> $LOGERR # stderr replaced with file $LOGERR. # Functions # Database dump function dbdump () { -pg_dump --username=$USERNAME $HOST $OPT $1 > $2 -return 0 + touch $2 + chmod 600 $2 + pg_dump --username=$USERNAME $PGHOST $OPT $1 > $2 + return 0 } -# Compression function +# Compression function plus latest copy SUFFIX="" compression () { if [ "$COMP" = "gzip" ]; then @@ -279,6 +331,9 @@ else echo "No compression option set, check advanced settings" fi +if [ "$LATEST" = "yes" ]; then + cp $1$SUFFIX "$BACKUPDIR/latest/" +fi return 0 } @@ -308,15 +363,16 @@ # Hostname for LOG information if [ "$DBHOST" = "localhost" ]; then - DBHOST="`hostname -f`" - HOST="" + HOST=`hostname` + PGHOST="" else - HOST="-h $DBHOST" + HOST=$DBHOST + PGHOST="-h $DBHOST" fi # If backing up all DBs on the server if [ "$DBNAMES" = "all" ]; then - DBNAMES="`psql -U $USERNAME $HOST -l -A -F: | sed -ne "/:/ { /Name:Owner/d; /template0/d; s/:.*$//; p }"`" + DBNAMES="`psql -U $USERNAME $PGHOST -l -A -F: | sed -ne "/:/ { /Name:Owner/d; /template0/d; s/:.*$//; p }"`" # If DBs are excluded for exclude in $DBEXCLUDE @@ -331,7 +387,7 @@ echo AutoPostgreSQLBackup VER $VER echo http://autopgsqlbackup.frozenpc.net/ echo -echo Backup of Database Server - $DBHOST +echo Backup of Database Server - $HOST echo ====================================================================== # Test is seperate DB backups are required @@ -339,7 +395,7 @@ echo Backup Start Time `date` echo ====================================================================== # Monthly Full Backup of all Databases - if [ $DOM = "01" ]; then + if [ "$DOM" = "01" ]; then for MDB in $MDBNAMES do @@ -375,7 +431,7 @@ fi # Weekly Backup - if [ $DNOW = $DOWEEKLY ]; then + if [ "$DNOW" = "$DOWEEKLY" ]; then echo Weekly Backup of Database \( $DB \) echo Rotating 5 weeks Backups... if [ "$W" -le 05 ];then @@ -385,7 +441,7 @@ else REMW=`expr $W - 5` fi - eval rm -fv "$BACKUPDIR/weekly/$DB/week.$REMW.*" + eval rm -fv "$BACKUPDIR/weekly/$DB/${DB}_week.$REMW.*" echo dbdump "$DB" "$BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.sql" compression "$BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.sql" @@ -412,7 +468,7 @@ echo Backup Start `date` echo ====================================================================== # Monthly Full Backup of all Databases - if [ $DOM = "01" ]; then + if [ "$DOM" = "01" ]; then echo Monthly full Backup of \( $MDBNAMES \)... dbdump "$MDBNAMES" "$BACKUPDIR/monthly/$DATE.$M.all-databases.sql" compression "$BACKUPDIR/monthly/$DATE.$M.all-databases.sql" @@ -421,7 +477,7 @@ fi # Weekly Backup - if [ $DNOW = $DOWEEKLY ]; then + if [ "$DNOW" = "$DOWEEKLY" ]; then echo Weekly Backup of Databases \( $DBNAMES \) echo echo Rotating 5 weeks Backups... @@ -473,26 +529,62 @@ #Clean up IO redirection exec 1>&6 6>&- # Restore stdout and close file descriptor #6. +exec 1>&7 7>&- # Restore stdout and close file descriptor #7. if [ "$MAILCONTENT" = "files" ] then + if [ -s "$LOGERR" ] + then + # Include error log if is larger than zero. + BACKUPFILES="$BACKUPFILES $LOGERR" + ERRORNOTE="WARNING: Error Reported - " + fi #Get backup size ATTSIZE=`du -c $BACKUPFILES | grep "[[:digit:][:space:]]total$" |sed s/\s*total//` if [ $MAXATTSIZE -ge $ATTSIZE ] then BACKUPFILES=`echo "$BACKUPFILES" | sed -e "s# # -a #g"` #enable multiple attachments - mutt -s "PostgreSQL Backup Log and SQL Files for $DBHOST - $DATE" $BACKUPFILES $MAILADDR < $LOGFILE #send via mutt + mutt -s "PostgreSQL Backup Log and SQL Files for $HOST - $DATE" $BACKUPFILES $MAILADDR < $LOGFILE #send via mutt else cat "$LOGFILE" | mail -s "WARNING! - PostgreSQL Backup exceeds set maximum attachment size on $HOST - $DATE" $MAILADDR fi elif [ "$MAILCONTENT" = "log" ] then - cat "$LOGFILE" | mail -s "PostgreSQL Backup Log for $DBHOST - $DATE" $MAILADDR + 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 +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 else - cat "$LOGFILE" + if [ -s "$LOGERR" ] + then + cat "$LOGFILE" + echo + echo "###### WARNING ######" + echo "Errors reported during AutoPostgreSQLBackup execution.. Backup failed" + echo "Error log below.." + cat "$LOGERR" + else + cat "$LOGFILE" + fi +fi + +if [ -s "$LOGERR" ] + then + STATUS=1 + else + STATUS=0 fi # Clean up Logfile eval rm -f "$LOGFILE" +eval rm -f "$LOGERR" -exit 0 +exit $STATUS debian/patches/10_fix_code_injection0000644000000000000000000000437412231232101014655 0ustar Description: Fix code injection via unsafe database names inside eval Author: Axel Beckert Bug-Debian: http://bugs.debian.org/706095 Last-Update: 2013-04-24 --- a/autopostgresqlbackup +++ b/autopostgresqlbackup @@ -301,7 +301,7 @@ then mkdir -p "$BACKUPDIR/latest" fi -eval rm -f "$BACKUPDIR/latest/*" +rm -f "$BACKUPDIR"/latest/* fi # IO redirection for logging. @@ -358,7 +358,7 @@ echo ====================================================================== echo "Prebackup command output." echo - eval $PREBACKUP + $PREBACKUP echo echo ====================================================================== echo @@ -459,7 +459,7 @@ else REMW=`expr $W - 5` fi - eval rm -fv "$BACKUPDIR/weekly/$DB/${DB}_week.$REMW.*" + rm -fv "$BACKUPDIR/weekly/$DB/${DB}_week.$REMW".* echo dbdump "$DB" "$BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.sql" compression "$BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.sql" @@ -470,7 +470,7 @@ else echo Daily Backup of Database \( $DB \) echo Rotating last weeks Backup... - eval rm -fv "$BACKUPDIR/daily/$DB/*.$DOW.sql.*" + rm -fv "$BACKUPDIR/daily/$DB"/*."$DOW".sql.* echo dbdump "$DB" "$BACKUPDIR/daily/$DB/${DB}_$DATE.$DOW.sql" compression "$BACKUPDIR/daily/$DB/${DB}_$DATE.$DOW.sql" @@ -506,7 +506,7 @@ else REMW=`expr $W - 5` fi - eval rm -fv "$BACKUPDIR/weekly/week.$REMW.*" + rm -fv "$BACKUPDIR/weekly/week.$REMW".* echo dbdump "$DBNAMES" "$BACKUPDIR/weekly/week.$W.$DATE.sql" compression "$BACKUPDIR/weekly/week.$W.$DATE.sql" @@ -518,7 +518,7 @@ echo Daily Backup of Databases \( $DBNAMES \) echo echo Rotating last weeks Backup... - eval rm -fv "$BACKUPDIR/daily/*.$DOW.sql.*" + rm -fv "$BACKUPDIR"/daily/*."$DOW".sql.* echo dbdump "$DBNAMES" "$BACKUPDIR/daily/$DATE.$DOW.sql" compression "$BACKUPDIR/daily/$DATE.$DOW.sql" @@ -540,7 +540,7 @@ echo ====================================================================== echo "Postbackup command output." echo - eval $POSTBACKUP + $POSTBACKUP echo echo ====================================================================== fi @@ -602,7 +602,7 @@ fi # Clean up Logfile -eval rm -f "$LOGFILE" -eval rm -f "$LOGERR" +rm -f "$LOGFILE" +rm -f "$LOGERR" exit $STATUS debian/patches/series0000644000000000000000000000025612231233373012034 0ustar 01_sync_latest_automysqlbackup 05_debian_specifics 10_fix_code_injection 11_fix_stderr_fd 12_fix_crash_backup_single_file 13_include_global_objects 14_backup_files_extension debian/patches/12_fix_crash_backup_single_file0000644000000000000000000000170112231232142016664 0ustar Description: Fix crash while using option SEPDIR=no Author: Emmanuel Bouthenot Last-Update: 2013-09-20 --- This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ --- a/autopostgresqlbackup +++ b/autopostgresqlbackup @@ -319,13 +319,16 @@ # Database dump function dbdump () { + rm -f $2 touch $2 chmod 600 $2 - if [ -n "$SU_USERNAME" ]; then - su $SU_USERNAME -c "pg_dump $PGHOST $OPT $1" > $2 - else - pg_dump --username=$USERNAME $PGHOST $OPT $1 > $2 - fi + for db in $1 ; do + if [ -n "$SU_USERNAME" ]; then + su $SU_USERNAME -c "pg_dump $PGHOST $OPT $db" >> $2 + else + pg_dump --username=$USERNAME $PGHOST $OPT $db >> $2 + fi + done return 0 } @@ -397,8 +400,8 @@ do DBNAMES=`echo $DBNAMES | sed "s/\b$exclude\b//g"` done - - MDBNAMES=$DBNAMES + DBNAMES="$(echo $DBNAMES| tr '\n' ' ')" + MDBNAMES=$DBNAMES fi echo ====================================================================== debian/patches/13_include_global_objects0000644000000000000000000000304312231232150015506 0ustar Description: Patch to also backup "globals" like users, roles, tablespaces, etc Author: Emmanuel Bouthenot Bug-Debian: http://bugs.debian.org/706088 Last-Update: 2013-09-22 --- This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ --- a/autopostgresqlbackup +++ b/autopostgresqlbackup @@ -44,6 +44,9 @@ # List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3" DBNAMES="all" +# pseudo database name used to dump global objects (users, roles, tablespaces) +GLOBALS_OBJECTS="postgres_globals" + # Backup directory location e.g /backups BACKUPDIR="/backups" @@ -324,9 +327,17 @@ chmod 600 $2 for db in $1 ; do if [ -n "$SU_USERNAME" ]; then - su $SU_USERNAME -c "pg_dump $PGHOST $OPT $db" >> $2 + if [ "$db" = "$GLOBALS_OBJECTS" ]; then + su $SU_USERNAME -c "pg_dumpall $PGHOST --globals-only" >> $2 + else + su $SU_USERNAME -c "pg_dump $PGHOST $OPT $db" >> $2 + fi else - pg_dump --username=$USERNAME $PGHOST $OPT $db >> $2 + if [ "$db" = "$GLOBALS_OBJECTS" ]; then + pg_dumpall --username=$USERNAME $PGHOST --globals-only >> $2 + else + pg_dump --username=$USERNAME $PGHOST $OPT $db >> $2 + fi fi done return 0 @@ -403,7 +414,11 @@ DBNAMES="$(echo $DBNAMES| tr '\n' ' ')" MDBNAMES=$DBNAMES fi - + +# Include global objects (users, tablespaces) +DBNAMES="$GLOBALS_OBJECTS $DBNAMES" +MDBNAMES="$GLOBALS_OBJECTS $MDBNAMES" + echo ====================================================================== echo AutoPostgreSQLBackup VER $VER echo http://autopgsqlbackup.frozenpc.net/ debian/patches/11_fix_stderr_fd0000644000000000000000000000112712231232131013652 0ustar Description: Fix a bug while restoring STDERR file descriptor Author: Cyprien Devillez Bug-Debian: http://bugs.debian.org/711983 Last-Update: 2013-09-18 --- This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ --- a/autopostgresqlbackup +++ b/autopostgresqlbackup @@ -547,7 +547,7 @@ #Clean up IO redirection exec 1>&6 6>&- # Restore stdout and close file descriptor #6. -exec 1>&7 7>&- # Restore stdout and close file descriptor #7. +exec 2>&7 7>&- # Restore stdout and close file descriptor #7. if [ "$MAILCONTENT" = "files" ] then debian/patches/05_debian_specifics0000644000000000000000000000410612231232062014310 0ustar Description: Add Debian specific changes (use of /etc/defaults/autopostgresqlbackup and su) Author: Emmanuel Bouthenot Forwarded: not-needed Last-Update: 2011-05-28 --- a/autopostgresqlbackup +++ b/autopostgresqlbackup @@ -90,12 +90,23 @@ # Additionally keep a copy of the most recent backup in a seperate directory. LATEST=no +# OPT string for use with pg_dump ( see man pg_dump ) +OPT="" + # Command to run before backups (uncomment to use) #PREBACKUP="/etc/postgresql-backup-pre" # Command run after backups (uncomment to use) #POSTBACKUP="/etc/postgresql-backup-post" +# =============================== +# === Debian specific options === +#================================ + +if [ -f /etc/default/autopostgresqlbackup ]; then + . /etc/default/autopostgresqlbackup +fi + #===================================================================== # Options documentation #===================================================================== @@ -256,7 +267,6 @@ LOGFILE=$BACKUPDIR/$DBHOST-`date +%N`.log # Logfile Name LOGERR=$BACKUPDIR/ERRORS_$DBHOST-`date +%N`.log # Logfile Name BACKUPFILES="" -OPT="" # OPT string for use with pg_dump ( see man pg_dump ) # Add --compress pg_dump option to $OPT if [ "$COMMCOMP" -gt 0 ]; @@ -311,7 +321,11 @@ dbdump () { touch $2 chmod 600 $2 - pg_dump --username=$USERNAME $PGHOST $OPT $1 > $2 + if [ -n "$SU_USERNAME" ]; then + su $SU_USERNAME -c "pg_dump $PGHOST $OPT $1" > $2 + else + pg_dump --username=$USERNAME $PGHOST $OPT $1 > $2 + fi return 0 } @@ -372,7 +386,11 @@ # If backing up all DBs on the server if [ "$DBNAMES" = "all" ]; then - DBNAMES="`psql -U $USERNAME $PGHOST -l -A -F: | sed -ne "/:/ { /Name:Owner/d; /template0/d; s/:.*$//; p }"`" + if [ -n "$SU_USERNAME" ]; then + DBNAMES="$(su $SU_USERNAME -c "LANG=C psql -U $USERNAME $PGHOST -l -A -F: | sed -ne '/:/ { /Name:Owner/d; /template0/d; s/:.*$//; p }'")" + else + DBNAMES="`LANG=C psql -U $USERNAME $PGHOST -l -A -F: | sed -ne "/:/ { /Name:Owner/d; /template0/d; s/:.*$//; p }"`" + fi # If DBs are excluded for exclude in $DBEXCLUDE debian/patches/14_backup_files_extension0000644000000000000000000001045612231235651015575 0ustar Description: Make possible configure the extension of backup files Author: Emmanuel Bouthenot Bug-Debian: http://bugs.debian.org/726630 Forwarded: no Last-Update: 2013-10-21 --- This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ --- a/autopostgresqlbackup +++ b/autopostgresqlbackup @@ -96,6 +96,9 @@ # OPT string for use with pg_dump ( see man pg_dump ) OPT="" +# Backup files extension +EXT="sql" + # Command to run before backups (uncomment to use) #PREBACKUP="/etc/postgresql-backup-pre" @@ -443,9 +446,9 @@ mkdir -p "$BACKUPDIR/monthly/$MDB" fi echo Monthly Backup of $MDB... - dbdump "$MDB" "$BACKUPDIR/monthly/$MDB/${MDB}_$DATE.$M.$MDB.sql" - compression "$BACKUPDIR/monthly/$MDB/${MDB}_$DATE.$M.$MDB.sql" - BACKUPFILES="$BACKUPFILES $BACKUPDIR/monthly/$MDB/${MDB}_$DATE.$M.$MDB.sql$SUFFIX" + 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 ---------------------------------------------------------------------- done fi @@ -479,20 +482,20 @@ fi rm -fv "$BACKUPDIR/weekly/$DB/${DB}_week.$REMW".* echo - dbdump "$DB" "$BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.sql" - compression "$BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.sql" - BACKUPFILES="$BACKUPFILES $BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.sql$SUFFIX" + 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".sql.* + rm -fv "$BACKUPDIR/daily/$DB"/*."$DOW".$EXT.* echo - dbdump "$DB" "$BACKUPDIR/daily/$DB/${DB}_$DATE.$DOW.sql" - compression "$BACKUPDIR/daily/$DB/${DB}_$DATE.$DOW.sql" - BACKUPFILES="$BACKUPFILES $BACKUPDIR/daily/$DB/${DB}_$DATE.$DOW.sql$SUFFIX" + 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 @@ -506,9 +509,9 @@ # Monthly Full Backup of all Databases if [ "$DOM" = "01" ]; then echo Monthly full Backup of \( $MDBNAMES \)... - dbdump "$MDBNAMES" "$BACKUPDIR/monthly/$DATE.$M.all-databases.sql" - compression "$BACKUPDIR/monthly/$DATE.$M.all-databases.sql" - BACKUPFILES="$BACKUPFILES $BACKUPDIR/monthly/$DATE.$M.all-databases.sql$SUFFIX" + 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 ---------------------------------------------------------------------- fi @@ -526,9 +529,9 @@ fi rm -fv "$BACKUPDIR/weekly/week.$REMW".* echo - dbdump "$DBNAMES" "$BACKUPDIR/weekly/week.$W.$DATE.sql" - compression "$BACKUPDIR/weekly/week.$W.$DATE.sql" - BACKUPFILES="$BACKUPFILES $BACKUPDIR/weekly/week.$W.$DATE.sql$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 ---------------------------------------------------------------------- # Daily Backup @@ -536,11 +539,11 @@ echo Daily Backup of Databases \( $DBNAMES \) echo echo Rotating last weeks Backup... - rm -fv "$BACKUPDIR"/daily/*."$DOW".sql.* + rm -fv "$BACKUPDIR"/daily/*."$DOW".$EXT.* echo - dbdump "$DBNAMES" "$BACKUPDIR/daily/$DATE.$DOW.sql" - compression "$BACKUPDIR/daily/$DATE.$DOW.sql" - BACKUPFILES="$BACKUPFILES $BACKUPDIR/daily/$DATE.$DOW.sql$SUFFIX" + dbdump "$DBNAMES" "$BACKUPDIR/daily/$DATE.$DOW.$EXT" + compression "$BACKUPDIR/daily/$DATE.$DOW.$EXT" + BACKUPFILES="$BACKUPFILES $BACKUPDIR/daily/$DATE.$DOW.$EXT$SUFFIX" echo ---------------------------------------------------------------------- fi echo Backup End Time `date` debian/dirs0000644000000000000000000000003611570142070010046 0ustar /var/lib/autopostgresqlbackup debian/manpages0000644000000000000000000000004211570137230010677 0ustar debian/man/autopostgresqlbackup.8 debian/cron.daily0000644000000000000000000000013611570141765011162 0ustar #!/bin/sh if [ -x /usr/sbin/autopostgresqlbackup ]; then /usr/sbin/autopostgresqlbackup fi debian/compat0000644000000000000000000000000211570137350010366 0ustar 7 debian/man/0000755000000000000000000000000012233221460007734 5ustar debian/man/autopostgresqlbackup.pod0000644000000000000000000000112112220344512014715 0ustar =head1 NAME autopostgresqlbackup - backup all of your PostgreSQL databases daily, weekly, and monthly =head1 SYNOPSIS autopostgresqlbackup =head1 DESCRIPTION autopostgresqlbackup is a shell script (usually executed from a cron job) designed to provide a fully automated tool to make periodic backups of PostgreSQL databases. On Debian systems, autopostgresqlbackup can be configured by editing some options in file /etc/default/autopostgresqlbackup. =head1 AUTHOR This manpage was written by Emmanuel Bouthenot for Debian GNU/Linux but may be used by others. =cut debian/rules0000755000000000000000000000044011570205762010251 0ustar #!/usr/bin/make -f override_dh_auto_build: pod2man \ --center "" --date "" --release "" \ --section=8 debian/man/autopostgresqlbackup.pod > debian/man/autopostgresqlbackup.8 dh_auto_build override_dh_auto_clean: rm -f debian/man/autopostgresqlbackup.8 dh_auto_clean %: dh $@