From a95af249f142f7feb253c34687cfc415a0614d41 Mon Sep 17 00:00:00 2001 From: Elijah Saxon Date: Tue, 26 Jul 2005 23:05:17 +0000 Subject: [PATCH 01/16] fixed bug where multiple 'when' options were ignored. --- backupninja | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backupninja b/backupninja index a1bfabc..aba997e 100755 --- a/backupninja +++ b/backupninja @@ -271,7 +271,7 @@ EOF function process_action() { local file="$1" local suffix="$2" - + local run="no" setfile $file # skip over this config if "when" option @@ -290,13 +290,14 @@ function process_action() { IFS=$'\t\n' if [ $ret == 0 ]; then debug "skipping $file because it is not $w" - return else info ">>>> starting action $file (because it is $w)" + run="yes" fi done IFS=$' \t\n' fi + [ "$run" == "no" ] && return let "actions_run += 1" -- 2.30.2 From 9d8adb4e8772f9c64801d4deca49d4178914fdc0 Mon Sep 17 00:00:00 2001 From: Elijah Saxon Date: Tue, 26 Jul 2005 23:15:12 +0000 Subject: [PATCH 02/16] --- changelog | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/changelog b/changelog index 8f408e9..1872cdd 100644 --- a/changelog +++ b/changelog @@ -1,9 +1,10 @@ -version 0.7 -- July 3 2005 +version 0.7 -- July 26 2005 added ninjahelper: a dialog based wizard for creating backupninja configs. considerably improved and changed the log file output. you can now disable actions with .disabled (this is new preferred method). - added makecd handler and example.makecd for backing up to cd/dvd - + added makecd handler and example.makecd for backing up to cd/dvd (thanks stef). + fixed bug when specifying multiple 'when' options. + version 0.6 -- June 16 2005 ldap handler has new options: backup method to use (ldapsearch or slapcat), restart, passwordfile and binddn. Default backup method @@ -34,7 +35,6 @@ version 0.6 -- June 16 2005 (.my.cnf files now have double quotes around password) can now pass options to hwinfo and sfdisk in sys handler. ->>>>>>> .r129 version 0.5 -- April 12 2005 rdiff handler works when remote sshd has a banner rdiff handler supports local dest -- 2.30.2 From 5fcde095badc217991da05af7d9b4098f0440f4e Mon Sep 17 00:00:00 2001 From: Elijah Saxon Date: Tue, 26 Jul 2005 23:21:04 +0000 Subject: [PATCH 03/16] --- changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog b/changelog index 1872cdd..e344db6 100644 --- a/changelog +++ b/changelog @@ -3,7 +3,7 @@ version 0.7 -- July 26 2005 considerably improved and changed the log file output. you can now disable actions with .disabled (this is new preferred method). added makecd handler and example.makecd for backing up to cd/dvd (thanks stef). - fixed bug when specifying multiple 'when' options. + fixed bug when specifying multiple 'when' options. version 0.6 -- June 16 2005 ldap handler has new options: backup method to use (ldapsearch or -- 2.30.2 From a37e9ccdb9453185765c59dafa808c47a098e75a Mon Sep 17 00:00:00 2001 From: Elijah Saxon Date: Wed, 27 Jul 2005 17:30:24 +0000 Subject: [PATCH 04/16] changed on to yes (on doesn't work!) --- handlers/sys.helper | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/handlers/sys.helper b/handlers/sys.helper index 93ae332..060e96c 100644 --- a/handlers/sys.helper +++ b/handlers/sys.helper @@ -8,14 +8,14 @@ sys_wizard() { "hardware" "detailed hardware information" on [ $? = 1 ] && return; result="$REPLY" - packages="packages = off" - partitions="partitions = off" - hardware="hardware = off" + packages="packages = no" + partitions="partitions = no" + hardware="hardware = no" for opt in $result; do case $opt in - '"packages"') packages="packages = on";; - '"partitions"') partitions="partitions = on";; - '"hardware"') hardware="hardware = on";; + '"packages"') packages="packages = yes";; + '"partitions"') partitions="partitions = yes";; + '"hardware"') hardware="hardware = yes";; esac done get_next_filename $configdirectory/10.sys -- 2.30.2 From b5120bcd7b12047e802a8067f2275f0d3d2ebeba Mon Sep 17 00:00:00 2001 From: Elijah Saxon Date: Wed, 27 Jul 2005 17:30:56 +0000 Subject: [PATCH 05/16] fixed when bug for real this time. --- backupninja | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backupninja b/backupninja index aba997e..7bd3541 100755 --- a/backupninja +++ b/backupninja @@ -279,8 +279,10 @@ function process_action() { getconf when "$defaultwhen" if [ "$processnow" == 1 ]; then info ">>>> starting action $file (because of --now)" + run="yes" elif [ "$when" == "hourly" ]; then info ">>>> starting action $file (because 'when = hourly')" + run="yes" else IFS=$'\t\n' for w in $when; do @@ -297,6 +299,7 @@ function process_action() { done IFS=$' \t\n' fi + debug $run [ "$run" == "no" ] && return let "actions_run += 1" -- 2.30.2 From 773c194279bb6e1ca91de76b82fe94c6e2ff624a Mon Sep 17 00:00:00 2001 From: intrigeri Date: Tue, 9 Aug 2005 20:28:52 +0000 Subject: [PATCH 06/16] Added pgsql (PostgreSQL) handler, with vservers support. --- README | 1 + backupninja | 2 + changelog | 4 ++ etc/backup.d/example.pgsql | 19 ++++++++ handlers/pgsql | 96 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 122 insertions(+) create mode 100644 etc/backup.d/example.pgsql create mode 100644 handlers/pgsql diff --git a/README b/README index e3977bc..9e2f2e6 100644 --- a/README +++ b/README @@ -62,6 +62,7 @@ file in /etc/backup.d according to the file's suffix: .dup -- filesystem backup (using duplicity) .mysql -- backup mysql databases .ldap -- backup ldap databases + .pgsql -- backup PostgreSQL databases .sys -- general hardware, partition, and system reports. .svn -- backup subversion repositories .maildir -- incrementally backup maildirs (very specialized) diff --git a/backupninja b/backupninja index 7bd3541..59361b3 100755 --- a/backupninja +++ b/backupninja @@ -438,6 +438,8 @@ getconf RDIFFBACKUP /usr/bin/rdiff-backup getconf MYSQL /usr/bin/mysql getconf MYSQLHOTCOPY /usr/bin/mysqlhotcopy getconf MYSQLDUMP /usr/bin/mysqldump +getconf PGSQLDUMP /usr/bin/pg_dump +getconf PGSQLDUMPALL /usr/bin/pg_dumpall getconf GZIP /bin/gzip getconf RSYNC /usr/bin/rsync getconf vservers no diff --git a/changelog b/changelog index e344db6..198009d 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,7 @@ +version XX -- ... + + added pgsql (PostgreSQL) handler, with vservers support + version 0.7 -- July 26 2005 added ninjahelper: a dialog based wizard for creating backupninja configs. considerably improved and changed the log file output. diff --git a/etc/backup.d/example.pgsql b/etc/backup.d/example.pgsql new file mode 100644 index 0000000..8313bd4 --- /dev/null +++ b/etc/backup.d/example.pgsql @@ -0,0 +1,19 @@ +### backupninja PostgreSQL config file ### + +# backupdir = (default: /var/backups/postgres) +# where to dump the backups +# +# databases = < all | db1 db2 db3 > (default = all) +# which databases to backup. should either be the word 'all' or a +# space separated list of database names. +# Note: when using 'all', pg_dumpall is used instead of pg_dump, which means +# that cluster-wide data (such as users and groups) are saved. +# +# compress = < yes | no > (default = yes) +# if yes, compress the pg_dump output. +# +# vsname = (no default) +# what vserver to operate on, only used if vserver = yes in /etc/backupninja.conf +# if you do not specify a vsname the host will be operated on +# Note: if operating on a vserver, $VROOTDIR will be prepended to backupdir. + diff --git a/handlers/pgsql b/handlers/pgsql new file mode 100644 index 0000000..8d8f0c7 --- /dev/null +++ b/handlers/pgsql @@ -0,0 +1,96 @@ +# +# PostgreSQL handler script for backupninja +# + +getconf backupdir /var/backups/postgres +getconf databases all +getconf compress yes +getconf vsname + +localhost=`hostname` + +# If vservers are configured, decide if the handler should +# use them or if it should just operate on the host + +if [ "$vservers" == "yes" ] + then + if [ ! -z $vsname ] + then + info "Using vserver '$vsname'" + usevserver=1 + else + info "No vserver name specified, actions will be performed on the host" + fi +fi + +# Check to make sure that the specified vserver exists +if [ $usevserver ] + then + vroot="$VROOTDIR/$vsname" + [ -d $vroot ] || fatal "vserver '$vsname' does not exist at '$vroot'" +fi + +# create backup dir, the vroot variable will be empty if no vsname was specified +# and will proceed to operate on the host +[ -d $vroot$backupdir ] || mkdir -p $vroot$backupdir +[ -d $vroot$backupdir ] || fatal "Backup directory '$vroot$backupdir'" + +# give backup dir the good uid and permissions +# (in respect to the vserver, if $usevserver) +pguid=`grep '^postgres:' $vroot/etc/passwd | awk -F: '{print $3}'` +debug "chown $pguid $vroot$backupdir" +chown $pguid $vroot$backupdir +debug "chmod 700 $vroot$backupdir" +chmod 700 $vroot$backupdir + +# if $databases = all, use pg_dumpall +if [ "$databases" == "all" ]; then + if [ $usevserver ]; then + execstr="$VSERVER $vsname exec su - postgres -c $PGSQLDUMPALL > $vroot$backupdir/${vsname}.sql" + else + execstr="su - postgres -c $PGSQLDUMPALL > $backupdir/${localhost}-all.sql" + fi + debug "$execstr" + if [ ! $test ]; then + output=`$execstr 2>&1` + code=$? + if [ "$code" == "0" ]; then + debug $output + info "Successfully finished dump of pgsql cluster" + else + warning $output + warning "Failed to dump pgsql cluster" + fi + fi + +# else use pg_dump on each specified database +else + for db in $databases; do + if [ $usevserver ] + then + execstr="$VSERVER $vsname exec su - postgres -c $PGSQLDUMP $db > $vroot$backupdir/${db}.sql" + else + execstr="su - postgres -c $PGSQLDUMP $db > $backupdir/${db}.sql" + fi + debug "$execstr" + if [ ! $test ]; then + output=`$execstr 2>&1` + code=$? + if [ "$code" == "0" ]; then + debug $output + info "Successfully finished dump of pgsql database ${db}" + else + warning $output + warning "Failed to dump pgsql database ${db}" + fi + fi + done +fi + +if [ "$compress" == "yes" ]; then + output=`$GZIP -f $vroot$backupdir/*.sql 2>&1` + debug $output +fi + +return 0 + -- 2.30.2 From d675fa6df95984eca8ecfc10e7ec00a34a0d2720 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Tue, 9 Aug 2005 20:41:37 +0000 Subject: [PATCH 07/16] Added vservers support to duplicity handler. --- changelog | 6 +++++- etc/backup.d/example.dup | 12 ++++++++++++ handlers/dup | 41 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/changelog b/changelog index 198009d..bb7a439 100644 --- a/changelog +++ b/changelog @@ -1,7 +1,11 @@ version XX -- ... added pgsql (PostgreSQL) handler, with vservers support - + added vservers support to duplicity handler + Note: the configuration is a bit different of rdiff + handler's one, but the default behavior is the same: have + a look to example.dup. + version 0.7 -- July 26 2005 added ninjahelper: a dialog based wizard for creating backupninja configs. considerably improved and changed the log file output. diff --git a/etc/backup.d/example.dup b/etc/backup.d/example.dup index 5dfd3a2..37ca92e 100644 --- a/etc/backup.d/example.dup +++ b/etc/backup.d/example.dup @@ -58,6 +58,18 @@ include = /usr/local/sbin include = /var/lib/dpkg/status include = /var/lib/dpkg/status-old +# If vservers = yes in /etc/backupninja.conf then the following variables can +# be used: +# vsnames = all | ... (default = all) +# vsinclude = +# Any path specified in vsinclude is added to the include list for each vserver +# listed in vsnames (or all if vsnames = all). +# E.g. vsinclude = /home will backup the /home partition in every vserver +# listed in vsnames. If you have vsnames = "foo bar baz", this vsinclude will +# add to the include list /vservers/foo/home, /vservers/bar/home and +# /vservers/baz/home. +# Vservers paths are derived from $VROOTDIR. + # rdiff-backup specific comment, TO ADAPT # files to exclude from the backup # (supports globbing with '*') diff --git a/handlers/dup b/handlers/dup index 55667f6..3b4d032 100644 --- a/handlers/dup +++ b/handlers/dup @@ -14,6 +14,8 @@ getconf encryptkey setsection source getconf include +getconf vsnames all +getconf vsinclude getconf exclude setsection dest @@ -29,7 +31,34 @@ destdir=${destdir%/} [ "$include" != "" ] || fatal "No source includes specified" [ "$password" != "" ] || fatal "No password specified" -# see if we can login +### vservers stuff ### + +# See if vservers are configured. +# If so, check that the ones listed in $vsnames do exist. +if [ "$vservers" == "yes" ]; then + [ -d "$VROOTDIR" ] || fatal "vservers enabled, but $VROOTDIR does not exist!" + if [ "$vsnames" == "all" ]; then + vsnames="" + for vserver in `ls $VROOTDIR | grep -v lost+found | grep -v ARCHIVES`; do + vsnames="$vserver $vsnames" + done + else + for vserver in "$vsnames"; do + [ -d "$VROOTDIR/$vserver" ] || fatal "vserver '$vserver' does not exist." + done + fi + if [ -n "$vsnames" ]; then + if [ -n "$vsinclude" ]; then + info "Using vservers '$vsnames'" + usevserver=1 + fi + else + [ -z "$vsinclude" ] || warning 'vsnames is empty, vsinclude configuration lines will be ignored' + fi +fi + +### see if we can login ### + if [ "$testconnect" == "yes" ]; then debug "ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'" if [ ! $test ]; then @@ -80,6 +109,16 @@ for i in $include; do execstr="${execstr}--include $str " done +# vsincludes +if [ $usevserver ]; then + for vserver in $vsnames; do + for vi in $vsinclude; do + str="${vi//__star__/*}" + execstr="${execstr}--include '$VROOTDIR/$vserver$str' " + done + done +fi + ### EXECUTE ### # exclude everything else, start with root -- 2.30.2 From f22dbec1dcad37d85b6ee8b556dc999c542bc3c0 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Tue, 9 Aug 2005 20:46:18 +0000 Subject: [PATCH 08/16] Improved README a bit. --- README | 8 +++++--- changelog | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README b/README index 9e2f2e6..849fe3a 100644 --- a/README +++ b/README @@ -80,8 +80,9 @@ For example: 90-runthislast.rdiff Typically, you will put a '.rdiff' config file last, so that any -database dumps you make are included in the filesystem backup. -Configurations files which begin with 0 (zero) are skipped. +database dumps you make are included in the filesystem backup. +Configurations files with names beginning with 0 (zero) or ending with +.disabled (preferred method) are skipped. Unless otherwise specified, the config file format is "ini style." @@ -205,6 +206,7 @@ Installation: # tar xvzf backupninja.tar.gz # cd backupninja # mv backupninja /usr/sbin/backupninja + # mv ninjahelper /usr/sbin/ninjahelper # mv etc/logrotate.d/backupninja /etc/logrotate.d/backupninja # mv etc/cron.d/backupninja /etc/cron.d/backupninja # mkdir /etc/backup.d/ @@ -226,7 +228,7 @@ probably don't need to be changed: VSERVERINFO (default: /usr/sbin/vserver-info) VSERVER (default: /usr/sbin/vserver) -VROOTDIR (default: `$VSERVERINFO info SYSINFO |grep vserver-Rootdir | awk '{print $2}'; fi`) +VROOTDIR (default: `$VSERVERINFO info SYSINFO |grep vserver-Rootdir | awk '{print $2}'`) NINJAHELPER =========== diff --git a/changelog b/changelog index bb7a439..96f4723 100644 --- a/changelog +++ b/changelog @@ -5,6 +5,10 @@ version XX -- ... Note: the configuration is a bit different of rdiff handler's one, but the default behavior is the same: have a look to example.dup. + improved README + documented .disabled method. + corrected VROOTDIR default value. + added ninjahelper to the install instructions. version 0.7 -- July 26 2005 added ninjahelper: a dialog based wizard for creating backupninja configs. -- 2.30.2 From 4e0c31d01627b9c01ff09841e1061f42750997f6 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Tue, 9 Aug 2005 20:50:05 +0000 Subject: [PATCH 09/16] Fixed/improved a few bits of rdiff, dup and sys handlers. --- changelog | 7 +++++++ handlers/dup | 2 +- handlers/rdiff | 2 +- handlers/sys | 14 +++++++------- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/changelog b/changelog index 96f4723..a37d6aa 100644 --- a/changelog +++ b/changelog @@ -9,6 +9,13 @@ version XX -- ... documented .disabled method. corrected VROOTDIR default value. added ninjahelper to the install instructions. + improved rdiff, dup and sys handlers' vservers support + prevent vserver-debiantools' $VROOTDIR/ARCHIVES directory + to be seen as a vserver + changes to sys handler + make use of configurable $VSERVERINFO instead of hard-coded vserver-info. + fixed dpkg existence test inside vserver. + fixed $nodpkg use. version 0.7 -- July 26 2005 added ninjahelper: a dialog based wizard for creating backupninja configs. diff --git a/handlers/dup b/handlers/dup index 3b4d032..7dfb766 100644 --- a/handlers/dup +++ b/handlers/dup @@ -39,7 +39,7 @@ if [ "$vservers" == "yes" ]; then [ -d "$VROOTDIR" ] || fatal "vservers enabled, but $VROOTDIR does not exist!" if [ "$vsnames" == "all" ]; then vsnames="" - for vserver in `ls $VROOTDIR | grep -v lost+found | grep -v ARCHIVES`; do + for vserver in `ls $VROOTDIR | grep -E -v "lost+found|ARCHIVES"`; do vsnames="$vserver $vsnames" done else diff --git a/handlers/rdiff b/handlers/rdiff index 7120e7a..10cb3c0 100644 --- a/handlers/rdiff +++ b/handlers/rdiff @@ -118,7 +118,7 @@ done # vsinclude if [ $usevserver ] then - for vserver in `ls $VROOTDIR|grep -v lost+found` + for vserver in `ls $VROOTDIR | grep -E -v "lost+found|ARCHIVES"` do for vi in $vsinclude do diff --git a/handlers/sys b/handlers/sys index cb0856b..83af9b9 100755 --- a/handlers/sys +++ b/handlers/sys @@ -46,20 +46,20 @@ fi if [ "$packages" == "yes" ]; then if [ $usevserver ] then - nodpkg="lost+found" + nodpkg="lost+found|ARCHIVES" info "vserver root directory set to: $VROOTDIR" - for vserver in `ls $VROOTDIR |grep -v $nodpkg` + for vserver in `ls $VROOTDIR | grep -E -v $nodpkg` do info "examining vserver: $vserver" - running=`vserver-info $vserver RUNNING` + running=`$VSERVERINFO $vserver RUNNING` if [ $running = 1 ]; then - if [ ! -x "`$VSERVER $vserver exec which dpkg`" ]; then + if [ ! -x "$VROOTDIR/$vserver`$VSERVER $vserver exec which dpkg`" ]; then warning "can't find dpkg in vserver $vserver, skipping installed packages report." - nodpkg="$nodpkg $vserver" + nodpkg="$nodpkg|$vserver" fi else warning "vserver $vserver is not running, skipping installed packages report." - nodpkg="$nodpkg $vserver" + nodpkg="$nodpkg|$vserver" fi done @@ -97,7 +97,7 @@ fi if [ $usevserver ] then - for vserver in `ls $VROOTDIR | grep -v $nodpkg | grep -v lost+found` + for vserver in `ls $VROOTDIR | grep -E -v $nodpkg` do debug "$VSERVER $vserver exec dpkg --get-selections > $VROOTDIR/$vserver$packagesfile" $VSERVER $vserver exec dpkg --get-selections > $VROOTDIR/$vserver$packagesfile -- 2.30.2 From 49dfbcb81f79772c2283a9637eee49616b0b5ac8 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Tue, 9 Aug 2005 20:53:19 +0000 Subject: [PATCH 10/16] Added a few safety checks to pgsql handler. --- changelog | 4 ++++ handlers/pgsql | 45 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/changelog b/changelog index a37d6aa..51ee159 100644 --- a/changelog +++ b/changelog @@ -16,6 +16,10 @@ version XX -- ... make use of configurable $VSERVERINFO instead of hard-coded vserver-info. fixed dpkg existence test inside vserver. fixed $nodpkg use. + changes to pgsql handler + now checks if the specified vserver is running. + now checks if $PGSQLDUMP/$PGSQLDUMPALL are available where needed. + now checks if "postgres" user exists on the host/vserver. version 0.7 -- July 26 2005 added ninjahelper: a dialog based wizard for creating backupninja configs. diff --git a/handlers/pgsql b/handlers/pgsql index 8d8f0c7..3f7d0b9 100644 --- a/handlers/pgsql +++ b/handlers/pgsql @@ -11,33 +11,56 @@ localhost=`hostname` # If vservers are configured, decide if the handler should # use them or if it should just operate on the host - -if [ "$vservers" == "yes" ] - then - if [ ! -z $vsname ] - then - info "Using vserver '$vsname'" +if [ "$vservers" == "yes" ]; then + if [ ! -z $vsname ]; then + info "using vserver '$vsname'" usevserver=1 else - info "No vserver name specified, actions will be performed on the host" + info "no vserver name specified, actions will be performed on the host" fi fi -# Check to make sure that the specified vserver exists -if [ $usevserver ] - then +# As needed, make sure that : +# * the specified vserver exists and is running +# * the specified vserver or host has the needed executables +if [ $usevserver ]; then + info "examining vserver '$vsname'" + # does it exist ? vroot="$VROOTDIR/$vsname" [ -d $vroot ] || fatal "vserver '$vsname' does not exist at '$vroot'" + # is it running ? + running=`$VSERVERINFO $vsname RUNNING` + if [ $running = 1 ]; then + if [ "$databases" == "all" ]; then + [ -x "$vroot`$VSERVER $vsname exec which $PGSQLDUMPALL`" ] || \ + fatal "Can't find $PGSQLDUMPALL in vserver $vsname." + else + [ -x "$vroot`$VSERVER $vsname exec which $PGSQLDUMP`" ] || \ + fatal "Can't find $PGSQLDUMP in vserver $vsname." + fi + else + fatal "vserver $vsname is not running." + fi +else + if [ "$databases" == "all" ]; then + [ -x "`which $PGSQLDUMPALL`" ] || \ + fatal "Can't find $PGSQLDUMPALL." + else + [ -x "`which $PGSQLDUMP`" ] || \ + fatal "Can't find $PGSQLDUMP." + fi fi # create backup dir, the vroot variable will be empty if no vsname was specified # and will proceed to operate on the host -[ -d $vroot$backupdir ] || mkdir -p $vroot$backupdir +[ -d $vroot$backupdir ] || (debug "mkdir -p $vroot$backupdir"; mkdir -p $vroot$backupdir) [ -d $vroot$backupdir ] || fatal "Backup directory '$vroot$backupdir'" # give backup dir the good uid and permissions # (in respect to the vserver, if $usevserver) pguid=`grep '^postgres:' $vroot/etc/passwd | awk -F: '{print $3}'` +[ -n "$pguid" ] || \ + fatal "No user called postgres`[ $usevserver != 1 ] || echo \" on vserver $vsname\"`." debug "chown $pguid $vroot$backupdir" chown $pguid $vroot$backupdir debug "chmod 700 $vroot$backupdir" -- 2.30.2 From 540f7e0f7c34b7a366a80f68ee8ea4dd32c89ecc Mon Sep 17 00:00:00 2001 From: intrigeri Date: Tue, 9 Aug 2005 20:55:58 +0000 Subject: [PATCH 11/16] ninjahelper: better check_perms(), improved xedit. --- changelog | 6 ++++++ ninjahelper | 30 +++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/changelog b/changelog index 51ee159..f2e11b1 100644 --- a/changelog +++ b/changelog @@ -20,6 +20,12 @@ version XX -- ... now checks if the specified vserver is running. now checks if $PGSQLDUMP/$PGSQLDUMPALL are available where needed. now checks if "postgres" user exists on the host/vserver. + changes to ninjahelper + check_perms() does not die anymore on group/world readable + helper scripts (now consistent with the "helper scripts + must not be group or world writable!" error msg). + xedit action now tries $EDITOR, then /etc/alternatives/editor, + then nano, vim and vi, and aborts if none of these exists. version 0.7 -- July 26 2005 added ninjahelper: a dialog based wizard for creating backupninja configs. diff --git a/ninjahelper b/ninjahelper index aedeaf5..817b47b 100755 --- a/ninjahelper +++ b/ninjahelper @@ -6,11 +6,12 @@ function check_perms() { local file=$1 local perms=`ls -ld $file` - perms=${perms:4:6} - if [[ "$perms" != "------" && "$perms" != "r--r--" ]]; then + group_w_perm=${perms:5:1} + world_w_perm=${perms:8:1} + if [ "$group_w_perm" == "w" -o "$world_w_perm" == "w" ]; then echo $perms - echo "helper scripts must not be group or world writable! Dying on file $file" - exit + echo "helper scripts must not be group or world writable! Dying on file $file" + exit fi if [ `ls -ld $file | awk '{print $3}'` != "root" ]; then echo "helper scripts must be owned by root! Dying on file $file" @@ -87,6 +88,25 @@ do_run() { read } +do_xedit() { + if [ -z "$EDITOR" -o ! -x "`which $EDITOR`" ]; then + if [ -h /etc/alternatives/editor -a -x "`readlink /etc/alternatives/editor`" ]; then + EDITOR="`readlink /etc/alternatives/editor`" + elif [ -x "`which nano`" ]; then + EDITOR="`which nano`" + elif [ -x "`which vim`" ]; then + EDITOR="`which vim`" + elif [ -x "`which vi`" ]; then + EDITOR="`which vi`" + else + echo "No suitable editor found." + echo "Please define $EDITOR or configure /etc/alternatives/editor." + exit + fi + fi + $EDITOR $1 +} + do_run_test() { backupninja --test --run $1 echo "Hit return to continue..." @@ -130,7 +150,7 @@ doaction() { result="$REPLY" case "$result" in "view") dialog --textbox $action 0 0;; - "xedit") $EDITOR $action;; + "xedit") do_xedit $action;; "disable") do_disable $action; return;; "enable") do_enable $action; return;; "name") do_rename $action; return;; -- 2.30.2 From ddaceb7ddae3d4e24657d7ce1d750cfa3e4f05b3 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Tue, 9 Aug 2005 20:59:20 +0000 Subject: [PATCH 12/16] Added helper for pgsql handler. --- changelog | 7 +-- etc/backup.d/example.pgsql | 17 ++++---- handlers/pgsql.helper | 89 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 11 deletions(-) create mode 100644 handlers/pgsql.helper diff --git a/changelog b/changelog index f2e11b1..cabe82b 100644 --- a/changelog +++ b/changelog @@ -1,10 +1,10 @@ version XX -- ... - added pgsql (PostgreSQL) handler, with vservers support + added pgsql (PostgreSQL) handler, with vservers support. added vservers support to duplicity handler Note: the configuration is a bit different of rdiff - handler's one, but the default behavior is the same: have - a look to example.dup. + handler's one, but the default behavior is the same: + have a look to example.dup. improved README documented .disabled method. corrected VROOTDIR default value. @@ -26,6 +26,7 @@ version XX -- ... must not be group or world writable!" error msg). xedit action now tries $EDITOR, then /etc/alternatives/editor, then nano, vim and vi, and aborts if none of these exists. + added helper for pgsql handler. version 0.7 -- July 26 2005 added ninjahelper: a dialog based wizard for creating backupninja configs. diff --git a/etc/backup.d/example.pgsql b/etc/backup.d/example.pgsql index 8313bd4..d9aab42 100644 --- a/etc/backup.d/example.pgsql +++ b/etc/backup.d/example.pgsql @@ -1,19 +1,20 @@ ### backupninja PostgreSQL config file ### +# vsname = (no default) +# what vserver to operate on, only used if vserver = yes in /etc/backupninja.conf +# if you do not specify a vsname the host will be operated on +# Note: if operating on a vserver, $VROOTDIR will be prepended to backupdir. + # backupdir = (default: /var/backups/postgres) # where to dump the backups -# + # databases = < all | db1 db2 db3 > (default = all) # which databases to backup. should either be the word 'all' or a # space separated list of database names. # Note: when using 'all', pg_dumpall is used instead of pg_dump, which means # that cluster-wide data (such as users and groups) are saved. -# + # compress = < yes | no > (default = yes) -# if yes, compress the pg_dump output. -# -# vsname = (no default) -# what vserver to operate on, only used if vserver = yes in /etc/backupninja.conf -# if you do not specify a vsname the host will be operated on -# Note: if operating on a vserver, $VROOTDIR will be prepended to backupdir. +# if yes, compress the pg_dump/pg_dumpall output. + diff --git a/handlers/pgsql.helper b/handlers/pgsql.helper new file mode 100644 index 0000000..8f9a8d4 --- /dev/null +++ b/handlers/pgsql.helper @@ -0,0 +1,89 @@ +HELPERS="$HELPERS pgsql:postgresql_database_backup" + +do_pgsql_vserver() { + inputBox "$pgsql_title" "Specify a vserver name:" + [ $? = 1 ] && return; + pgsql_vsname="vsname = $REPLY" +} + +do_pgsql_databases() { + formBegin "$pgsql_title: databases" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formDisplay + [ $? = 1 ] && return + + pgsql_databases="databases = " + for i in $REPLY; do + [ "$i" != "" ] && pgsql_databases="$pgsql_databases $i" + done +} + +pgsql_wizard() { + + # constants + pgsql_title="PostgreSQL action wizard" + + # vserver support + booleanBox "$pgsql_title" "Do you want to operate on a vserver? If not, the host will be operated on." + [ $? = 0 ] && do_pgsql_vserver + + # backupdir + inputBox "$pgsql_title" "Directory where to store the backups:`[ -z \"$pgsql_vsname\" ] || echo \"\n(In respect to chosen vserver's root directory)\"`" "/var/backups/postgres" + [ $? = 1 ] && return + pgsql_backupdir="backupdir = $REPLY" + + # databases + booleanBox "$pgsql_title" "Do you want to backup the whole cluster? If not, you'll be offered to choose the databases to backup." + if [ $? = 0 ]; then + pgsql_databases="databases = all" + else + do_pgsql_databases + fi + + # compress + booleanBox "$pgsql_title" "Do you want to compress the backups?" + if [ $? = 0 ]; then + pgsql_compress="compress = yes" + else + pgsql_compress="compress = no" + fi + + # write config file + get_next_filename $configdirectory/20.pgsql + cat >> $next_filename < (no default) +# what vserver to operate on, only used if vserver = yes in /etc/backupninja.conf +# if you do not specify a vsname the host will be operated on +# Note: if operating on a vserver, $VROOTDIR will be prepended to backupdir. +$pgsql_vsname + +# backupdir = (default: /var/backups/postgres) +# where to dump the backups +$pgsql_backupdir + +# databases = < all | db1 db2 db3 > (default = all) +# which databases to backup. should either be the word 'all' or a +# space separated list of database names. +# Note: when using 'all', pg_dumpall is used instead of pg_dump, which means +# that cluster-wide data (such as users and groups) are saved. +$pgsql_databases + +# compress = < yes | no > (default = yes) +# if yes, compress the pg_dump/pg_dumpall output. +$pgsql_compress + +EOF + chmod 000 $next_filename + +} -- 2.30.2 From 428e9532bf53fb73d2075865d2ced1c3c760812b Mon Sep 17 00:00:00 2001 From: Elijah Saxon Date: Tue, 9 Aug 2005 21:28:26 +0000 Subject: [PATCH 13/16] label is no longer required (now this works with ninjahelper without problems) --- handlers/rdiff | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/handlers/rdiff b/handlers/rdiff index 10cb3c0..40ad52d 100644 --- a/handlers/rdiff +++ b/handlers/rdiff @@ -65,7 +65,6 @@ fi ### SOURCE ### -[ "$label" != "" ] || fatal "Source missing label" [ "$sourcetype" == "local" ] || fatal "Only local source type supported" [ "$include" != "" -o "$vsinclude" != "" ] || fatal "No source includes specified" #TODO should I test for vsinclude if usevservers=1? @@ -140,10 +139,10 @@ if [ ! $test ]; then code=$? if [ "$code" == "0" ]; then debug $output - info "Successfully finished backing up source '$label'" + info "Successfully finished backing up source $label" else warning $output - warning "Failed backup up source '$label'" + warning "Failed backup up source $label" fi fi -- 2.30.2 From 4b662f4b336e4a42567cb818bd032afed7de9017 Mon Sep 17 00:00:00 2001 From: Elijah Saxon Date: Tue, 9 Aug 2005 21:36:13 +0000 Subject: [PATCH 14/16] minor change to rdiff handler. --- changelog | 58 +++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/changelog b/changelog index cabe82b..2dae7ad 100644 --- a/changelog +++ b/changelog @@ -1,33 +1,33 @@ -version XX -- ... +version 0.8 -- + added pgsql (PostgreSQL) handler, with vservers support. + added vservers support to duplicity handler + Note: the configuration is a bit different of rdiff + handler's one, but the default behavior is the same: + have a look to example.dup. + improved README + documented .disabled method. + corrected VROOTDIR default value. + added ninjahelper to the install instructions. + improved rdiff, dup and sys handlers' vservers support + prevent vserver-debiantools' $VROOTDIR/ARCHIVES directory + to be seen as a vserver + changes to sys handler + make use of configurable $VSERVERINFO instead of hard-coded vserver-info. + fixed dpkg existence test inside vserver. + fixed $nodpkg use. + changes to pgsql handler + now checks if the specified vserver is running. + now checks if $PGSQLDUMP/$PGSQLDUMPALL are available where needed. + now checks if "postgres" user exists on the host/vserver. + changes to ninjahelper + check_perms() does not die anymore on group/world readable + helper scripts (now consistent with the "helper scripts + must not be group or world writable!" error msg). + xedit action now tries $EDITOR, then /etc/alternatives/editor, + then nano, vim and vi, and aborts if none of these exists. + added helper for pgsql handler. + rdiff handler now does not require 'label' - added pgsql (PostgreSQL) handler, with vservers support. - added vservers support to duplicity handler - Note: the configuration is a bit different of rdiff - handler's one, but the default behavior is the same: - have a look to example.dup. - improved README - documented .disabled method. - corrected VROOTDIR default value. - added ninjahelper to the install instructions. - improved rdiff, dup and sys handlers' vservers support - prevent vserver-debiantools' $VROOTDIR/ARCHIVES directory - to be seen as a vserver - changes to sys handler - make use of configurable $VSERVERINFO instead of hard-coded vserver-info. - fixed dpkg existence test inside vserver. - fixed $nodpkg use. - changes to pgsql handler - now checks if the specified vserver is running. - now checks if $PGSQLDUMP/$PGSQLDUMPALL are available where needed. - now checks if "postgres" user exists on the host/vserver. - changes to ninjahelper - check_perms() does not die anymore on group/world readable - helper scripts (now consistent with the "helper scripts - must not be group or world writable!" error msg). - xedit action now tries $EDITOR, then /etc/alternatives/editor, - then nano, vim and vi, and aborts if none of these exists. - added helper for pgsql handler. - version 0.7 -- July 26 2005 added ninjahelper: a dialog based wizard for creating backupninja configs. considerably improved and changed the log file output. -- 2.30.2 From 3d3c5aa3df15af6b97633c068747e2adc6fe3a81 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Sun, 14 Aug 2005 22:49:43 +0000 Subject: [PATCH 15/16] Fixed a critical bug in pgsql handler vservers support. --- handlers/pgsql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/handlers/pgsql b/handlers/pgsql index 3f7d0b9..11a5cfe 100644 --- a/handlers/pgsql +++ b/handlers/pgsql @@ -69,14 +69,14 @@ chmod 700 $vroot$backupdir # if $databases = all, use pg_dumpall if [ "$databases" == "all" ]; then if [ $usevserver ]; then - execstr="$VSERVER $vsname exec su - postgres -c $PGSQLDUMPALL > $vroot$backupdir/${vsname}.sql" + execstr="$VSERVER $vsname exec su - postgres -c $PGSQLDUMPALL > $backupdir/${vsname}.sql" else execstr="su - postgres -c $PGSQLDUMPALL > $backupdir/${localhost}-all.sql" fi debug "$execstr" if [ ! $test ]; then - output=`$execstr 2>&1` - code=$? + output=`$execstr 2>&1` + code=$? if [ "$code" == "0" ]; then debug $output info "Successfully finished dump of pgsql cluster" @@ -91,7 +91,7 @@ else for db in $databases; do if [ $usevserver ] then - execstr="$VSERVER $vsname exec su - postgres -c $PGSQLDUMP $db > $vroot$backupdir/${db}.sql" + execstr="$VSERVER $vsname exec su - postgres -c $PGSQLDUMP $db > $backupdir/${db}.sql" else execstr="su - postgres -c $PGSQLDUMP $db > $backupdir/${db}.sql" fi -- 2.30.2 From 88d1f719c580ded553e95cbc125a65bf9362e5a4 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Sun, 14 Aug 2005 22:54:08 +0000 Subject: [PATCH 16/16] Fixed a critical bug in sys handler vservers support: it tried (and failed) to save packages list even if packages=no. --- handlers/sys | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/handlers/sys b/handlers/sys index 83af9b9..8054b4a 100755 --- a/handlers/sys +++ b/handlers/sys @@ -95,22 +95,23 @@ fi # here we grab a list of the packages installed and removed. # -if [ $usevserver ] -then - for vserver in `ls $VROOTDIR | grep -E -v $nodpkg` - do - debug "$VSERVER $vserver exec dpkg --get-selections > $VROOTDIR/$vserver$packagesfile" - $VSERVER $vserver exec dpkg --get-selections > $VROOTDIR/$vserver$packagesfile - done -fi - -# We want to perform this on the host as well if [ "$packages" == "yes" ]; then - debug "dpkg --get-selections > $packagesfile" - dpkg --get-selections > $packagesfile + if [ $usevserver ] + then + for vserver in `ls $VROOTDIR | grep -E -v $nodpkg` + do + debug "$VSERVER $vserver exec dpkg --get-selections > $VROOTDIR/$vserver$packagesfile" + $VSERVER $vserver exec dpkg --get-selections > $VROOTDIR/$vserver$packagesfile + done + fi + +# We want to perform this on the host as well + if [ "$packages" == "yes" ]; then + debug "dpkg --get-selections > $packagesfile" + dpkg --get-selections > $packagesfile + fi fi - ## PARTITIONS ############################# # here we use sfdisk to dump a listing of all the partitions. -- 2.30.2