From 4ecaae94054c4eb919ddbd45904d834383a09558 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Fri, 22 May 2009 14:50:52 +0200 Subject: Make all indentation consistent. Previously, there were many indentation styles in use: Real tabs, 2, 3 or 4 spaces, mixing these within the same file, function or even within a single line. This commit changes all bash scripts in the handlers, src and lib dirs to use consistent indentation: three spaces are now used everywhere. Other files (e.g. Makefiles) are left untouched. Additionally, this commit removes all trailing whitespace. --- handlers/dup.helper.in | 148 +++++++-------- handlers/dup.in | 38 ++-- handlers/ldap.helper.in | 50 ++--- handlers/ldap.in | 28 +-- handlers/maildir.in | 453 +++++++++++++++++++++++----------------------- handlers/makecd.helper.in | 114 ++++++------ handlers/makecd.in | 60 +++--- handlers/mysql.helper.in | 102 +++++------ handlers/mysql.in | 380 +++++++++++++++++++------------------- handlers/pgsql.helper.in | 24 +-- handlers/pgsql.in | 116 ++++++------ handlers/rdiff.helper.in | 60 +++--- handlers/rdiff.in | 200 ++++++++++---------- handlers/rsync.in | 266 +++++++++++++-------------- handlers/sh.in | 2 +- handlers/svn.in | 64 +++---- handlers/sys.helper.in | 26 +-- handlers/sys.in | 194 ++++++++++---------- handlers/tar.helper.in | 20 +- handlers/tar.in | 22 +-- handlers/trac.in | 55 +++--- handlers/wget | 120 ++++++------ 22 files changed, 1269 insertions(+), 1273 deletions(-) (limited to 'handlers') diff --git a/handlers/dup.helper.in b/handlers/dup.helper.in index c1fbdd5..86745c8 100644 --- a/handlers/dup.helper.in +++ b/handlers/dup.helper.in @@ -13,11 +13,11 @@ do_dup_host_includes() { [ -z "$dup_includes" ] && dup_includes="$dup_default_includes" for i in $dup_includes; do formItem include "$i" - done - formItem include "" - formItem include "" - formItem include "" - formDisplay + done + formItem include "" + formItem include "" + formItem include "" + formDisplay [ $? = 0 ] || return 1 dup_includes="$REPLY" done @@ -37,10 +37,10 @@ do_dup_vserver() { [ -z "$dup_vsincludes" ] && dup_vsincludes="$dup_default_includes" for i in $dup_vsincludes; do formItem include "$i" - done - formItem include "" - formItem include "" - formItem include "" + done + formItem include "" + formItem include "" + formItem include "" formDisplay [ $? = 0 ] || return 1 dup_vsincludes="$REPLY" @@ -69,26 +69,26 @@ do_dup_src() { [ $? = 0 ] || return 1 case $host_or_vservers in 'host') - do_dup_host_includes - [ $? = 0 ] || return 1 - ;; + do_dup_host_includes + [ $? = 0 ] || return 1 + ;; 'vservers') - do_dup_vserver - [ $? = 0 ] || return 1 - ;; + do_dup_vserver + [ $? = 0 ] || return 1 + ;; 'both') - do_dup_host_includes - [ $? = 0 ] || return 1 - do_dup_vserver - [ $? = 0 ] || return 1 - ;; + do_dup_host_includes + [ $? = 0 ] || return 1 + do_dup_vserver + [ $? = 0 ] || return 1 + ;; *) - return 1 - ;; + return 1 + ;; esac do_dup_excludes [ $? = 0 ] || return 1 - + _src_done="(DONE)" setDefault dest } @@ -102,13 +102,13 @@ do_dup_dest() { REPLY= while [ -z "$REPLY" -o -z "$dup_destdir" -o -z "$dup_desthost" -o -z "$dup_destuser" ]; do formBegin "$dup_title - destination: first three items are compulsory" - formItem "desthost" "$dup_desthost" - formItem "destuser" "$dup_destuser" - formItem "destdir" "$dup_destdir" - formItem "keep" "$dup_keep" + formItem "desthost" "$dup_desthost" + formItem "destuser" "$dup_destuser" + formItem "destdir" "$dup_destdir" + formItem "keep" "$dup_keep" formItem "incremental" "$dup_incremental" - formItem "bandwidthlimit" "$dup_bandwidth" - formItem "sshoptions" "$dup_sshoptions" + formItem "bandwidthlimit" "$dup_bandwidth" + formItem "sshoptions" "$dup_sshoptions" formDisplay [ $? = 0 ] || return 1 @@ -117,7 +117,7 @@ do_dup_dest() { IFS=$':' thereply=($replyconverted) IFS=$' \t\n' - + dup_desthost=${thereply[0]} dup_destuser=${thereply[1]} dup_destdir=${thereply[2]} @@ -165,9 +165,9 @@ do_dup_gpg_signkey() { # signkey ? REPLY= while [ -z "$REPLY" -o -z "$dup_gpg_signkey" ]; do - inputBox "$dup_title - GnuPG" "Enter the ID of the private GnuPG key to be used to sign the backups:" "$dup_gpg_signkey" - [ $? = 0 ] || return 1 - dup_gpg_signkey="$REPLY" + inputBox "$dup_title - GnuPG" "Enter the ID of the private GnuPG key to be used to sign the backups:" "$dup_gpg_signkey" + [ $? = 0 ] || return 1 + dup_gpg_signkey="$REPLY" done fi } @@ -183,7 +183,7 @@ do_dup_gpg_passphrase() { } do_dup_gpg() { - + # symmetric or public key encryption ? booleanBox "$dup_title - GnuPG" "Use public key encryption? Otherwise, symmetric encryption will be used, and data signing will be impossible." "$dup_gpg_asymmetric_encryption" if [ $? = 0 ]; then @@ -197,7 +197,7 @@ do_dup_gpg() { do_dup_gpg_encryptkey ; [ $? = 0 ] || return 1 do_dup_gpg_sign ; [ $? = 0 ] || return 1 if [ "$dup_gpg_sign" == yes ]; then - do_dup_gpg_signkey ; [ $? = 0 ] || return 1 + do_dup_gpg_signkey ; [ $? = 0 ] || return 1 fi else dup_gpg_sign=no @@ -334,7 +334,7 @@ EOF if [ "$host_or_vservers" == host -o "$host_or_vservers" == both ]; then set -o noglob for i in $dup_includes; do - echo "include = $i" >> $next_filename + echo "include = $i" >> $next_filename done set +o noglob fi @@ -432,49 +432,49 @@ EOF dup_main_menu() { - while true; do - srcitem="choose files to include & exclude $_src_done" - destitem="configure backup destination $_dest_done" - gpgitem="configure GnuPG encryption/signing $_gpg_done" - conitem="set up ssh keys and test remote connection $_con_done" - advitem="edit advanced settings $_adv_done" - # TODO: add the following to the menu when do_dup_conn is written - # conn "$conitem" \ - menuBox "$dup_title" "choose a step:" \ - src "$srcitem" \ - dest "$destitem" \ - gpg "$gpgitem" \ - adv "$advitem" \ - finish "finish and create config file" - [ $? = 0 ] || return 1 - result="$REPLY" - - case "$result" in - "src") do_dup_src;; - "dest") do_dup_dest;; - "gpg") do_dup_gpg;; - # TODO: enable the following when do_dup_conn is written - # "conn") do_dup_conn;; - "adv") do_dup_adv;; - "finish") - if [[ "$_dest_done$_gpg_done$_src_done" != "(DONE)(DONE)(DONE)" ]]; then - # TODO: replace the previous test by the following when do_dup_conn is written - # if [[ "$_con_done$_dest_done$_gpg_done$_src_done" != "(DONE)(DONE)(DONE)(DONE)" ]]; then - msgBox "$dup_title" "You cannot create the configuration file until the four first steps are completed." - else - do_dup_finish - break - fi - ;; - esac - - done + while true; do + srcitem="choose files to include & exclude $_src_done" + destitem="configure backup destination $_dest_done" + gpgitem="configure GnuPG encryption/signing $_gpg_done" + conitem="set up ssh keys and test remote connection $_con_done" + advitem="edit advanced settings $_adv_done" + # TODO: add the following to the menu when do_dup_conn is written + # conn "$conitem" \ + menuBox "$dup_title" "choose a step:" \ + src "$srcitem" \ + dest "$destitem" \ + gpg "$gpgitem" \ + adv "$advitem" \ + finish "finish and create config file" + [ $? = 0 ] || return 1 + result="$REPLY" + + case "$result" in + "src") do_dup_src;; + "dest") do_dup_dest;; + "gpg") do_dup_gpg;; + # TODO: enable the following when do_dup_conn is written + # "conn") do_dup_conn;; + "adv") do_dup_adv;; + "finish") + if [[ "$_dest_done$_gpg_done$_src_done" != "(DONE)(DONE)(DONE)" ]]; then + # TODO: replace the previous test by the following when do_dup_conn is written + # if [[ "$_con_done$_dest_done$_gpg_done$_src_done" != "(DONE)(DONE)(DONE)(DONE)" ]]; then + msgBox "$dup_title" "You cannot create the configuration file until the four first steps are completed." + else + do_dup_finish + break + fi + ;; + esac + + done } ### Main function dup_wizard() { - + require_packages duplicity # Global variables diff --git a/handlers/dup.in b/handlers/dup.in index 9c6a493..60a4ce9 100644 --- a/handlers/dup.in +++ b/handlers/dup.in @@ -66,9 +66,9 @@ if [ "$testconnect" == "yes" ]; then if [ ! $test ]; then result=`ssh $sshoptions -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'` if [ "$result" != "1" ]; then - fatal "Can't connect to $desthost as $destuser." + fatal "Can't connect to $desthost as $destuser." else - debug "Connected to $desthost as $destuser successfully" + debug "Connected to $desthost as $destuser successfully" fi fi fi @@ -152,7 +152,7 @@ fi # If incremental==no, force a full backup anyway. if [ "$incremental" == "no" ]; then # before 0.4.4, full was an option and not a command - if [ "$duplicity_major" -le 0 -a "$duplicity_minor" -le 4 -a "$duplicity_sub" -lt 4 ]; then + if [ "$duplicity_major" -le 0 -a "$duplicity_minor" -le 4 -a "$duplicity_sub" -lt 4 ]; then execstr_options="${execstr_options} --full" else execstr_command="full" @@ -204,9 +204,9 @@ done if [ $usevserver = yes ]; then for vserver in $vsnames; do for vi in $vsinclude; do - str="${vi//__star__/*}" - str="$VROOTDIR/$vserver$str" - execstr_source="${execstr_source} --include '$str'" + str="${vi//__star__/*}" + str="$VROOTDIR/$vserver$str" + execstr_source="${execstr_source} --include '$str'" done done fi @@ -229,11 +229,11 @@ if [ "$duplicity_major" -ge 0 -a "$duplicity_minor" -ge 4 -a "$duplicity_sub" -g "$precmd duplicity cleanup --force $execstr_options $execstr_serverpart 2>&1"` exit_code=$? if [ $exit_code -eq 0 ]; then - debug $output - info "Duplicity cleanup finished successfully." + debug $output + info "Duplicity cleanup finished successfully." else - debug $output - warning "Duplicity cleanup failed." + debug $output + warning "Duplicity cleanup failed." fi fi fi @@ -244,17 +244,17 @@ if [ "$keep" != "yes" ]; then debug "$precmd duplicity remove-older-than $keep --force $execstr_options $execstr_serverpart" if [ ! $test ]; then export PASSPHRASE=$password - output=`nice -n $nicelevel \ + output=`nice -n $nicelevel \ su -c \ "$precmd duplicity remove-older-than $keep --force $execstr_options $execstr_serverpart 2>&1"` - exit_code=$? - if [ $exit_code -eq 0 ]; then - debug $output - info "Duplicity remove-older-than finished successfully." - else - debug $output - warning "Duplicity remove-older-than failed." - fi + exit_code=$? + if [ $exit_code -eq 0 ]; then + debug $output + info "Duplicity remove-older-than finished successfully." + else + debug $output + warning "Duplicity remove-older-than failed." + fi fi fi fi diff --git a/handlers/ldap.helper.in b/handlers/ldap.helper.in index 9251826..4870ae4 100644 --- a/handlers/ldap.helper.in +++ b/handlers/ldap.helper.in @@ -3,7 +3,7 @@ HELPERS="$HELPERS ldap:ldap_database_backup" ldap_create_file() { -while true; do + while true; do checkBox "ldap action wizard" "check options (slapcat OR ldapsearch)" \ "slapcat" "export ldif using slapcat" yes \ "ldapsearch" "export ldif using ldapsearch" no \ @@ -22,21 +22,21 @@ while true; do result="$REPLY" for opt in $result; do case $opt in - '"compress"') compress="compress = yes";; - '"slapcat"') - method="method = slapcat" - [ "$_RESTART" == "yes" ] && restart="restart = yes" - ;; - '"ldapsearch"') - method="method = ldapsearch" - inputBox "ldap action wizard" "ldapsearch requires authentication. Specify here what password file to use. It must have the password with no trailing return and it should not be world readable." - [ $? = 1 ] && return - passwordfile="passwordfile = $REPLY" - inputBox "ldap action wizard" "ldapsearch requires authentication. Specify here what DN to bind as:" - [ $? = 1 ] && return - binddn="binddn = $REPLY" - require_packages ldap-utils - ;; + '"compress"') compress="compress = yes";; + '"slapcat"') + method="method = slapcat" + [ "$_RESTART" == "yes" ] && restart="restart = yes" + ;; + '"ldapsearch"') + method="method = ldapsearch" + inputBox "ldap action wizard" "ldapsearch requires authentication. Specify here what password file to use. It must have the password with no trailing return and it should not be world readable." + [ $? = 1 ] && return + passwordfile="passwordfile = $REPLY" + inputBox "ldap action wizard" "ldapsearch requires authentication. Specify here what DN to bind as:" + [ $? = 1 ] && return + binddn="binddn = $REPLY" + require_packages ldap-utils + ;; '"ssl"') ssl="ssl = yes";; '"tls"') tls="tls = yes";; esac @@ -54,9 +54,9 @@ $tls # conf = /etc/ldap/slapd.conf # databases = all EOF - chmod 600 $next_filename - return -done + chmod 600 $next_filename + return + done } ldap_wizard() { @@ -71,7 +71,7 @@ ldap_wizard() { elif [ "$backend" == "ldbm" ]; then ldbm=yes fi - done + done if [ "$bdb" == "yes" -o "$hdb" == "yes" ]; then if [ "$ldbm" == "no" ]; then @@ -80,11 +80,11 @@ ldap_wizard() { ldap_create_file fi elif [ "$ldbm" == "yes" ]; then - msgBox "ldap action wizard" "It looks like the backend in your slapd.conf is set to LDBM. Because of this, you will have less options (because it is not safe to use slapcat while slapd is running LDBM)." - _RESTART=yes - ldap_create_file + msgBox "ldap action wizard" "It looks like the backend in your slapd.conf is set to LDBM. Because of this, you will have less options (because it is not safe to use slapcat while slapd is running LDBM)." + _RESTART=yes + ldap_create_file else - msgBox "ldap action wizard" "I couldn't find any supported backend in your slapd.conf. Bailing out." - return + msgBox "ldap action wizard" "I couldn't find any supported backend in your slapd.conf. Bailing out." + return fi } diff --git a/handlers/ldap.in b/handlers/ldap.in index 8ff1ccf..0b0166e 100644 --- a/handlers/ldap.in +++ b/handlers/ldap.in @@ -35,25 +35,25 @@ dbsuffixes=(`@AWK@ 'BEGIN {OFS=":"} /[:space:]*^database[:space:]*\w*/ {db=$2}; if [ "$ldif" == "yes" ]; then dumpdir="$backupdir" [ -d $dumpdir ] || mkdir -p $dumpdir - + if [ "$databases" == 'all' ]; then dbcount=`grep '^database' $conf | wc -l` let "dbcount = dbcount - 1" databases=`seq 0 $dbcount`; - fi - + fi + for db in $databases; do if [ `expr index "$db" "="` == "0" ]; then - # db is a number, get the suffix. + # db is a number, get the suffix. dbsuffix=${dbsuffixes[$db]/*:/} else dbsuffix=$db fi - # some databases don't have suffix (like monitor), skip these + # some databases don't have suffix (like monitor), skip these if [ "$dbsuffix" == "" ]; then continue; fi - + if [ "$method" == "slapcat" ]; then execstr="$SLAPCAT -f $conf -b $dbsuffix" else @@ -74,16 +74,16 @@ if [ "$ldif" == "yes" ]; then debug "Shutting down ldap server..." /etc/init.d/slapd stop fi - - ext= - if [ "$compress" == "yes" ]; then - ext=".gz" - fi + + ext= + if [ "$compress" == "yes" ]; then + ext=".gz" + fi touch $dumpdir/$dbsuffix.ldif$ext if [ ! -f $dumpdir/$dbsuffix.ldif$ext ]; then fatal "Couldn't create ldif dump file: $dumpdir/$dbsuffix.ldif$ext" fi - + if [ "$compress" == "yes" ]; then execstr="$execstr | $GZIP > $dumpdir/$dbsuffix.ldif.gz" else @@ -99,13 +99,13 @@ if [ "$ldif" == "yes" ]; then warning $output warning "Failed ldif export of $dbsuffix" fi - + if [ "$restart" == "yes" ]; then debug "Starting ldap server..." /etc/init.d/slapd start fi fi - done + done fi return 0 diff --git a/handlers/maildir.in b/handlers/maildir.in index d5731be..e88619d 100644 --- a/handlers/maildir.in +++ b/handlers/maildir.in @@ -6,17 +6,17 @@ # to a remote server. It is designed to be run with low overhead # in terms of cpu and bandwidth so it runs pretty slow. # Hardlinking is used to save storage space. -# +# # This handler expects that your maildir directory structure is # either one of the following: -# -# 1. /$srcdir/[a-zA-Z0-9]/$user for example: +# +# 1. /$srcdir/[a-zA-Z0-9]/$user for example: # /var/maildir/a/anarchist # /var/maildir/a/arthur # ... # /var/maildir/Z/Zaphod # /var/maildir/Z/Zebra -# +# # 2. or the following: # /var/maildir/domain.org/user1 # /var/maildir/domain.org/user2 @@ -25,7 +25,7 @@ # /var/maildir/anotherdomain.org/user2 # ... # -# if the configuration is setup to have keepdaily at 3, +# if the configuration is setup to have keepdaily at 3, # keepweekly is 2, and keepmonthly is 1, then each user's # maildir backup snapshot directory will contain these files: # daily.1 @@ -41,15 +41,15 @@ # We handle each maildir individually because it becomes very # unweldy to hardlink and rsync many hundreds of thousands # of files at once. It is much faster to take on smaller -# chunks at a time. +# chunks at a time. # -# For the backup rotation to work, destuser must be able to run +# For the backup rotation to work, destuser must be able to run # arbitrary bash commands on the desthost. # # Any maildir which is deleted from the source will be moved to -# "deleted" directory in the destination. It is up to you to +# "deleted" directory in the destination. It is up to you to # periodically remove this directory or old maildirs in it. -# +# ############################################################## getconf rotate yes @@ -91,33 +91,33 @@ excludes="--exclude '.Trash/\*' --exclude '.Mistakes/\*' --exclude '.Spam/\*'" ### FUNCTIONS function do_user() { - local user=$1 - local btype=$2 - local userdir=${3%/} - local source="$srcdir/$userdir/$user/" - local target="$destdir/$userdir/$user/$btype.1" - if [ ! -d $source ]; then - warning "maildir $source not found" - return - fi - - debug "syncing" - ret=`$RSYNC -e "ssh -p $destport -i $destid_file" -r \ - --links --ignore-existing --delete --size-only --bwlimit=$speedlimit \ - --exclude '.Trash/*' --exclude '.Mistakes/*' --exclude '.Spam/*' \ - $source $destuser@$desthost:$target \ - 2>&1` - ret=$? - # ignore 0 (success) and 24 (file vanished before it could be copied) - if [ $ret != 0 -a $ret != 24 ]; then - warning "rsync $user failed" - warning " returned: $ret" - let "failedcount = failedcount + 1" - if [ $failedcount -gt 100 ]; then - fatal "100 rsync errors -- something is not working right. bailing out." - fi - fi - ssh -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file "date +%c%n%s > $target/created" + local user=$1 + local btype=$2 + local userdir=${3%/} + local source="$srcdir/$userdir/$user/" + local target="$destdir/$userdir/$user/$btype.1" + if [ ! -d $source ]; then + warning "maildir $source not found" + return + fi + + debug "syncing" + ret=`$RSYNC -e "ssh -p $destport -i $destid_file" -r \ + --links --ignore-existing --delete --size-only --bwlimit=$speedlimit \ + --exclude '.Trash/*' --exclude '.Mistakes/*' --exclude '.Spam/*' \ + $source $destuser@$desthost:$target \ + 2>&1` + ret=$? + # ignore 0 (success) and 24 (file vanished before it could be copied) + if [ $ret != 0 -a $ret != 24 ]; then + warning "rsync $user failed" + warning " returned: $ret" + let "failedcount = failedcount + 1" + if [ $failedcount -gt 100 ]; then + fatal "100 rsync errors -- something is not working right. bailing out." + fi + fi + ssh -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file "date +%c%n%s > $target/created" } # remove any maildirs from backup which might have been deleted @@ -125,116 +125,116 @@ function do_user() { # (actually, it just moved them to the directory "deleted") function do_remove() { - local tmp1=`maketemp maildir-tmp-file` - local tmp2=`maketemp maildir-tmp-file` - - ssh -p $destport -i $destid_file $destuser@$desthost mkdir -p "$destdir/deleted" - cd "$srcdir" - for userdir in `ls -d1 */`; do - ls -1 "$srcdir/$userdir" | sort > $tmp1 - ssh -p $destport -i $destid_file $destuser@$desthost ls -1 "$destdir/$userdir" | sort > $tmp2 - for deluser in `join -v 2 $tmp1 $tmp2`; do - [ "$deluser" != "" ] || continue - info "removing $destuser@$desthost:$destdir/$userdir$deluser/" - ssh -p $destport -i $destid_file $destuser@$desthost mv "$destdir/$userdir$deluser/" "$destdir/deleted" - ssh -p $destport -i $destid_file $destuser@$desthost "date +%c%n%s > '$destdir/deleted/$deluser/deleted_on'" - done - done - rm $tmp1 - rm $tmp2 + local tmp1=`maketemp maildir-tmp-file` + local tmp2=`maketemp maildir-tmp-file` + + ssh -p $destport -i $destid_file $destuser@$desthost mkdir -p "$destdir/deleted" + cd "$srcdir" + for userdir in `ls -d1 */`; do + ls -1 "$srcdir/$userdir" | sort > $tmp1 + ssh -p $destport -i $destid_file $destuser@$desthost ls -1 "$destdir/$userdir" | sort > $tmp2 + for deluser in `join -v 2 $tmp1 $tmp2`; do + [ "$deluser" != "" ] || continue + info "removing $destuser@$desthost:$destdir/$userdir$deluser/" + ssh -p $destport -i $destid_file $destuser@$desthost mv "$destdir/$userdir$deluser/" "$destdir/deleted" + ssh -p $destport -i $destid_file $destuser@$desthost "date +%c%n%s > '$destdir/deleted/$deluser/deleted_on'" + done + done + rm $tmp1 + rm $tmp2 } function do_rotate() { - [ "$rotate" == "yes" ] || return; - local user=$1 - local userdir=${2%/} - local backuproot="$destdir/$userdir/$user" + [ "$rotate" == "yes" ] || return; + local user=$1 + local userdir=${2%/} + local backuproot="$destdir/$userdir/$user" ( - ssh -T -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file < 0; i-- )); do - if [ -d \$dir.\$i ]; then - if [ -f \$dir.\$i/created ]; then - created=\`tail -1 \$dir.\$i/created\` - else - created=0 - fi - cutoff_time=\$(( now - (seconds*(i-1)) )) - if [ ! \$created -gt \$cutoff_time ]; then - next=\$(( i + 1 )) - if [ ! -d \$dir.\$next ]; then - echo "Debug: \$rottype.\$i --> \$rottype.\$next" - mv \$dir.\$i \$dir.\$next - date +%c%n%s > \$dir.\$next/rotated - else - echo "Debug: skipping rotation of \$dir.\$i because \$dir.\$next already exists." - fi - else - echo "Debug: skipping rotation of \$dir.\$i because it was created" \$(( (now-created)/86400)) "days ago ("\$(( (now-cutoff_time)/86400))" needed)." - fi - fi - done - done - - max=\$((keepdaily+1)) - if [ \( \$keepweekly -gt 0 -a -d $backuproot/daily.\$max \) -a ! -d $backuproot/weekly.1 ]; then - echo "Debug: daily.\$max --> weekly.1" - mv $backuproot/daily.\$max $backuproot/weekly.1 - date +%c%n%s > $backuproot/weekly.1/rotated - fi - - max=\$((keepweekly+1)) - if [ \( \$keepmonthly -gt 0 -a -d $backuproot/weekly.\$max \) -a ! -d $backuproot/monthly.1 ]; then - echo "Debug: weekly.\$max --> monthly.1" - mv $backuproot/weekly.\$max $backuproot/monthly.1 - date +%c%n%s > $backuproot/monthly.1/rotated - fi - - for rottype in daily weekly monthly; do - max=\$((keep\${rottype}+1)) - dir="$backuproot/\$rottype" - oldest=\`find $backuproot -maxdepth 1 -type d -name \$rottype'.*' | @SED@ 's/^.*\.//' | sort -n | tail -1\` - [ "\$oldest" == "" ] && oldest=0 - # if we've rotated the last backup off the stack, remove it. - for (( i=\$oldest; i >= \$max; i-- )); do - if [ -d \$dir.\$i ]; then - if [ -d $backuproot/rotate.tmp ]; then - echo "Debug: removing rotate.tmp" - rm -rf $backuproot/rotate.tmp - fi - echo "Debug: moving \$rottype.\$i to rotate.tmp" - mv \$dir.\$i $backuproot/rotate.tmp - fi - done - done + seconds_daily=86400 + seconds_weekly=604800 + seconds_monthly=2628000 + keepdaily=$keepdaily + keepweekly=$keepweekly + keepmonthly=$keepmonthly + now=\`date +%s\` + + if [ ! -d "$backuproot" ]; then + echo "Debug: skipping rotate of $user. $backuproot doesn't exist." + exit + fi + for rottype in daily weekly monthly; do + seconds=\$((seconds_\${rottype})) + + dir="$backuproot/\$rottype" + if [ ! -d \$dir.1 ]; then + echo "Debug: \$dir.1 does not exist, skipping." + continue 1 + elif [ ! -f \$dir.1/created ]; then + echo "Warning: \$dir.1/created does not exist. This backup may be only partially completed. Skipping rotation." + continue 1 + fi + + # Rotate the current list of backups, if we can. + oldest=\`find $backuproot -maxdepth 1 -type d -name \$rottype'.*' | @SED@ 's/^.*\.//' | sort -n | tail -1\` + #echo "Debug: oldest \$oldest" + [ "\$oldest" == "" ] && oldest=0 + for (( i=\$oldest; i > 0; i-- )); do + if [ -d \$dir.\$i ]; then + if [ -f \$dir.\$i/created ]; then + created=\`tail -1 \$dir.\$i/created\` + else + created=0 + fi + cutoff_time=\$(( now - (seconds*(i-1)) )) + if [ ! \$created -gt \$cutoff_time ]; then + next=\$(( i + 1 )) + if [ ! -d \$dir.\$next ]; then + echo "Debug: \$rottype.\$i --> \$rottype.\$next" + mv \$dir.\$i \$dir.\$next + date +%c%n%s > \$dir.\$next/rotated + else + echo "Debug: skipping rotation of \$dir.\$i because \$dir.\$next already exists." + fi + else + echo "Debug: skipping rotation of \$dir.\$i because it was created" \$(( (now-created)/86400)) "days ago ("\$(( (now-cutoff_time)/86400))" needed)." + fi + fi + done + done + + max=\$((keepdaily+1)) + if [ \( \$keepweekly -gt 0 -a -d $backuproot/daily.\$max \) -a ! -d $backuproot/weekly.1 ]; then + echo "Debug: daily.\$max --> weekly.1" + mv $backuproot/daily.\$max $backuproot/weekly.1 + date +%c%n%s > $backuproot/weekly.1/rotated + fi + + max=\$((keepweekly+1)) + if [ \( \$keepmonthly -gt 0 -a -d $backuproot/weekly.\$max \) -a ! -d $backuproot/monthly.1 ]; then + echo "Debug: weekly.\$max --> monthly.1" + mv $backuproot/weekly.\$max $backuproot/monthly.1 + date +%c%n%s > $backuproot/monthly.1/rotated + fi + + for rottype in daily weekly monthly; do + max=\$((keep\${rottype}+1)) + dir="$backuproot/\$rottype" + oldest=\`find $backuproot -maxdepth 1 -type d -name \$rottype'.*' | @SED@ 's/^.*\.//' | sort -n | tail -1\` + [ "\$oldest" == "" ] && oldest=0 + # if we've rotated the last backup off the stack, remove it. + for (( i=\$oldest; i >= \$max; i-- )); do + if [ -d \$dir.\$i ]; then + if [ -d $backuproot/rotate.tmp ]; then + echo "Debug: removing rotate.tmp" + rm -rf $backuproot/rotate.tmp + fi + echo "Debug: moving \$rottype.\$i to rotate.tmp" + mv \$dir.\$i $backuproot/rotate.tmp + fi + done + done ####### END REMOTE SCRIPT ####### EOF ) | (while read a; do passthru $a; done) @@ -243,67 +243,67 @@ EOF function setup_remote_dirs() { - local user=$1 - local backuptype=$2 - local userdir=${3%/} - local dir="$destdir/$userdir/$user/$backuptype" - local tmpdir="$destdir/$userdir/$user/rotate.tmp" + local user=$1 + local backuptype=$2 + local userdir=${3%/} + local dir="$destdir/$userdir/$user/$backuptype" + local tmpdir="$destdir/$userdir/$user/rotate.tmp" ( - ssh -T -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file < $backuptype.1" - cp -alf $dir.2/. $dir.1 - #if [ \$? == 1 ]; then - # echo "Fatal: could not create hard links to $dir.1 on host $desthost" - # exit 1 - #fi - fi - fi - [ -f $dir.1/created ] && rm $dir.1/created - [ -f $dir.1/rotated ] && rm $dir.1/rotated - exit 0 + ssh -T -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file < $backuptype.1" + cp -alf $dir.2/. $dir.1 + #if [ \$? == 1 ]; then + # echo "Fatal: could not create hard links to $dir.1 on host $desthost" + # exit 1 + #fi + fi + fi + [ -f $dir.1/created ] && rm $dir.1/created + [ -f $dir.1/rotated ] && rm $dir.1/rotated + exit 0 EOF ) | (while read a; do passthru $a; done) - if [ $? == 1 ]; then exit; fi + if [ $? == 1 ]; then exit; fi } function start_mux() { - if [ "$multiconnection" == "yes" ]; then - debug "Starting dummy ssh connection" - ssh -p $destport -i $destid_file $destuser@$desthost sleep 1d & - sleep 1 - fi + if [ "$multiconnection" == "yes" ]; then + debug "Starting dummy ssh connection" + ssh -p $destport -i $destid_file $destuser@$desthost sleep 1d & + sleep 1 + fi } function end_mux() { - if [ "$multiconnection" == "yes" ]; then - debug "Stopping dummy ssh connection" - ssh -p $destport -i $destid_file $destuser@$desthost pkill sleep - fi + if [ "$multiconnection" == "yes" ]; then + debug "Stopping dummy ssh connection" + ssh -p $destport -i $destid_file $destuser@$desthost pkill sleep + fi } ### @@ -312,10 +312,10 @@ function end_mux() { # see if we can login debug "ssh -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file 'echo -n 1'" if [ ! $test ]; then - result=`ssh -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file 'echo -n 1' 2>&1` - if [ "$result" != "1" ]; then - fatal "Can't connect to $desthost as $destuser using $destid_file." - fi + result=`ssh -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file 'echo -n 1' 2>&1` + if [ "$result" != "1" ]; then + fatal "Can't connect to $desthost as $destuser using $destid_file." + fi fi end_mux @@ -324,47 +324,46 @@ start_mux ## SANITY CHECKS ## status=`ssh -p $destport -i $destid_file $destuser@$desthost "[ -d \"$destdir\" ] && echo 'ok'"` if [ "$status" != "ok" ]; then - end_mux - fatal "Destination directory $destdir doesn't exist!" - exit + end_mux + fatal "Destination directory $destdir doesn't exist!" + exit fi ### REMOVE OLD MAILDIRS ### if [ "$remove" == "yes" ]; then - do_remove + do_remove fi ### MAKE BACKUPS ### if [ "$backup" == "yes" ]; then - if [ $keepdaily -gt 0 ]; then btype=daily - elif [ $keepweekly -gt 0 ]; then btype=weekly - elif [ $keepmonthly -gt 0 ]; then btype=monthly - else fatal "keeping no backups"; fi - - if [ "$testuser" != "" ]; then - cd "$srcdir/${user:0:1}" - do_rotate $testuser - setup_remote_dirs $testuser $btype - do_user $testuser $btype - else - [ -d "$srcdir" ] || fatal "directory $srcdir not found." - cd "$srcdir" - for userdir in `ls -d1 */`; do - [ -d "$srcdir/$userdir" ] || fatal "directory $srcdir/$userdir not found." - cd "$srcdir/$userdir" - debug $userdir - for user in `ls -1`; do - [ "$user" != "" ] || continue - debug "$user $userdir" - do_rotate $user $userdir - setup_remote_dirs $user $btype $userdir - do_user $user $btype $userdir - done - done - fi + if [ $keepdaily -gt 0 ]; then btype=daily + elif [ $keepweekly -gt 0 ]; then btype=weekly + elif [ $keepmonthly -gt 0 ]; then btype=monthly + else fatal "keeping no backups"; fi + + if [ "$testuser" != "" ]; then + cd "$srcdir/${user:0:1}" + do_rotate $testuser + setup_remote_dirs $testuser $btype + do_user $testuser $btype + else + [ -d "$srcdir" ] || fatal "directory $srcdir not found." + cd "$srcdir" + for userdir in `ls -d1 */`; do + [ -d "$srcdir/$userdir" ] || fatal "directory $srcdir/$userdir not found." + cd "$srcdir/$userdir" + debug $userdir + for user in `ls -1`; do + [ "$user" != "" ] || continue + debug "$user $userdir" + do_rotate $user $userdir + setup_remote_dirs $user $btype $userdir + do_user $user $btype $userdir + done + done + fi fi end_mux - diff --git a/handlers/makecd.helper.in b/handlers/makecd.helper.in index f83b541..c8a6762 100644 --- a/handlers/makecd.helper.in +++ b/handlers/makecd.helper.in @@ -7,59 +7,59 @@ declare -a makecd_excludes makecd_wizard() { - inputBox "$wizardname" "specify a burner type cd or dvd:" - [ $? = 1 ] && return - burnertype="burnertype = $REPLY" - - booleanBox "$wizardname" "Make iso image only? or burn" - if [ $? = 0 ]; then - isoonly="isoonly = yes" - else - isoonly="isoonly = no" - fi - - # backupdir - inputBox "$wizardname" "Directory where to store the backups:" - [ $? = 1 ] && return - backupdir="backupdir = $REPLY" - - inputBox "$wizardname" "what name to give to the image file?" - [ $? = 1 ] && return - imagefile="imagefile = $REPLY" - - inputBox "$wizardname" "specify a burner device:" - [ $? = 1 ] && return - device="device = $REPLY" - - # target - root of system to be included - inputBox "$wizardname" "root of filesystem for burn:" - [ $? = 1 ] && return - target="target = $REPLY" - - - # excludes - - formBegin "$wizardname: excludes" - for ((i=0; i < ${#makecd_excludes[@]} ; i++)); do - formItem exclude ${makecd_excludes[$i]} - done - formItem exclude - formItem exclude - formItem exclude - formItem exclude - formItem exclude - formItem exclude - formItem exclude - formItem exclude - formItem exclude - formDisplay - [ $? = 1 ] && return; - - unset makecd_excludes - makecd_excludes=($REPLY) - - get_next_filename $configdirectory/20.makecd - cat >> $next_filename <> $next_filename <> $next_filename - done - + for ((j=0; j < ${#makecd_excludes[@]} ; j++)); do + echo "exclude = ${makecd_excludes[$j]}" >> $next_filename + done + chmod 600 $next_filename } diff --git a/handlers/makecd.in b/handlers/makecd.in index 1a95d6d..78e5454 100644 --- a/handlers/makecd.in +++ b/handlers/makecd.in @@ -31,7 +31,7 @@ DVDINFO="/usr/bin/dvd+rw-mediainfo" [ -x "$CDRDAO" ] || debug 3 "echo executable $CDRDAO not present" if [ "$isoonly" == "no" ]; then - [ -e $device ] || fatal "No Burner device available" + [ -e $device ] || fatal "No Burner device available" fi outputfile="$backupdir/$imagefile" @@ -40,7 +40,7 @@ execstr="nice -n $nicelevel $MKISOFS --quiet -R -o $outputfile " str="" # excludes for i in $exclude; do - str=" -x ${i}$str" + str=" -x ${i}$str" done debug 0 "echo $str " @@ -50,39 +50,39 @@ debug 0 "echo $execstr " output=` $execstr 2>&1 ` code=$? if [ "$code" == "0" ]; then - debug $output - info "Successfully finished creation of iso" + debug $output + info "Successfully finished creation of iso" else - warning $output - warning "Failed to create iso" + warning $output + warning "Failed to create iso" fi if [ "$isoonly" == "no" ]; then - if [ "$burnertype" == "cd" ]; then - # burning iso to CD - $CDRECORD -v gracetime=2 dev=$device speed=8 -dao -data $outputfile - code=$? - if [ "$code" == "0" ]; then - debug $output - info "Successfully burned CD" - else - warning $output - warning "Failed to create CD" - fi - fi - if [ "$burnertype" == "dvd" ]; then - # burning iso dvd - $GROWISOFS -speed=2 -Z $device=$outputfile -use-the-force-luke=notray -use-the-force-luke=tty - code=$? - if [ "$code" == "0" ]; then - debug $output - info "Successfully burned DVD" - else - warning $output - warning "Failed to create DVD" - fi - fi + if [ "$burnertype" == "cd" ]; then + # burning iso to CD + $CDRECORD -v gracetime=2 dev=$device speed=8 -dao -data $outputfile + code=$? + if [ "$code" == "0" ]; then + debug $output + info "Successfully burned CD" + else + warning $output + warning "Failed to create CD" + fi + fi + if [ "$burnertype" == "dvd" ]; then + # burning iso dvd + $GROWISOFS -speed=2 -Z $device=$outputfile -use-the-force-luke=notray -use-the-force-luke=tty + code=$? + if [ "$code" == "0" ]; then + debug $output + info "Successfully burned DVD" + else + warning $output + warning "Failed to create DVD" + fi + fi fi return 0 diff --git a/handlers/mysql.helper.in b/handlers/mysql.helper.in index 00eeca0..fb9f11d 100644 --- a/handlers/mysql.helper.in +++ b/handlers/mysql.helper.in @@ -13,43 +13,43 @@ do_mysql_databases() { while [ -z "$REPLY" ]; do formBegin "$mysql_title: databases" formItem "Database:" - formItem "Database:" - formItem "Database:" - formItem "Database:" - formItem "Database:" - formItem "Database:" - formItem "Database:" - formItem "Database:" - formItem "Database:" - formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" formDisplay [ $? = 0 ] || return 1 mysql_databases="databases = " for i in $REPLY; do - [ -n "$i" ] && mysql_databases="$mysql_databases $i" + [ -n "$i" ] && mysql_databases="$mysql_databases $i" done done } do_mysql_password() { - inputBox "$mysql_title" "specify a mysql user:" - [ $? = 1 ] && return - user=$REPLY - inputBox "$mysql_title" "specify the mysql user's password:" - [ $? = 1 ] && return - password=$REPLY - do_mysql_final "dbusername = $user\ndbpassword = $password" + inputBox "$mysql_title" "specify a mysql user:" + [ $? = 1 ] && return + user=$REPLY + inputBox "$mysql_title" "specify the mysql user's password:" + [ $? = 1 ] && return + password=$REPLY + do_mysql_final "dbusername = $user\ndbpassword = $password" } do_mysql_debian() { - _DISABLE_HOTCOPY=yes - do_mysql_final "configfile = /etc/mysql/debian.cnf" + _DISABLE_HOTCOPY=yes + do_mysql_final "configfile = /etc/mysql/debian.cnf" } do_mysql_user() { - inputBox "$mysql_title" "what system user does mysql backup use?" - [ $? = 1 ] && return - do_mysql_final "user = $REPLY" + inputBox "$mysql_title" "what system user does mysql backup use?" + [ $? = 1 ] && return + do_mysql_final "user = $REPLY" } do_mysql_final() { @@ -69,18 +69,18 @@ do_mysql_final() { hotcopy="hotcopy = no" fi - [ $status = 1 ] && return; + [ $status = 1 ] && return; result="$REPLY" compress="compress = no" for opt in $result; do case $opt in - '"sqldump"') sqldump="sqldump = yes";; - '"hotcopy"') hotcopy="hotcopy = yes";; - '"compress"') compress="compress = yes";; + '"sqldump"') sqldump="sqldump = yes";; + '"hotcopy"') hotcopy="hotcopy = yes";; + '"compress"') compress="compress = yes";; esac done get_next_filename $configdirectory/20.mysql - + cat >> $next_filename < (default = all) -# which databases to backup. should either be the word 'all' or a +# which databases to backup. should either be the word 'all' or a # space separated list of database names. $mysql_databases @@ -122,43 +122,43 @@ EOF if [ $host_or_vservers == vservers ] then - cat >> $next_filename <> $next_filename < (no default) -# vsname indicates which vserver to operate on, this is only used if +# vsname indicates which vserver to operate on, this is only used if # vserver is set to yes in /etc/backupninja.conf # NOTE: if you do not specify a vsname the host will be operated on -# alsoNOTE: if operating on a vserver, $VROOTDIR will be +# alsoNOTE: if operating on a vserver, $VROOTDIR will be # prepended to backupdir. EOF echo -e "$mysql_vsname\n" >> $next_filename fi echo -e $@ >> $next_filename - + chmod 600 $next_filename } mysql_wizard() { - + # Global variables mysql_title="MySQL action wizard" - + # backup the host system or a Vserver? choose_host_or_one_vserver "$mysql_title" [ $? = 0 ] || return 1 if [ $host_or_vservers == vservers ] then - do_mysql_vserver - [ $? = 0 ] || return 1 + do_mysql_vserver + [ $? = 0 ] || return 1 fi - + # backupdir if [ $host_or_vservers == vservers ] then - inputBox "$mysql_title" "Directory where to store the backups:`echo \"\n(Relative to chosen vserver's root directory)\"`" "/var/backups/mysql" + inputBox "$mysql_title" "Directory where to store the backups:`echo \"\n(Relative to chosen vserver's root directory)\"`" "/var/backups/mysql" else - inputBox "$mysql_title" "Directory where to store the backups" "/var/backups/mysql" + inputBox "$mysql_title" "Directory where to store the backups" "/var/backups/mysql" fi [ $? = 1 ] && return mysql_backupdir="backupdir = $REPLY" @@ -171,23 +171,23 @@ mysql_wizard() { do_mysql_databases [ $? = 0 ] || return 1 fi - + while true; do _DISABLE_HOTCOPY= menuBoxHelpFile "$mysql_title" "choose a mysql authentication method:" \ - user "change to a linux user first." \ - password "manually specify mysql user and password." \ - debian "use default mysql user debian-sys-maint." + user "change to a linux user first." \ + password "manually specify mysql user and password." \ + debian "use default mysql user debian-sys-maint." status=$? if [ $status = 2 ]; then - # show help. - helptmp="/tmp/backupninja.help.$$" - cat > $helptmp < $helptmp < $mycnf < $mycnf <&1` - code=$? - if [ "$code" == "0" ] - then - debug $output - info "Successfully finished hotcopy of all mysql databases" - else - warning $output - warning "Failed to hotcopy all mysql databases" - fi - fi - else - for db in $databases - do - if [ $usevserver = yes ] - then - execstr="$VSERVER $vsname exec $MYSQLHOTCOPY --allowold $db $hotdir" - else - execstr="$MYSQLHOTCOPY --allowold $db $hotdir" - fi - debug 'su $user -c \"$execstr\"' - if [ ! $test ] - then - output=`su $user -c "$execstr" 2>&1` - code=$? - if [ "$code" == "0" ] - then - debug $output - info "Successfully finished hotcopy of mysql database $db" - else - warning $output - warning "Failed to hotcopy mysql database $db" - fi - fi - done - fi + info "Initializing hotcopy method" + if [ "$databases" == "all" ] + then + if [ $usevserver = yes ] + then + info "dbhost: $dbhost" + execstr="$VSERVER $vsname exec $MYSQLHOTCOPY -h $dbhost --quiet --allowold --regexp /.\*/./.\*/ $hotdir" + else + execstr="$MYSQLHOTCOPY --quiet --allowold --regexp /.\*/./.\*/ $hotdir" + fi + debug "su $user -c \"$execstr\"" + if [ ! $test ] + then + output=`su $user -c "$execstr" 2>&1` + code=$? + if [ "$code" == "0" ] + then + debug $output + info "Successfully finished hotcopy of all mysql databases" + else + warning $output + warning "Failed to hotcopy all mysql databases" + fi + fi + else + for db in $databases + do + if [ $usevserver = yes ] + then + execstr="$VSERVER $vsname exec $MYSQLHOTCOPY --allowold $db $hotdir" + else + execstr="$MYSQLHOTCOPY --allowold $db $hotdir" + fi + debug 'su $user -c \"$execstr\"' + if [ ! $test ] + then + output=`su $user -c "$execstr" 2>&1` + code=$? + if [ "$code" == "0" ] + then + debug $output + info "Successfully finished hotcopy of mysql database $db" + else + warning $output + warning "Failed to hotcopy mysql database $db" + fi + fi + done + fi fi ########################################################################## @@ -224,97 +224,97 @@ fi if [ "$sqldump" == "yes" ] then - info "Initializing SQL dump method" - if [ "$databases" == "all" ] - then - if [ $usevserver = yes ] - then - debug 'echo show databases | $VSERVER $vsname exec su $user -c \"$MYSQL $defaultsfile\" | grep -v Database' - databases=`echo 'show databases' | $VSERVER $vsname exec su $user -c "$MYSQL $defaultsfile" | grep -v Database` - if [ $? -ne 0 ] - then - fatal "Authentication problem, maybe user/password is wrong or mysqld is not running?" - fi - else - databases=$(su $user -c "$MYSQL $defaultsfile -N -B -e 'show databases'" | sed 's/|//g;/\+----/d') - if [ $? -ne 0 ] - then - fatal "Authentication problem, maybe user/password is wrong or mysqld is not running?" - fi - fi - fi + info "Initializing SQL dump method" + if [ "$databases" == "all" ] + then + if [ $usevserver = yes ] + then + debug 'echo show databases | $VSERVER $vsname exec su $user -c \"$MYSQL $defaultsfile\" | grep -v Database' + databases=`echo 'show databases' | $VSERVER $vsname exec su $user -c "$MYSQL $defaultsfile" | grep -v Database` + if [ $? -ne 0 ] + then + fatal "Authentication problem, maybe user/password is wrong or mysqld is not running?" + fi + else + databases=$(su $user -c "$MYSQL $defaultsfile -N -B -e 'show databases'" | sed 's/|//g;/\+----/d') + if [ $? -ne 0 ] + then + fatal "Authentication problem, maybe user/password is wrong or mysqld is not running?" + fi + fi + fi - for db in $databases - do - DUMP_BASE="$MYSQLDUMP $defaultsfile $sqldumpoptions" + for db in $databases + do + DUMP_BASE="$MYSQLDUMP $defaultsfile $sqldumpoptions" - # Dumping structure and data - DUMP="$DUMP_BASE $ignore $db" + # Dumping structure and data + DUMP="$DUMP_BASE $ignore $db" - # If requested, dump only the table structure for this database - if echo "$nodata" | grep -E '(^|[[:space:]])'"$db\." >/dev/null - then - # Get the structure of the tables, without data - DUMP_STRUCT="$DUMP_BASE --no-data $db" - for qualified_table in $nodata - do - table=$( expr match "$qualified_table" "$db\.\([^\w]*\)" ) - DUMP_STRUCT="$DUMP_STRUCT $table" - done - DUMP="( $DUMP; $DUMP_STRUCT )" - fi - if [ $usevserver = yes ] - then - # Test to make sure mysqld is running, if it is not sqldump will not work - $VSERVER $vsname exec su $user -c "$MYSQLADMIN $defaultsfile ping 2>&1 >/dev/null" - if [ $? -ne 0 ]; then - fatal "mysqld doesn't appear to be running!" - fi - if [ "$compress" == "yes" ]; then - execstr="$VSERVER $vsname exec $DUMP | $GZIP > $vroot$dumpdir/${db}.sql.gz" - else - execstr="$VSERVER $vsname exec $DUMP -r $vroot$dumpdir/${db}.sql" - fi - else - # Test to make sure mysqld is running, if it is not sqldump will not work - su $user -c "$MYSQLADMIN $defaultsfile ping 2>&1 >/dev/null" - if [ $? -ne 0 ]; then - fatal "mysqld doesn't appear to be running!" - fi - if [ "$compress" == "yes" ]; then - execstr="$DUMP | $GZIP > $dumpdir/${db}.sql.gz" - else - execstr="$DUMP -r $dumpdir/${db}.sql" - fi - fi - debug "su $user -c \"$execstr\"" - if [ ! $test ] - then - output=`su $user -c "$execstr" 2>&1` - code=$? - if [ "$code" == "0" ] - then - debug $output - info "Successfully finished dump of mysql database $db" - else - warning $output - warning "Failed to dump mysql databases $db" - fi - fi - done + # If requested, dump only the table structure for this database + if echo "$nodata" | grep -E '(^|[[:space:]])'"$db\." >/dev/null + then + # Get the structure of the tables, without data + DUMP_STRUCT="$DUMP_BASE --no-data $db" + for qualified_table in $nodata + do + table=$( expr match "$qualified_table" "$db\.\([^\w]*\)" ) + DUMP_STRUCT="$DUMP_STRUCT $table" + done + DUMP="( $DUMP; $DUMP_STRUCT )" + fi + if [ $usevserver = yes ] + then + # Test to make sure mysqld is running, if it is not sqldump will not work + $VSERVER $vsname exec su $user -c "$MYSQLADMIN $defaultsfile ping 2>&1 >/dev/null" + if [ $? -ne 0 ]; then + fatal "mysqld doesn't appear to be running!" + fi + if [ "$compress" == "yes" ]; then + execstr="$VSERVER $vsname exec $DUMP | $GZIP > $vroot$dumpdir/${db}.sql.gz" + else + execstr="$VSERVER $vsname exec $DUMP -r $vroot$dumpdir/${db}.sql" + fi + else + # Test to make sure mysqld is running, if it is not sqldump will not work + su $user -c "$MYSQLADMIN $defaultsfile ping 2>&1 >/dev/null" + if [ $? -ne 0 ]; then + fatal "mysqld doesn't appear to be running!" + fi + if [ "$compress" == "yes" ]; then + execstr="$DUMP | $GZIP > $dumpdir/${db}.sql.gz" + else + execstr="$DUMP -r $dumpdir/${db}.sql" + fi + fi + debug "su $user -c \"$execstr\"" + if [ ! $test ] + then + output=`su $user -c "$execstr" 2>&1` + code=$? + if [ "$code" == "0" ] + then + debug $output + info "Successfully finished dump of mysql database $db" + else + warning $output + warning "Failed to dump mysql databases $db" + fi + fi + done fi # clean up tmp config file if [ "$dbusername" != "" -a "$dbpassword" != "" ] then - ## clean up tmp config file - debug "rm $mycnf" - rm $mycnf - if [ -f "$tmpcnf" ] - then - debug "mv $tmpcnf $mycnf" - mv $tmpcnf $mycnf - fi + ## clean up tmp config file + debug "rm $mycnf" + rm $mycnf + if [ -f "$tmpcnf" ] + then + debug "mv $tmpcnf $mycnf" + mv $tmpcnf $mycnf + fi fi return 0 diff --git a/handlers/pgsql.helper.in b/handlers/pgsql.helper.in index 8024616..48bf047 100644 --- a/handlers/pgsql.helper.in +++ b/handlers/pgsql.helper.in @@ -13,20 +13,20 @@ do_pgsql_databases() { while [ -z "$REPLY" ]; do formBegin "$pgsql_title: databases" formItem "Database:" - formItem "Database:" - formItem "Database:" - formItem "Database:" - formItem "Database:" - formItem "Database:" - formItem "Database:" - formItem "Database:" - formItem "Database:" - formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" + formItem "Database:" formDisplay [ $? = 0 ] || return 1 pgsql_databases="databases = " for i in $REPLY; do - [ -n "$i" ] && pgsql_databases="$pgsql_databases $i" + [ -n "$i" ] && pgsql_databases="$pgsql_databases $i" done done } @@ -86,14 +86,14 @@ EOF $pgsql_backupdir # databases = < all | db1 db2 db3 > (default = all) -# which databases to backup. should either be the word 'all' or a +# 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. +# if yes, compress the pg_dump/pg_dumpall output. $pgsql_compress ### You can also set the following variables in backupninja.conf: diff --git a/handlers/pgsql.in b/handlers/pgsql.in index f334bf2..b7e4262 100644 --- a/handlers/pgsql.in +++ b/handlers/pgsql.in @@ -36,18 +36,18 @@ if [ $usevserver = yes ]; then debug "Examining vserver '$vsname'." if [ "$databases" == "all" ]; then [ -x "$vroot`$VSERVER $vsname exec which $PGSQLDUMPALL`" ] || \ - fatal "Can't find $PGSQLDUMPALL in vserver $vsname." + fatal "Can't find $PGSQLDUMPALL in vserver $vsname." else [ -x "$vroot`$VSERVER $vsname exec which $PGSQLDUMP`" ] || \ - fatal "Can't find $PGSQLDUMP in vserver $vsname." + fatal "Can't find $PGSQLDUMP in vserver $vsname." fi else if [ "$databases" == "all" ]; then [ -x "`which $PGSQLDUMPALL`" ] || \ - fatal "Can't find $PGSQLDUMPALL." + fatal "Can't find $PGSQLDUMPALL." else [ -x "`which $PGSQLDUMP`" ] || \ - fatal "Can't find $PGSQLDUMP." + fatal "Can't find $PGSQLDUMP." fi fi @@ -64,7 +64,7 @@ else pguid=`getent passwd $PGSQLUSER | @AWK@ -F: '{print $3}'` fi [ -n "$pguid" ] || \ - fatal "No user called $PGSQLUSER`[ $usevserver = no ] || echo \" on vserver $vsname\"`." + fatal "No user called $PGSQLUSER`[ $usevserver = no ] || echo \" on vserver $vsname\"`." debug "chown $pguid $vroot$backupdir" chown $pguid $vroot$backupdir debug "chmod 700 $vroot$backupdir" @@ -72,61 +72,61 @@ chmod 700 $vroot$backupdir # if $databases = all, use pg_dumpall if [ "$databases" == "all" ]; then - if [ $usevserver = yes ]; then - if [ "$compress" == "yes" ]; then - execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMPALL | $GZIP > $backupdir/${vsname}.sql.gz\"" - else - execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMPALL > $backupdir/${vsname}.sql\"" - fi - else - if [ "$compress" == "yes" ]; then - execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL | $GZIP > $backupdir/${localhost}-all.sql.gz\"" - else - execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL > $backupdir/${localhost}-all.sql\"" - fi - fi - debug "$execstr" - if [ ! $test ]; then - output=`eval $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 - + if [ $usevserver = yes ]; then + if [ "$compress" == "yes" ]; then + execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMPALL | $GZIP > $backupdir/${vsname}.sql.gz\"" + else + execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMPALL > $backupdir/${vsname}.sql\"" + fi + else + if [ "$compress" == "yes" ]; then + execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL | $GZIP > $backupdir/${localhost}-all.sql.gz\"" + else + execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL > $backupdir/${localhost}-all.sql\"" + fi + fi + debug "$execstr" + if [ ! $test ]; then + output=`eval $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 = yes ]; then - if [ "$compress" == "yes" ]; then - execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMP $db | $GZIP > $backupdir/${db}.sql.gz\"" - else - execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMP $db | > $backupdir/${db}.sql\"" - fi - else - if [ "$compress" == "yes" ]; then - execstr="su - $PGSQLUSER -c \"$PGSQLDUMP $db | $GZIP > $backupdir/${db}.sql.gz\"" - else - execstr="su - $PGSQLUSER -c \"$PGSQLDUMP $db > $backupdir/${db}.sql\"" - fi - fi - debug "$execstr" - if [ ! $test ]; then - output=`eval $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 + for db in $databases; do + if [ $usevserver = yes ]; then + if [ "$compress" == "yes" ]; then + execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMP $db | $GZIP > $backupdir/${db}.sql.gz\"" + else + execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMP $db | > $backupdir/${db}.sql\"" + fi + else + if [ "$compress" == "yes" ]; then + execstr="su - $PGSQLUSER -c \"$PGSQLDUMP $db | $GZIP > $backupdir/${db}.sql.gz\"" + else + execstr="su - $PGSQLUSER -c \"$PGSQLDUMP $db > $backupdir/${db}.sql\"" + fi + fi + debug "$execstr" + if [ ! $test ]; then + output=`eval $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 return 0 diff --git a/handlers/rdiff.helper.in b/handlers/rdiff.helper.in index 1055280..c673723 100644 --- a/handlers/rdiff.helper.in +++ b/handlers/rdiff.helper.in @@ -18,9 +18,9 @@ do_rdiff_host_includes() { for ((i=0; i < ${#rdiff_includes[@]} ; i++)); do formItem include ${rdiff_includes[$i]} done - formItem include - formItem include - formItem include + formItem include + formItem include + formItem include formDisplay [ $? = 0 ] || return unset rdiff_includes @@ -41,7 +41,7 @@ do_rdiff_vserver() { while [ -z "$REPLY" ]; do formBegin "$rdiff_title - vsincludes (backup these directories from every vserver)" [ -z "$rdiff_vsincludes" ] && rdiff_vsincludes="$rdiff_default_includes" - + for i in $rdiff_vsincludes; do formItem include "$i" done @@ -52,19 +52,19 @@ do_rdiff_vserver() { [ $? = 0 ] || return 1 rdiff_vsincludes=($REPLY) done - + set +o noglob } do_rdiff_excludes() { set -o noglob - formBegin "$rdiff_title: excludes" + formBegin "$rdiff_title: excludes" for ((i=0; i < ${#rdiff_excludes[@]} ; i++)) do formItem exclude ${rdiff_excludes[$i]} done - formItem exclude - formItem exclude + formItem exclude + formItem exclude formDisplay [ $? = 0 ] || return unset rdiff_excludes @@ -102,10 +102,10 @@ do_rdiff_src() { do_rdiff_dest() { declare -a tmp_array - + set -o noglob REPLY= - while [ -z "$REPLY" -o -z "$rdiff_directory" -o -z "$rdiff_host" -o -z "$rdiff_user" ] + while [ -z "$REPLY" -o -z "$rdiff_directory" -o -z "$rdiff_host" -o -z "$rdiff_user" ] do formBegin "$rdiff_title - destination: last three items are required" formItem "keep" "$rdiff_keep" @@ -119,11 +119,11 @@ do_rdiff_dest() { rdiff_keep=${tmp_array[0]} rdiff_directory=${tmp_array[1]} rdiff_host=${tmp_array[2]} - rdiff_user=${tmp_array[3]} + rdiff_user=${tmp_array[3]} rdiff_type=${tmp_array[4]} done set +o noglob - + _dest_done="(DONE)" setDefault conn } @@ -155,7 +155,7 @@ do_rdiff_ssh_con() { echo "Done. hit return to continue" read fi - + ssh -o PreferredAuthentications=publickey $rdiff_host -l $rdiff_user "exit" 2> /dev/null if [ $? -ne 0 ]; then echo "Copying root's public ssh key to authorized_keys of $rdiff_user@$rdiff_host. When prompted, specify the password for user $rdiff_user@$rdiff_host." @@ -171,7 +171,7 @@ do_rdiff_ssh_con() { 1 ) msgBox "$rdiff_title: error" "Connected successfully to $rdiff_user@$rdiff_host, but unable to write. Check ownership and modes of ~$rdiff_user on $rdiff_host." ;; 255 ) msgBox "$rdiff_title: error" "Failed to connect to $rdiff_user@$rdiff_host. Check hostname, username, and password. Also, make sure sshd is running on the destination host." ;; * ) msgBox "$rdiff_title: error" "Unexpected error." ;; - esac + esac return else echo "Done. hit return to continue" @@ -195,20 +195,20 @@ do_rdiff_ssh_con() { else booleanBox "Remote directory does not exist" "The destination backup directory does not exist, do you want me to create it for you?" if [ $? = 0 ]; then - ssh $rdiff_user@$rdiff_host "mkdir -p ${rdiff_directory}" + ssh $rdiff_user@$rdiff_host "mkdir -p ${rdiff_directory}" result=$? case $result in 0) msgBox "$rdiff_title: success" "Creation of the remote destination directory was a success!";; - 1) msgBox "$rdiff_title: error" "Connected successfully to $rdiff_user@$rdiff_host, but was unable to create the destination directory, check the directory permissions." + 1) msgBox "$rdiff_title: error" "Connected successfully to $rdiff_user@$rdiff_host, but was unable to create the destination directory, check the directory permissions." remote_status=failed;; - 255) msgBox "$rdiff_title: error" "Failed to connect to $rdiff_user@$rdiff_host. Check hostname, username, and password. Also, make sure sshd is running on the destination host." + 255) msgBox "$rdiff_title: error" "Failed to connect to $rdiff_user@$rdiff_host. Check hostname, username, and password. Also, make sure sshd is running on the destination host." remote_status=failed;; - *) msgBox "$rdiff_title: error" "Unexpected error." + *) msgBox "$rdiff_title: error" "Unexpected error." remote_status=failed;; esac fi fi - + if [ "$remote_status" = "ok" ]; then do_rdiff_con fi @@ -231,12 +231,12 @@ do_rdiff_con() { echo "Hit return to continue." read case $result in - 0) msgBox "$rdiff_title: success" "Installation of rdiff-backup was a success!" + 0) msgBox "$rdiff_title: success" "Installation of rdiff-backup was a success!" do_rdiff_con;; 1) msgBox "$rdiff_title: error" "Connected successfully to $rdiff_user@$rdiff_host, but was unable to install the package for some reason.";; 255) msgBox "$rdiff_title: error" "Failed to connect to $rdiff_user@$rdiff_host. Check hostname, username, and password. Also, make sure sshd is running on the destination host.";; *) msgBox "$rdiff_title: error" "Unexpected error.";; - esac + esac return fi else @@ -256,9 +256,9 @@ do_rdiff_con() { fi fi else - echo "SUCCESS: Everything looks good!" - echo "Hit return to continue." - read + echo "SUCCESS: Everything looks good!" + echo "Hit return to continue." + read fi _con_done="(DONE)" @@ -298,11 +298,11 @@ EOF set -o noglob for ((i=0; i < ${#rdiff_includes[@]} ; i++)); do echo "include = ${rdiff_includes[$i]}" >> $next_filename - done + done set +o noglob fi - if [ "$host_or_vservers" == vservers -o "$host_or_vservers" == both ]; then + if [ "$host_or_vservers" == vservers -o "$host_or_vservers" == both ]; then cat >> $next_filename <&1`" if [ $? = 0 ]; then - debug $output - info "Removing backups older than $keep days succeeded." + debug $output + info "Removing backups older than $keep days succeeded." else - warning $output - warning "Failed removing backups older than $keep." + warning $output + warning "Failed removing backups older than $keep." fi fi fi -# Add cstream +# Add cstream if [ ! -z $bwlimit ]; then - check_cstream $CSTREAM; - if [ "$desttype" = "remote" ]; then - RDIFFBACKUP="$RDIFFBACKUP --remote-schema 'cstream -t $bwlimit | ssh %s \''rdiff-backup --server\'''" - elif [ "$sourcetype" = "remote" ]; then - RDIFFBACKUP="$RDIFFBACKUP --remote-schema 'ssh %s \''rdiff-backup --server\'' | cstream -t $bwlimit'" - else - fatal "You specified a bandwidth limit but neither your source nor destination types are remote." - fi + check_cstream $CSTREAM; + if [ "$desttype" = "remote" ]; then + RDIFFBACKUP="$RDIFFBACKUP --remote-schema 'cstream -t $bwlimit | ssh %s \''rdiff-backup --server\'''" + elif [ "$sourcetype" = "remote" ]; then + RDIFFBACKUP="$RDIFFBACKUP --remote-schema 'ssh %s \''rdiff-backup --server\'' | cstream -t $bwlimit'" + else + fatal "You specified a bandwidth limit but neither your source nor destination types are remote." + fi fi ### EXECUTE ### @@ -212,7 +212,7 @@ for i in $exclude; do str="${i//__star__/*}" execstr="${execstr}--exclude '$str' " done -# includes +# includes for i in $include; do [ "$i" != "/" ] || fatal "Sorry, you cannot use 'include = /'" str="${i//__star__/*}" @@ -223,10 +223,10 @@ done if [ $usevserver = yes ]; then for vserver in $vsnames; do for vi in $vsinclude; do - str="${vi//__star__/*}" - str="$VROOTDIR/$vserver$str" + str="${vi//__star__/*}" + str="$VROOTDIR/$vserver$str" if [ -n "$str" ]; then - execstr="${execstr}--include '$str' " + execstr="${execstr}--include '$str' " else warning "vsinclude statement '${vi//__star__/*}' will be ignored for VServer $vserver. $symlinks_warning" fi @@ -238,20 +238,20 @@ set +o noglob # exclude everything else [ "$include" != "" -o "$vsinclude" != "" ] && execstr="${execstr}--exclude '/*' " - + # include client-part and server-part execstr="${execstr}$execstr_sourcepart $execstr_destpart" debug "$execstr" if [ $test = 0 ]; then - output=`nice -n $nicelevel su -c "$execstr" 2>&1` - if [ $? = 0 ]; then - debug $output - info "Successfully finished backing up source $label" - else - warning $output - warning "Failed backup up source $label" - fi -fi + output=`nice -n $nicelevel su -c "$execstr" 2>&1` + if [ $? = 0 ]; then + debug $output + info "Successfully finished backing up source $label" + else + warning $output + warning "Failed backup up source $label" + fi +fi return 0 diff --git a/handlers/rsync.in b/handlers/rsync.in index 9baa2f2..9e5e4f9 100644 --- a/handlers/rsync.in +++ b/handlers/rsync.in @@ -102,40 +102,40 @@ getconf service function rotate { - if [[ "$2" < 4 ]]; then - error "Rotate: minimum of 4 rotations" - exit 1 - fi - - if [ -d $1.$2 ]; then - $nice $mv /$1.$2 /$1.tmp - fi - - for ((n=`echo "$2 - 1" | bc`; n >= 0; n--)); do - if [ -d $1.$n ]; then - dest=`echo "$n + 1" | bc` - $nice $mv /$1.$n /$1.$dest - $touch /$1.$dest - fi - done - - if [ -d $1.tmp ]; then - $nice $mv /$1.tmp /$1.0 - fi - - if [ -d $1.1 ]; then - $nice $cp -alf /$1.1/. /$1.0 - fi + if [[ "$2" < 4 ]]; then + error "Rotate: minimum of 4 rotations" + exit 1 + fi + + if [ -d $1.$2 ]; then + $nice $mv /$1.$2 /$1.tmp + fi + + for ((n=`echo "$2 - 1" | bc`; n >= 0; n--)); do + if [ -d $1.$n ]; then + dest=`echo "$n + 1" | bc` + $nice $mv /$1.$n /$1.$dest + $touch /$1.$dest + fi + done + + if [ -d $1.tmp ]; then + $nice $mv /$1.tmp /$1.0 + fi + + if [ -d $1.1 ]; then + $nice $cp -alf /$1.1/. /$1.0 + fi } function move_files { - ref=$tmp/makesnapshot-mymv-$$; - $touch -r $1 $ref; - $mv $1 $2; - $touch -r $ref $2; - $rm $ref; + ref=$tmp/makesnapshot-mymv-$$; + $touch -r $1 $ref; + $mv $1 $2; + $touch -r $ref $2; + $rm $ref; } @@ -143,54 +143,54 @@ backupdir="$mountpoint/$backupdir" # does $backupdir exists? -if [ ! -d "$backupdir" ]; then - error "Backupdir $backupdir does not exist" - exit 1 +if [ ! -d "$backupdir" ]; then + error "Backupdir $backupdir does not exist" + exit 1 fi # setup number of increments if [ -z "$days" ]; then - keep="4" + keep="4" else - keep="`echo $days - 1 | bc -l`" + keep="`echo $days - 1 | bc -l`" fi # lockfile setup if [ ! -z "$lockfile" ]; then - $touch $lockfile || warning "Could not create lockfile $lockfile" + $touch $lockfile || warning "Could not create lockfile $lockfile" fi # nicelevel setup -if [ ! -z "$nicelevel" ]; then - nice="nice -n $nicelevel" -else - nice="" +if [ ! -z "$nicelevel" ]; then + nice="nice -n $nicelevel" +else + nice="" fi # connection test if [ "$from" == "remote" ] && [ "$testconnect" == "yes" ]; then - debug "$ssh -o PasswordAuthentication=no $user@$host 'echo -n 1'" - result=`ssh -o PasswordAuthentication=no $user@$host 'echo -n 1'` - if [ "$result" != "1" ]; then - fatal "Can't connect to $host as $user." - else - debug "Connected to $srchost successfully" - fi + debug "$ssh -o PasswordAuthentication=no $user@$host 'echo -n 1'" + result=`ssh -o PasswordAuthentication=no $user@$host 'echo -n 1'` + if [ "$result" != "1" ]; then + fatal "Can't connect to $host as $user." + else + debug "Connected to $srchost successfully" + fi fi # rsync options for local sources if [ "$from" == "local" ]; then - rsync_local_options="$rsync_options" + rsync_local_options="$rsync_options" - if [ ! -z "$numericids" ]; then - rsync_local_options="$rsync_local_options --numeric-ids " - fi + if [ ! -z "$numericids" ]; then + rsync_local_options="$rsync_local_options --numeric-ids " + fi fi @@ -198,41 +198,41 @@ fi if [ "$from" == "remote" ]; then - rsync_remote_options="$rsync_options --rsync-path=$remote_rsync" + rsync_remote_options="$rsync_options --rsync-path=$remote_rsync" - if [ "$compress" == "1" ]; then - rsync_remote_options="$rsync_remote_options --compress" - fi + if [ "$compress" == "1" ]; then + rsync_remote_options="$rsync_remote_options --compress" + fi - if [ ! -z "$bandwidthlimit" ]; then - rsync_remote_options="$rsync_remote_options --bwlimit=$bandwidthlimit" - fi + if [ ! -z "$bandwidthlimit" ]; then + rsync_remote_options="$rsync_remote_options --bwlimit=$bandwidthlimit" + fi - if [ ! -z "$numericids" ]; then - rsync_remote_options="$rsync_remote_options --numeric-ids" - fi + if [ ! -z "$numericids" ]; then + rsync_remote_options="$rsync_remote_options --numeric-ids" + fi fi # set mv procedure if [ $enable_mv_timestamp_bug == "yes" ]; then - mv=move_files + mv=move_files fi # set excludes for path in $exclude; do - EXCLUDES="$EXCLUDES --exclude=$path" + EXCLUDES="$EXCLUDES --exclude=$path" done # stop services if [ ! -z "$service" ]; then - for daemon in $service; do - info "Stopping service $daemon..." - $initscripts/$daemon stop - done + for daemon in $service; do + info "Stopping service $daemon..." + $initscripts/$daemon stop + done fi echo "Starting backup at `date`" >> $log @@ -240,110 +240,110 @@ echo "Starting backup at `date`" >> $log # mount backup destination folder as read-write if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then - if [ -d "$mountpoint" ]; then - mount -o remount,rw $mountpoint - if (($?)); then - error "Could not mount $mountpoint" - exit 1 - fi - fi + if [ -d "$mountpoint" ]; then + mount -o remount,rw $mountpoint + if (($?)); then + error "Could not mount $mountpoint" + exit 1 + fi + fi fi # add vservers to included folders if [ "$vservers_are_available" == "yes" ]; then - # sane permission on backup - mkdir -p $backupdir/$VROOTDIR - chmod 000 $backupdir/$VROOTDIR - - for candidate in $found_vservers; do - candidate="`basename $candidate`" - found_excluded_vserver="0" - for excluded_vserver in $exclude_vserver; do - if [ "$excluded_vserver" == "$candidate" ]; then - found_excluded_vserver="1" - break + # sane permission on backup + mkdir -p $backupdir/$VROOTDIR + chmod 000 $backupdir/$VROOTDIR + + for candidate in $found_vservers; do + candidate="`basename $candidate`" + found_excluded_vserver="0" + for excluded_vserver in $exclude_vserver; do + if [ "$excluded_vserver" == "$candidate" ]; then + found_excluded_vserver="1" + break + fi + done + if [ "$found_excluded_vserver" == "0" ]; then + include="$include $VROOTDIR/$candidate" fi - done - if [ "$found_excluded_vserver" == "0" ]; then - include="$include $VROOTDIR/$candidate" - fi - done + done fi # the backup procedure for SECTION in $include; do - section="`basename $SECTION`" - - if [ ! -d "$backupdir/$SECTION/$section.0" ]; then - mkdir -p $backupdir/$SECTION/$section.0 - fi - - info "Rotating $backupdir/$SECTION/$section..." - echo "Rotating $backupdir/$SECTION/$section..." >> $log - rotate $backupdir/$SECTION/$section $keep - info "Syncing $SECTION on $backupdir/$SECTION/$section.0..." - - if [ "$from" == "local" ]; then - debug $rsync $rsync_local_options $EXCLUDES /$SECTION/ $backupdir/$SECTION/$section.0/ - $nice $rsync $rsync_local_options $EXCLUDES /$SECTION/ $backupdir/$SECTION/$section.0/ >> $log - if [ "$?" != "0" ]; then - warning "Rsync error when trying to transfer $SECTION" - fi - elif [ "$from" == "remote" ]; then - if [ -z "$user" ] || [ -z "$host" ]; then - error "Config file error: either user or host was not specified" - exit 1 - else - debug $nice $rsync $rsync_remote_options $EXCLUDES -e "$ssh" $user@$host:/$SECTION/ $backupdir/$SECTION/$section.0 - $nice $rsync $rsync_remote_options $EXCLUDES -e "$ssh" $user@$host:/$SECTION/ $backupdir/$SECTION/$section.0 >> $log + section="`basename $SECTION`" + + if [ ! -d "$backupdir/$SECTION/$section.0" ]; then + mkdir -p $backupdir/$SECTION/$section.0 + fi + + info "Rotating $backupdir/$SECTION/$section..." + echo "Rotating $backupdir/$SECTION/$section..." >> $log + rotate $backupdir/$SECTION/$section $keep + info "Syncing $SECTION on $backupdir/$SECTION/$section.0..." + + if [ "$from" == "local" ]; then + debug $rsync $rsync_local_options $EXCLUDES /$SECTION/ $backupdir/$SECTION/$section.0/ + $nice $rsync $rsync_local_options $EXCLUDES /$SECTION/ $backupdir/$SECTION/$section.0/ >> $log if [ "$?" != "0" ]; then - warning "Rsync error when trying to transfer $SECTION" + warning "Rsync error when trying to transfer $SECTION" + fi + elif [ "$from" == "remote" ]; then + if [ -z "$user" ] || [ -z "$host" ]; then + error "Config file error: either user or host was not specified" + exit 1 + else + debug $nice $rsync $rsync_remote_options $EXCLUDES -e "$ssh" $user@$host:/$SECTION/ $backupdir/$SECTION/$section.0 + $nice $rsync $rsync_remote_options $EXCLUDES -e "$ssh" $user@$host:/$SECTION/ $backupdir/$SECTION/$section.0 >> $log + if [ "$?" != "0" ]; then + warning "Rsync error when trying to transfer $SECTION" + fi fi - fi - else - error "Invalid source $from" - exit 1 - fi + else + error "Invalid source $from" + exit 1 + fi - $touch $backupdir/$SECTION/$section.0 + $touch $backupdir/$SECTION/$section.0 done # remount backup destination as read-only if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then - mount -o remount,ro $mountpoint + mount -o remount,ro $mountpoint fi # check partition for errors if [ "$fscheck" == "1" ] || [ "$fscheck" == "yes" ]; then - umount $mountpoint - if (($?)); then - warning "Could not umount $mountpoint to run fsck" - else - $nice $fsck -v -y $partition >> $log - mount $mountpoint - fi + umount $mountpoint + if (($?)); then + warning "Could not umount $mountpoint to run fsck" + else + $nice $fsck -v -y $partition >> $log + mount $mountpoint + fi fi # restart services if [ ! -z "$service" ]; then - for daemon in $service; do - info "Starting service $daemon..." - $initscripts/$daemon start - done + for daemon in $service; do + info "Starting service $daemon..." + $initscripts/$daemon start + done fi # removes the lockfile if [ ! -z "$lockfile" ]; then - $rm $lockfile || warning "Could not remove lockfile $lockfile" + $rm $lockfile || warning "Could not remove lockfile $lockfile" fi echo "Finnishing backup at `date`" >> $log diff --git a/handlers/sh.in b/handlers/sh.in index f9f1926..4edfd9a 100644 --- a/handlers/sh.in +++ b/handlers/sh.in @@ -2,6 +2,6 @@ # # shell script handler for backupninja # runs the file /etc/backup.d/scriptname.sh -# +# [ $test ] || ( . $1 ) diff --git a/handlers/svn.in b/handlers/svn.in index d19b0b8..97d1701 100644 --- a/handlers/svn.in +++ b/handlers/svn.in @@ -7,7 +7,7 @@ getconf src /var/lib/svn getconf dest /var/backups/svn getconf tmp /var/backups/svn.tmp getconf HOTBACKUP "/usr/bin/svnadmin hotcopy" -getconf vsname +getconf vsname error=0 @@ -35,43 +35,43 @@ fi cd $vroot$src for repo in `find . -name svnserve.conf` do - repo=`dirname $repo` - repo=`dirname $repo` + repo=`dirname $repo` + repo=`dirname $repo` - ret=`mkdir -p $vroot$tmp/$repo 2>&1` - code=$? - if [ "$ret" ]; then - debug "$ret" - fi - if [ $code != 0 ]; then - error "command failed mkdir -p $vroot$tmp/$repo" - fi + ret=`mkdir -p $vroot$tmp/$repo 2>&1` + code=$? + if [ "$ret" ]; then + debug "$ret" + fi + if [ $code != 0 ]; then + error "command failed mkdir -p $vroot$tmp/$repo" + fi - if [ $usevserver = yes ] - then - ret=`$VSERVER $vsname exec $HOTBACKUP $src/$repo $tmp/$repo 2>&1` - else - ret=`$HOTBACKUP $src/$repo $tmp/$repo 2>&1` - fi - code=$? - if [ "$ret" ]; then - debug "$ret" - fi - if [ $code != 0 ]; then - error "command failed -- $HOTBACKUP $vroot$src/$repo $vroot$tmp/$repo" - error=1 - fi + if [ $usevserver = yes ] + then + ret=`$VSERVER $vsname exec $HOTBACKUP $src/$repo $tmp/$repo 2>&1` + else + ret=`$HOTBACKUP $src/$repo $tmp/$repo 2>&1` + fi + code=$? + if [ "$ret" ]; then + debug "$ret" + fi + if [ $code != 0 ]; then + error "command failed -- $HOTBACKUP $vroot$src/$repo $vroot$tmp/$repo" + error=1 + fi done if [ $error -eq 1 ]; then - echo "Error: because of earlier errors, we are leaving svn backups in $vroot$tmp instead of $vroot$dest" + echo "Error: because of earlier errors, we are leaving svn backups in $vroot$tmp instead of $vroot$dest" else - if [ -d $vroot$dest -a -d $vroot$tmp ]; then - rm -rf $vroot$dest - fi - if [ -d $vroot$tmp ]; then - mv $vroot$tmp $vroot$dest - fi + if [ -d $vroot$dest -a -d $vroot$tmp ]; then + rm -rf $vroot$dest + fi + if [ -d $vroot$tmp ]; then + mv $vroot$tmp $vroot$dest + fi fi exit 0 diff --git a/handlers/sys.helper.in b/handlers/sys.helper.in index c5892a9..c823712 100644 --- a/handlers/sys.helper.in +++ b/handlers/sys.helper.in @@ -5,13 +5,13 @@ HELPERS="$HELPERS sys:general_hardware_and_system_info" sys_wizard() { require_packages hwinfo debconf-utils checkBox "new sys action" "check options" \ - "packages" "list of all installed packages." on \ - "partitions" "the partition table of all disks." on \ - "sfdisk" "use sfdisk to get partition information." on \ - "hardware" "detailed hardware information" on \ - "luksheaders" "Luks headers of all Luks partitions." off \ - "lvm" "LVM metadata for all volume groups." off - [ $? = 1 ] && return; + "packages" "list of all installed packages." on \ + "partitions" "the partition table of all disks." on \ + "sfdisk" "use sfdisk to get partition information." on \ + "hardware" "detailed hardware information" on \ + "luksheaders" "Luks headers of all Luks partitions." off \ + "lvm" "LVM metadata for all volume groups." off + [ $? = 1 ] && return; result="$REPLY" packages="packages = no" partitions="partitions = no" @@ -21,12 +21,12 @@ sys_wizard() { lvm="lvm = no" for opt in $result; do case $opt in - '"packages"') packages="packages = yes";; - '"partitions"') partitions="partitions = yes";; - '"sfdisk"') sfdisk="dosfdisk = yes";; - '"hardware"') hardware="hardware = yes";; - '"luksheaders"') luksheaders="luksheaders = yes";; - '"lvm"') lvm="lvm = yes";; + '"packages"') packages="packages = yes";; + '"partitions"') partitions="partitions = yes";; + '"sfdisk"') sfdisk="dosfdisk = yes";; + '"hardware"') hardware="hardware = yes";; + '"luksheaders"') luksheaders="luksheaders = yes";; + '"lvm"') lvm="lvm = yes";; esac done get_next_filename $configdirectory/10.sys diff --git a/handlers/sys.in b/handlers/sys.in index e6cb273..2ab5871 100755 --- a/handlers/sys.in +++ b/handlers/sys.in @@ -11,17 +11,17 @@ # (2) a list of all the packages installed and removed. # this file can be used to restore the state of installed packages # by running "dpkg --set-selections < dpkg-selections.txt and -# then run "apt-get -u dselect-upgrade". If you have the +# then run "apt-get -u dselect-upgrade". If you have the # debconf-set-selections file from (1), you should restore those first. -# -# (3) the partition table of all disks. +# +# (3) the partition table of all disks. # this partition table can be used to format another disk of -# the same size. this can be handy if using software raid and +# the same size. this can be handy if using software raid and # you have a disk go bad. just replace the disk and partition it # by running "sfdisk /dev/sdb < partitions.sdb.txt" # (MAKE SURE YOU PARTITION THE CORRECT DISK!!!) # -# (4) hardware information. +# (4) hardware information. # write to a text file the important things which hwinfo can gleen. # # (5) the Luks header of every Luks block device, if option luksheaders @@ -55,7 +55,7 @@ getconf dohwinfo yes if [ ! -d $parentdir ]; then mkdir -p $parentdir fi - + if [ $os = "debian" ] then getconf packagesfile $parentdir/dpkg-selections.txt @@ -65,9 +65,9 @@ then getconf debconfgetselections `which debconf-get-selections` elif [ $os = "redhat" ] then - getconf packagesfile $parentdir/rpmpackages.txt - getconf packagemgr `which rpm` - getconf packagemgroptions ' -qa ' + getconf packagesfile $parentdir/rpmpackages.txt + getconf packagemgr `which rpm` + getconf packagemgroptions ' -qa ' getconf SYSREPORT `which sysreport` getconf sysreport_options ' -norpm ' @@ -163,7 +163,7 @@ if [ "$packages" == "yes" ]; then # don't expand * since it can be used in $packagemgroptions set -o noglob debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile" - $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile" + $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile" set +o noglob fi # is $debconfgetselections available inside $vserver ? @@ -184,9 +184,9 @@ if [ "$packages" == "yes" ]; then unset found done fi - + # We want to perform this on the host as well - if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then + if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then warning "can't find ${packagemgr}, skipping installed packages report." else # don't expand * since it can be used in $packagemgroptions @@ -235,7 +235,7 @@ catiffile () { done fi echo $DASHES >> $sysreportfile -} +} catifexec () { if [ -x $1 ]; then @@ -245,12 +245,12 @@ catifexec () { $* >> $sysreportfile 2>&1 || info "executing of $1 failed" fi } - + STATUS="Determining $os version:" catiffile $osversion -STATUS="Determinding your current hostname: " +STATUS="Determinding your current hostname: " catifexec "/bin/hostname" STATUS="Getting the date:" @@ -272,17 +272,17 @@ if [ $os = "redhat" ]; then catiffile "/bin/ls /etc/rc.d/rc*.d/" elif [ $os = "debian" ]; then - for level in 0 1 2 3 4 5 6 S; do - echo "Level: $level" >> $sysreportfile - for f in /etc/rc${level}.d/*; do - # Remove /etc/Knn or Snn from beginning - ff=$(echo $f | @SED@ 's_/etc/rc..d/[KS][0-9][0-9]__') - if [ $f != $ff ]; then - echo $ff >> $sysreportfile - fi - done - echo "" >> $sysreportfile - done + for level in 0 1 2 3 4 5 6 S; do + echo "Level: $level" >> $sysreportfile + for f in /etc/rc${level}.d/*; do + # Remove /etc/Knn or Snn from beginning + ff=$(echo $f | @SED@ 's_/etc/rc..d/[KS][0-9][0-9]__') + if [ $f != $ff ]; then + echo $ff >> $sysreportfile + fi + done + echo "" >> $sysreportfile + done fi STATUS="Getting bootloader information:" @@ -291,34 +291,34 @@ catifexec "/bin/ls" "-alR /boot" # This covers sparc, alpha, and intel (respectively) # updated for grub -mpg if [ -f /etc/silo.conf ]; then - STATUS="Collecting information about the boot process (silo):" - catiffile "/etc/silo.conf" + STATUS="Collecting information about the boot process (silo):" + catiffile "/etc/silo.conf" fi if [ -f /etc/milo.conf ]; then - STATUS="Collecting information about the boot process (milo):" - catiffile "/etc/milo.conf" + STATUS="Collecting information about the boot process (milo):" + catiffile "/etc/milo.conf" fi if [ -f /etc/lilo.conf ]; then - STATUS="Collecting information about the boot process (lilo):" - catiffile "/etc/lilo.conf" - catifexec "/sbin/lilo" "-q" + STATUS="Collecting information about the boot process (lilo):" + catiffile "/etc/lilo.conf" + catifexec "/sbin/lilo" "-q" fi if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then - STATUS="Collecting information about the boot process (grub.conf):" - catiffile "/boot/grub/grub.conf" - STATUS="Collecting information about the boot process (grub.map):" - catiffile "/boot/grub/device.map" + STATUS="Collecting information about the boot process (grub.conf):" + catiffile "/boot/grub/grub.conf" + STATUS="Collecting information about the boot process (grub.map):" + catiffile "/boot/grub/device.map" fi if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then - STATUS="Gathering information on cluster setup" - # 2.1 AS - if [ -f /etc/cluster.conf ] ; then - catiffile "/etc/cluster.conf" - fi - # Taroon - if [ -f /etc/cluster.xml ] ; then - catiffile "/etc/cluster.xml" - fi + STATUS="Gathering information on cluster setup" + # 2.1 AS + if [ -f /etc/cluster.conf ] ; then + catiffile "/etc/cluster.conf" + fi + # Taroon + if [ -f /etc/cluster.xml ] ; then + catiffile "/etc/cluster.xml" + fi fi STATUS="Gathering sysctl information (sysctl -a):" @@ -349,10 +349,10 @@ STATUS="Getting kernel version:" catifexec "/bin/uname" "-a" STATUS="Checking module information:" catifexec "/sbin/lsmod" -for x in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null +for x in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null ) ; do - STATUS="Checking module information $x:" - catifexec "/sbin/modinfo" "$x" + STATUS="Checking module information $x:" + catifexec "/sbin/modinfo" "$x" done STATUS="Gathering information about your filesystems:" @@ -375,27 +375,27 @@ STATUS="Collecting information regarding kernel modules" VER=`uname -r` catiffile "/lib/modules/$VER/modules.dep" if [ -f /etc/conf.modules ]; then - STATUS="Collecting information regarding kernel modules (conf.modules)" - catiffile "/etc/conf.modules" + STATUS="Collecting information regarding kernel modules (conf.modules)" + catiffile "/etc/conf.modules" fi if [ -f /etc/modules.conf ]; then - STATUS="Collecting information regarding kernel modules (modules.conf)" - catiffile "/etc/modules.conf" + STATUS="Collecting information regarding kernel modules (modules.conf)" + catiffile "/etc/modules.conf" fi if [ -f /etc/modprobe.conf ]; then - STATUS="Collecting information regarding kernel modules (modeprobe.conf)" - catiffile "/etc/modprobe.conf" + STATUS="Collecting information regarding kernel modules (modeprobe.conf)" + catiffile "/etc/modprobe.conf" fi # dkms status if [ -x /usr/sbin/dkms ] ; then STATUS="Gathering current status of modules, versions and kernels (dkms):" - catifexec "/usr/sbin/dkms" "status" + catifexec "/usr/sbin/dkms" "status" fi if [ -f /etc/sysconfig/isdncard ] ; then - STATUS="Gathering information about ISDN:" - catiffile "/etc/sysconfig/isdncard" + STATUS="Gathering information about ISDN:" + catiffile "/etc/sysconfig/isdncard" fi STATUS="Collecting information from the proc directory:" @@ -481,18 +481,18 @@ fi STATUS="Collecting device-mapper (dm) information:" catifexec '/sbin/dmsetup' 'info' - + STATUS="Collecting SCSI Tape information (/etc/stinit.def)" catiffile "/etc/stinit.def" if [ -x /sbin/lsusb ] ; then - STATUS="Collecting USB devices list (lsusb):" - catifexec "/sbin/lsusb" + STATUS="Collecting USB devices list (lsusb):" + catifexec "/sbin/lsusb" fi if [ -x /usr/bin/lshal ] ; then - STATUS="Collecting global devices list (lshal):" - catifexec "/usr/bin/lshal" + STATUS="Collecting global devices list (lshal):" + catifexec "/usr/bin/lshal" fi @@ -511,24 +511,24 @@ fi if [ "$partitions" == "yes" ]; then if [ "$dosfdisk" == "yes" ]; then - if [ ! -x "$SFDISK" ]; then - warning "can't find sfdisk, skipping sfdisk report." - partitions="no" - fi + if [ ! -x "$SFDISK" ]; then + warning "can't find sfdisk, skipping sfdisk report." + partitions="no" + fi fi if [ "$dohwinfo" == "yes" ]; then - if [ ! -x "$HWINFO" ]; then - warning "can't find hwinfo, skipping partition report." - partitions="no" - fi + if [ ! -x "$HWINFO" ]; then + warning "can't find hwinfo, skipping partition report." + partitions="no" + fi fi fi if [ "$hardware" == "yes" ]; then - if [ ! -x "$HWINFO" ]; then - warning "can't find hwinfo, skipping hardware report." - hardware="no" - fi + if [ ! -x "$HWINFO" ]; then + warning "can't find hwinfo, skipping hardware report." + hardware="no" + fi fi ## HARDWARE ############################# @@ -536,47 +536,47 @@ fi # # here we use hwinfo to dump a table listing all the # information we can find on the hardware of this machine -# +# if [ "$hardware" == "yes" ]; then if [ "dohwinfo" == "yes" ]; then if [ -f $hardwarefile ]; then - rm $hardwarefile + rm $hardwarefile fi touch $hardwarefile echo -e "\n\n====================== summary ======================\n" >> $hardwarefile debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile" $HWINFO --short --cpu --network --disk --pci >> $hardwarefile for flag in cpu network bios pci; do - echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile - $HWINFO --$flag >> $hardwarefile + echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile + $HWINFO --$flag >> $hardwarefile done fi fi ## PARTITIONS ############################# -# here we use sfdisk to dump a listing of all the partitions. +# here we use sfdisk to dump a listing of all the partitions. # these files can be used to directly partition a disk of the same size. if [ "$partitions" == "yes" ]; then if [ "$dosfdisk" == "yes" ]; then devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1` - if [ "$devices" == "" ]; then - warning "No harddisks found" - fi - for dev in $devices; do - debug "$SFDISK will try to backup partition tables for device $dev" - [ -b $dev ] || continue - label=${dev#/dev/} - label=${label//\//-} - outputfile=${partitionsfile//__star__/$label} - debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null" - $SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null - if [ $? -ne 0 ]; then - warning "The partition table for $dev could not be saved." - fi - done + if [ "$devices" == "" ]; then + warning "No harddisks found" + fi + for dev in $devices; do + debug "$SFDISK will try to backup partition tables for device $dev" + [ -b $dev ] || continue + label=${dev#/dev/} + label=${label//\//-} + outputfile=${partitionsfile//__star__/$label} + debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null" + $SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null + if [ $? -ne 0 ]; then + warning "The partition table for $dev could not be saved." + fi + done fi if [ "$dohwinfo" == "yes" ]; then debug "Using $HWINFO to get all available disk information" @@ -639,8 +639,8 @@ function doLvmBackup () { fi fi if [ ! -w "$lvmdir" ]; then - echo "can not write to directory $lvmdir" - return 2 + echo "can not write to directory $lvmdir" + return 2 fi debug "Let's try to gather the list of LVM volume groups" debug "$VGS --options vg_name --noheadings | @SED@ 's/^[ ]*//' | @SED@ 's/[ ]*$//' | tr '\n' ' '" diff --git a/handlers/tar.helper.in b/handlers/tar.helper.in index cc9a89b..2665382 100644 --- a/handlers/tar.helper.in +++ b/handlers/tar.helper.in @@ -14,7 +14,7 @@ tar_wizard() { inputBox "$tar_title" "\"Name\" of backups" "$backupname" [ $? = 1 ] && return tar_backupname="backupname = $REPLY" - backupname="$REPLY" + backupname="$REPLY" inputBox "$tar_title" "Directory where to store the backups" "/net/backups/$backupname" [ $? = 1 ] && return @@ -24,8 +24,8 @@ tar_wizard() { "none" "do not filter trough" off \ "compress" "filter trough compress" off \ "gzip" "filter trough gzip" off \ - "bzip" "filter trough bzip" on - [ $? = 1 ] && return; + "bzip" "filter trough bzip" on + [ $? = 1 ] && return; result="$REPLY" tar_compress="compress = $REPLY " @@ -47,14 +47,14 @@ tar_wizard() { [ $? = 0 ] || return 1 tar_includes="includes = " for i in $REPLY; do - [ -n "$i" ] && tar_includes="$tar_includes $i" + [ -n "$i" ] && tar_includes="$tar_includes $i" done done REPLY= while [ -z "$REPLY" ]; do formBegin "$tar_title: Excludes" - formItem "Exclude:" /tmp + formItem "Exclude:" /tmp formItem "Exclude:" /proc formItem "Exclude:" /sys formItem "Exclude:" /dev @@ -63,17 +63,17 @@ tar_wizard() { formItem "Exclude:" /misc formItem "Exclude:" /net formItem "Exclude:" /selinux - formItem "Exclude:" + formItem "Exclude:" formItem "Exclude:" formDisplay [ $? = 0 ] || return 1 tar_excludes="excludes = " for i in $REPLY; do - [ -n "$i" ] && tar_excludes="$tar_excludes $i" + [ -n "$i" ] && tar_excludes="$tar_excludes $i" done done -# Save the config +# Save the config get_next_filename $configdirectory/10.tar cat > $next_filename < "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.list \ 2> "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.err -[ $? -ne 0 ] && fatal "Tar backup failed" +[ $? -ne 0 ] && fatal "Tar backup failed" diff --git a/handlers/trac.in b/handlers/trac.in index a4b7bdf..f387d42 100644 --- a/handlers/trac.in +++ b/handlers/trac.in @@ -12,39 +12,38 @@ getconf tmp /var/backups/trac.tmp cd $src for repo in `find . -name VERSION` do - - repo=`dirname $repo` - if [ "$repo" == "." ] - then - repo="" - fi - - # Just make the parent directory for $tmp/$repo - parentdir=`dirname $tmp/$repo` - ret=`mkdir -p $parentdir 2>&1` - code=$? - if [ "$ret" ]; then - debug "$ret" - fi - if [ $code != 0 ]; then - error "command failed mkdir -p $parentdir" - fi - - ret=`trac-admin $src/$repo hotcopy $tmp/$repo 2>&1` - code=$? - if [ "$ret" ]; then - debug "$ret" - fi - if [ $code != 0 ]; then - error "command failed -- trac-admin $src/$repo hotcopy $tmp/$repo" - fi + repo=`dirname $repo` + if [ "$repo" == "." ] + then + repo="" + fi + + # Just make the parent directory for $tmp/$repo + parentdir=`dirname $tmp/$repo` + ret=`mkdir -p $parentdir 2>&1` + code=$? + if [ "$ret" ]; then + debug "$ret" + fi + if [ $code != 0 ]; then + error "command failed mkdir -p $parentdir" + fi + + ret=`trac-admin $src/$repo hotcopy $tmp/$repo 2>&1` + code=$? + if [ "$ret" ]; then + debug "$ret" + fi + if [ $code != 0 ]; then + error "command failed -- trac-admin $src/$repo hotcopy $tmp/$repo" + fi done if [ -d $dest -a -d $tmp ]; then - rm -rf $dest + rm -rf $dest fi if [ -d $tmp ]; then - mv $tmp $dest + mv $tmp $dest fi exit 0 diff --git a/handlers/wget b/handlers/wget index 51054ea..0c363eb 100644 --- a/handlers/wget +++ b/handlers/wget @@ -77,84 +77,82 @@ getconf folder function rotate { - if [[ "$2" < 4 ]]; then - error "Rotate: minimum of 4 rotations" - exit 1 - fi - - if [ -d $1.$2 ]; then - $nice $mv /$1.$2 /$1.tmp - fi - - for ((n=`echo "$2 - 1" | bc`; n >= 0; n--)); do - if [ -d $1.$n ]; then - dest=`echo "$n + 1" | bc` - $nice $mv /$1.$n /$1.$dest - $touch /$1.$dest - fi - done - - if [ -d $1.tmp ]; then - $nice $mv /$1.tmp /$1.0 - fi - - if [ -d $1.1 ]; then - $nice $cp -alf /$1.1/. /$1.0 - fi + if [[ "$2" < 4 ]]; then + error "Rotate: minimum of 4 rotations" + exit 1 + fi -} + if [ -d $1.$2 ]; then + $nice $mv /$1.$2 /$1.tmp + fi -function move_files { + for ((n=`echo "$2 - 1" | bc`; n >= 0; n--)); do + if [ -d $1.$n ]; then + dest=`echo "$n + 1" | bc` + $nice $mv /$1.$n /$1.$dest + $touch /$1.$dest + fi + done - ref=$tmp/makesnapshot-mymv-$$; - $touch -r $1 $ref; - $mv $1 $2; - $touch -r $ref $2; - $rm $ref; + if [ -d $1.tmp ]; then + $nice $mv /$1.tmp /$1.0 + fi + + if [ -d $1.1 ]; then + $nice $cp -alf /$1.1/. /$1.0 + fi } +function move_files { + ref=$tmp/makesnapshot-mymv-$$; + $touch -r $1 $ref; + $mv $1 $2; + $touch -r $ref $2; + $rm $ref; +} + backupdir="$mountpoint/$backupdir" # does $backupdir exists? -if [ ! -d "$backupdir" ]; then - error "Backupdir $backupdir does not exist" - exit 1 +if [ ! -d "$backupdir" ]; then + error "Backupdir $backupdir does not exist" + exit 1 fi # setup number of increments if [ -z "$days" ]; then - keep="4" + keep="4" else - keep="`echo $days - 1 | bc -l`" + keep="`echo $days - 1 | bc -l`" fi # lockfile setup if [ ! -z "$lockfile" ]; then - $touch $lockfile || warning "Could not create lockfile $lockfile" + $touch $lockfile || warning "Could not create lockfile $lockfile" fi # nicelevel setup -if [ ! -z "$nicelevel" ]; then - nice="nice -n $nicelevel" -else - nice="" +if [ ! -z "$nicelevel" ]; then + nice="nice -n $nicelevel" +else + nice="" fi # set mv procedure if [ $enable_mv_timestamp_bug == "yes" ]; then - mv=move_files + mv=move_files fi # set excludes for path in $exclude; do - EXCLUDES="$EXCLUDES --exclude=$path" + EXCLUDES="$EXCLUDES --exclude=$path" done echo "Starting backup at `date`" >> $log @@ -162,19 +160,19 @@ echo "Starting backup at `date`" >> $log # mount backup destination folder as read-write if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then - if [ -d "$mountpoint" ]; then - mount -o remount,rw $mountpoint - if (($?)); then - error "Could not mount $mountpoint" - exit 1 - fi - fi + if [ -d "$mountpoint" ]; then + mount -o remount,rw $mountpoint + if (($?)); then + error "Could not mount $mountpoint" + exit 1 + fi + fi fi # the backup procedure if [ ! -d "$backupdir/$folder/$folder.0" ]; then - mkdir -p $backupdir/$folder/$folder.0 + mkdir -p $backupdir/$folder/$folder.0 fi info "Rotating $backupdir/$folder/$folder..." @@ -183,7 +181,7 @@ rotate $backupdir/$folder/$folder $keep info "Wget'ing $SECTION on $backupdir/$folder/$folder.0..." if [ ! -z "$badnwidth" ]; then - limit_rate="--limit-rate=$badnwidth""k" + limit_rate="--limit-rate=$badnwidth""k" fi cd $backupdir/$folder/$folder.0 @@ -195,25 +193,25 @@ $touch $backupdir/$folder/$folder.0 # remount backup destination as read-only if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then - mount -o remount,ro $mountpoint + mount -o remount,ro $mountpoint fi # check partition for errors if [ "$fscheck" == "1" ] || [ "$fscheck" == "yes" ]; then - umount $mountpoint - if (($?)); then - warning "Could not umount $mountpoint to run fsck" - else - $nice $fsck -v -y $partition >> $log - mount $mountpoint - fi + umount $mountpoint + if (($?)); then + warning "Could not umount $mountpoint to run fsck" + else + $nice $fsck -v -y $partition >> $log + mount $mountpoint + fi fi # removes the lockfile if [ ! -z "$lockfile" ]; then - $rm $lockfile || warning "Could not remove lockfile $lockfile" + $rm $lockfile || warning "Could not remove lockfile $lockfile" fi echo "Finnishing backup at `date`" >> $log -- cgit v1.2.3 From 78884142e7cdaaf3e1f5571b1f28d2ea5a520b30 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Fri, 22 May 2009 15:27:09 +0200 Subject: Add a vim modeline with indentation settings. The modelines added match the emacs lines already present and also set the filetype to sh (just like the emacs lines). --- handlers/dup.helper.in | 1 + handlers/dup.in | 1 + handlers/ldap.helper.in | 1 + handlers/ldap.in | 1 + handlers/maildir.in | 1 + handlers/makecd.helper.in | 1 + handlers/makecd.in | 1 + handlers/mysql.helper.in | 1 + handlers/mysql.in | 1 + handlers/pgsql.helper.in | 1 + handlers/pgsql.in | 1 + handlers/rdiff.helper.in | 1 + handlers/rdiff.in | 1 + handlers/rsync.in | 2 ++ handlers/sh.in | 1 + handlers/svn.in | 1 + handlers/sys.helper.in | 1 + handlers/sys.in | 1 + handlers/tar.helper.in | 1 + handlers/tar.in | 1 + handlers/trac.in | 1 + handlers/wget | 2 ++ lib/easydialog.in | 1 + lib/tools.in | 1 + lib/vserver.in | 1 + src/backupninja.in | 1 + src/ninjahelper.in | 1 + src/ninjareport.in | 1 + 28 files changed, 30 insertions(+) (limited to 'handlers') diff --git a/handlers/dup.helper.in b/handlers/dup.helper.in index 86745c8..3c08a2f 100644 --- a/handlers/dup.helper.in +++ b/handlers/dup.helper.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: HELPERS="$HELPERS dup:incremental_encrypted_remote_filesystem_backup" diff --git a/handlers/dup.in b/handlers/dup.in index 60a4ce9..aed6030 100644 --- a/handlers/dup.in +++ b/handlers/dup.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # # duplicity script for backupninja # requires duplicity diff --git a/handlers/ldap.helper.in b/handlers/ldap.helper.in index 4870ae4..4154cc6 100644 --- a/handlers/ldap.helper.in +++ b/handlers/ldap.helper.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: HELPERS="$HELPERS ldap:ldap_database_backup" diff --git a/handlers/ldap.in b/handlers/ldap.in index 0b0166e..5f402c7 100644 --- a/handlers/ldap.in +++ b/handlers/ldap.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # # openldap backup handler script for backupninja # diff --git a/handlers/maildir.in b/handlers/maildir.in index e88619d..ab72ce1 100644 --- a/handlers/maildir.in +++ b/handlers/maildir.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: ############################################################### # diff --git a/handlers/makecd.helper.in b/handlers/makecd.helper.in index c8a6762..ad0c4aa 100644 --- a/handlers/makecd.helper.in +++ b/handlers/makecd.helper.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: HELPERS="$HELPERS makecd:makecd_backup" wizardname="makecd action wizard" diff --git a/handlers/makecd.in b/handlers/makecd.in index 78e5454..d44bba3 100644 --- a/handlers/makecd.in +++ b/handlers/makecd.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # # burncd handler script for backupninja # diff --git a/handlers/mysql.helper.in b/handlers/mysql.helper.in index fb9f11d..997f73c 100644 --- a/handlers/mysql.helper.in +++ b/handlers/mysql.helper.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: HELPERS="$HELPERS mysql:mysql_database_backup" diff --git a/handlers/mysql.in b/handlers/mysql.in index a4a3667..88ffb1a 100644 --- a/handlers/mysql.in +++ b/handlers/mysql.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # # mysql handler script for backupninja # diff --git a/handlers/pgsql.helper.in b/handlers/pgsql.helper.in index 48bf047..ff1cfd4 100644 --- a/handlers/pgsql.helper.in +++ b/handlers/pgsql.helper.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: HELPERS="$HELPERS pgsql:postgresql_database_backup" diff --git a/handlers/pgsql.in b/handlers/pgsql.in index b7e4262..ff5f7ba 100644 --- a/handlers/pgsql.in +++ b/handlers/pgsql.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # # PostgreSQL handler script for backupninja # diff --git a/handlers/rdiff.helper.in b/handlers/rdiff.helper.in index c673723..83f2fb5 100644 --- a/handlers/rdiff.helper.in +++ b/handlers/rdiff.helper.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: HELPERS="$HELPERS rdiff:incremental_remote_filesystem_backup" diff --git a/handlers/rdiff.in b/handlers/rdiff.in index 51da1cc..f59d56a 100644 --- a/handlers/rdiff.in +++ b/handlers/rdiff.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # # rdiff-backup handler script for backupninja # requires rdiff-backup diff --git a/handlers/rsync.in b/handlers/rsync.in index 9e5e4f9..072f2a6 100644 --- a/handlers/rsync.in +++ b/handlers/rsync.in @@ -1,3 +1,5 @@ +# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # # backupninja handler to do incremental backups using # rsync and hardlinks, based on diff --git a/handlers/sh.in b/handlers/sh.in index 4edfd9a..b070f3b 100644 --- a/handlers/sh.in +++ b/handlers/sh.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # # shell script handler for backupninja # runs the file /etc/backup.d/scriptname.sh diff --git a/handlers/svn.in b/handlers/svn.in index 97d1701..5e5531a 100644 --- a/handlers/svn.in +++ b/handlers/svn.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # # this handler will backup subversion repostitories. # diff --git a/handlers/sys.helper.in b/handlers/sys.helper.in index c823712..8a2fb07 100644 --- a/handlers/sys.helper.in +++ b/handlers/sys.helper.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: HELPERS="$HELPERS sys:general_hardware_and_system_info" diff --git a/handlers/sys.in b/handlers/sys.in index 2ab5871..69751ed 100755 --- a/handlers/sys.in +++ b/handlers/sys.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # # this handler will save various reports of vital system information. # by default, all the reports are saved in /var/backups. diff --git a/handlers/tar.helper.in b/handlers/tar.helper.in index 2665382..cdbe03a 100644 --- a/handlers/tar.helper.in +++ b/handlers/tar.helper.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: HELPERS="$HELPERS tar:tar_backup" diff --git a/handlers/tar.in b/handlers/tar.in index 0a762ce..b4f8c58 100644 --- a/handlers/tar.in +++ b/handlers/tar.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # # tar handler script for backupninja diff --git a/handlers/trac.in b/handlers/trac.in index f387d42..018bffd 100644 --- a/handlers/trac.in +++ b/handlers/trac.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # # this handler will backup trac environments (based on the svn handler) # diff --git a/handlers/wget b/handlers/wget index 0c363eb..ebb391e 100644 --- a/handlers/wget +++ b/handlers/wget @@ -1,3 +1,5 @@ +# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # # backupninja handler to do incremental backups using # wget and hardlinks, based on rsync handler diff --git a/lib/easydialog.in b/lib/easydialog.in index a0495a7..c41e6f7 100644 --- a/lib/easydialog.in +++ b/lib/easydialog.in @@ -1,5 +1,6 @@ #!@BASH@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # copyright 2002 lmoore@tump.com under the terms of the GNU LGPL. # additions 2005 collective@riseup.net diff --git a/lib/tools.in b/lib/tools.in index 0d368b8..929826b 100644 --- a/lib/tools.in +++ b/lib/tools.in @@ -1,5 +1,6 @@ #!@BASH@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # This file contains functions shared between ninjahelper and backupninja. diff --git a/lib/vserver.in b/lib/vserver.in index cc96a71..b356b2b 100644 --- a/lib/vserver.in +++ b/lib/vserver.in @@ -1,4 +1,5 @@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: ##################################################### ## VSERVERS RELATED FUNCTIONS FOR NINJAHELPER diff --git a/src/backupninja.in b/src/backupninja.in index ca5074c..a158715 100755 --- a/src/backupninja.in +++ b/src/backupninja.in @@ -1,5 +1,6 @@ #!@BASH@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # # |\_ # B A C K U P N I N J A /()/ diff --git a/src/ninjahelper.in b/src/ninjahelper.in index 7bbef1f..2a7faa9 100755 --- a/src/ninjahelper.in +++ b/src/ninjahelper.in @@ -1,5 +1,6 @@ #!@BASH@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: #################################################### ## Functions diff --git a/src/ninjareport.in b/src/ninjareport.in index 56a7209..4bc244e 100755 --- a/src/ninjareport.in +++ b/src/ninjareport.in @@ -1,5 +1,6 @@ #!@BASH@ # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # # # Ninjareport - generate a single simple report for a lot of hosts -- cgit v1.2.3 From 8000beda168ec59df4f8cc69e72cb6e9722368eb Mon Sep 17 00:00:00 2001 From: Micah Anderson Date: Thu, 9 Jul 2009 19:00:41 -0400 Subject: added sshoptions variable to the maildir handler for arbitrary options that you might need to pass updated the example.maildir to include this option, as well as detail the missing desid_file, destport --- ChangeLog | 2 ++ examples/example.maildir | 10 ++++++++++ handlers/maildir.in | 29 +++++++++++++++-------------- 3 files changed, 27 insertions(+), 14 deletions(-) (limited to 'handlers') diff --git a/ChangeLog b/ChangeLog index f1daeb9..74cc3ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,8 @@ version 0.9.7 -- UNRELEASED maildir: . fix location of deleted_on file . add missing destid_file options to ssh connections + . added sshoptions variable for arbitrary ssh options + . updated example file to include destid_file, destport and sshoptions mysql: . Options passed to mysqldump are now customizable with the new sqldumpoptions configuration variable. Thanks to Chris Lamb for his diff --git a/examples/example.maildir b/examples/example.maildir index 8898a78..eba5429 100644 --- a/examples/example.maildir +++ b/examples/example.maildir @@ -50,6 +50,16 @@ desthost = kakapo-pn # arbitrary bash commands on the desthost. destuser = backer +# For alternate ports from the default 22, specify here +destport = 4444 + +# If you need to specify an alternate ssh public key authentication file +# do that here. Default: /root/.ssh/id_rsa +destid_file = /home/backupkeys/.ssh/maildirbackup_id_rsa + +# If you need to specify other ssh configuration options, do that here +sshoptions = "-C -6" + # remove any maildirs from backup which might have been deleted remove = yes diff --git a/handlers/maildir.in b/handlers/maildir.in index ab72ce1..148c30d 100644 --- a/handlers/maildir.in +++ b/handlers/maildir.in @@ -69,6 +69,7 @@ getconf desthost getconf destport 22 getconf destuser getconf destid_file /root/.ssh/id_rsa +getconf sshoptions getconf multiconnection notset @@ -85,7 +86,7 @@ if [ $test ]; then testflags="--dry-run -v" fi -rsyncflags="$testflags -e 'ssh -p $destport -i $destid_file' -r -v --ignore-existing --delete --size-only --bwlimit=$speedlimit" +rsyncflags="$testflags -e 'ssh -p $destport -i $destid_file $sshoptions' -r -v --ignore-existing --delete --size-only --bwlimit=$speedlimit" excludes="--exclude '.Trash/\*' --exclude '.Mistakes/\*' --exclude '.Spam/\*'" ################################################################## @@ -103,7 +104,7 @@ function do_user() { fi debug "syncing" - ret=`$RSYNC -e "ssh -p $destport -i $destid_file" -r \ + ret=`$RSYNC -e "ssh -p $destport -i $destid_file $sshoptions" -r \ --links --ignore-existing --delete --size-only --bwlimit=$speedlimit \ --exclude '.Trash/*' --exclude '.Mistakes/*' --exclude '.Spam/*' \ $source $destuser@$desthost:$target \ @@ -118,7 +119,7 @@ function do_user() { fatal "100 rsync errors -- something is not working right. bailing out." fi fi - ssh -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file "date +%c%n%s > $target/created" + ssh -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file $sshoptions "date +%c%n%s > $target/created" } # remove any maildirs from backup which might have been deleted @@ -129,16 +130,16 @@ function do_remove() { local tmp1=`maketemp maildir-tmp-file` local tmp2=`maketemp maildir-tmp-file` - ssh -p $destport -i $destid_file $destuser@$desthost mkdir -p "$destdir/deleted" + ssh -p $destport -i $destid_file $sshoptions $destuser@$desthost mkdir -p "$destdir/deleted" cd "$srcdir" for userdir in `ls -d1 */`; do ls -1 "$srcdir/$userdir" | sort > $tmp1 - ssh -p $destport -i $destid_file $destuser@$desthost ls -1 "$destdir/$userdir" | sort > $tmp2 + ssh -p $destport -i $destid_file $sshoptions $destuser@$desthost ls -1 "$destdir/$userdir" | sort > $tmp2 for deluser in `join -v 2 $tmp1 $tmp2`; do [ "$deluser" != "" ] || continue info "removing $destuser@$desthost:$destdir/$userdir$deluser/" - ssh -p $destport -i $destid_file $destuser@$desthost mv "$destdir/$userdir$deluser/" "$destdir/deleted" - ssh -p $destport -i $destid_file $destuser@$desthost "date +%c%n%s > '$destdir/deleted/$deluser/deleted_on'" + ssh -p $destport -i $destid_file $sshoptions $destuser@$desthost mv "$destdir/$userdir$deluser/" "$destdir/deleted" + ssh -p $destport -i $destid_file $sshoptions $destuser@$desthost "date +%c%n%s > '$destdir/deleted/$deluser/deleted_on'" done done rm $tmp1 @@ -151,7 +152,7 @@ function do_rotate() { local userdir=${2%/} local backuproot="$destdir/$userdir/$user" ( - ssh -T -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file <&1` + result=`ssh -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file $sshoptions 'echo -n 1' 2>&1` if [ "$result" != "1" ]; then fatal "Can't connect to $desthost as $destuser using $destid_file." fi @@ -323,7 +324,7 @@ end_mux start_mux ## SANITY CHECKS ## -status=`ssh -p $destport -i $destid_file $destuser@$desthost "[ -d \"$destdir\" ] && echo 'ok'"` +status=`ssh -p $destport -i $destid_file $sshoptions $destuser@$desthost "[ -d \"$destdir\" ] && echo 'ok'"` if [ "$status" != "ok" ]; then end_mux fatal "Destination directory $destdir doesn't exist!" -- cgit v1.2.3 From f45803230a839de092122f6843422097deff4eaa Mon Sep 17 00:00:00 2001 From: intrigeri Date: Sat, 18 Jul 2009 10:45:45 +0200 Subject: dup: fixed bandwidthlimit test Thanks to Ian Beckwith for the patch. --- AUTHORS | 1 + ChangeLog | 3 +++ handlers/dup.in | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) (limited to 'handlers') diff --git a/AUTHORS b/AUTHORS index dc0d2bd..c5fdf33 100644 --- a/AUTHORS +++ b/AUTHORS @@ -29,3 +29,4 @@ Adam Monsen - spec file updates Matthew Palmer -- halt loglevel feature dan@garthwaite.org -- reportspace bugfix Tuomas Jormola -- "when = manual" option +Ian Beckwith -- dup bandwidthlimit fix diff --git a/ChangeLog b/ChangeLog index 74cc3ca..c91ca38 100644 --- a/ChangeLog +++ b/ChangeLog @@ -26,6 +26,9 @@ version 0.9.7 -- UNRELEASED . New lvm option (default=disabled) to backup LVM metadata for every detected volume group. . Backup dmsetup info as well, for easier restoring of Luks headers. + dup: + . Fixed bandwidthlimit syntax error. Thanks to Ian Beckwith for + the patch. version 0.9.6 -- July 21, 2008 backupninja changes diff --git a/handlers/dup.in b/handlers/dup.in index aed6030..54b7709 100644 --- a/handlers/dup.in +++ b/handlers/dup.in @@ -106,7 +106,7 @@ duplicity_sub="`echo $duplicity_version | @AWK@ -F '.' '{print $3}'`" # --sftp-command ourselves scpoptions="$sshoptions" -if [ "$bandwidthlimit" =! 0 ]; then +if [ "$bandwidthlimit" != 0 ]; then [ -z "$testurl" ] || warning 'The bandwidthlimit option is not used when desturl is set.' scpoptions="$scpoptions -l $bandwidthlimit" fi -- cgit v1.2.3 From 1b991d6c1545b0c83ec86a5256af9db14384f443 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Sat, 18 Jul 2009 10:48:10 +0200 Subject: dup: fixed bandwidth vs desturl testing --- handlers/dup.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'handlers') diff --git a/handlers/dup.in b/handlers/dup.in index 54b7709..59aa90a 100644 --- a/handlers/dup.in +++ b/handlers/dup.in @@ -107,7 +107,7 @@ duplicity_sub="`echo $duplicity_version | @AWK@ -F '.' '{print $3}'`" scpoptions="$sshoptions" if [ "$bandwidthlimit" != 0 ]; then - [ -z "$testurl" ] || warning 'The bandwidthlimit option is not used when desturl is set.' + [ -z "$desturl" ] || warning 'The bandwidthlimit option is not used when desturl is set.' scpoptions="$scpoptions -l $bandwidthlimit" fi -- cgit v1.2.3 From f549dc44f65919dde9429f25e0e9de941ff3cebb Mon Sep 17 00:00:00 2001 From: Micah Anderson Date: Wed, 23 Sep 2009 16:07:58 -0400 Subject: Fix missing $ in variable name, fixes: #1239 --- handlers/rdiff.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'handlers') diff --git a/handlers/rdiff.in b/handlers/rdiff.in index f59d56a..45d5096 100644 --- a/handlers/rdiff.in +++ b/handlers/rdiff.in @@ -59,7 +59,7 @@ function check_consistency() { if [ "$user" == "" ]; then fatal "User must be specified for remote $section." fi - if [ "host" == "" ]; then + if [ "$host" == "" ]; then fatal "Host must be specifed for remote $section." fi fi -- cgit v1.2.3 From 75d17d06f276ad1aa435d7dc31777677b10917b4 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Mon, 15 Jun 2009 12:14:01 -0300 Subject: Enhanced rsync handler. - Added support for: - Remote destinations - Long rotation format similar to maildir handler - Batch files through --read-batch and --write-batch - Custom file list using --files-from - SSH persistent connection using ControlMaster - The rsync:// protocol - Metadata folder for each backup folder - General refactoring - Code cleanup Not all options were tested and it might contain bugs. Tests, comments and patches are welcome. :) --- handlers/rsync.in | 1176 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 952 insertions(+), 224 deletions(-) (limited to 'handlers') diff --git a/handlers/rsync.in b/handlers/rsync.in index 072f2a6..829f148 100644 --- a/handlers/rsync.in +++ b/handlers/rsync.in @@ -1,13 +1,26 @@ -# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- -# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # -# backupninja handler to do incremental backups using -# rsync and hardlinks, based on +# backupninja handler for incremental backups using rsync and hardlinks +# feedback: rhatto at riseup.net # -# http://www.mikerubel.org/computers/rsync_snapshots/ +# rsync handler 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 any later version. # -# feedback: rhatto at riseup.net | gpl -# lot of enhancements grabbed from "rsnap" handler by paulv at bikkel.org +# rsync handler 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., 59 Temple +# Place - Suite 330, Boston, MA 02111-1307, USA +# +# Inspiration +# ----------- +# +# - http://www.mikerubel.org/computers/rsync_snapshots/ +# - rsnap handler by paulv at bikkel.org +# - maildir handler from backupninja # # Config file options # ------------------- @@ -17,21 +30,29 @@ # partition = partition where the backup lives # fscheck = set to 1 if fsck should run on $partition after the backup is made # read_only = set to 1 if $partition is mounted read-only -# mountpoint = backup partition mountpoint or backup main folder -# backupdir = folder relative do $mountpoint where the backup should be stored -# days = number of backup increments (min = 5) +# mountpoint = backup partition mountpoint or backup main folder (either local or remote) +# backupdir = folder relative do $mountpoint where the backup should be stored (local or remote) +# format = specify backup storage format: short, long or mirror (i.e, no rotations) +# days = for short storage format, specify the number of backup increments (min = 5) +# keepdaily = for long storage format, specify the number of daily backup increments +# keepweekly = for long storage format, specify the number of weekly backup increments +# keepmonthly = for long storage format, specify the number of monthly backup increments # lockfile = lockfile to be kept during backup execution # nicelevel = rsync command nice level # enable_mv_timestamp_bug = set to "yes" if your system isnt handling timestamps correctly # tmp = temp folder +# multiconnection = set to "yes" if you want to use multiconnection ssh support # # [source] # from = local or remote # host = source hostname or ip, if remote backup +# port = remote port number (remote source only) +# user = remote user name (remote source only) # testconnect = when "yes", test the connection for a remote source before backup # include = include folder on backup # exclude = exclude folder on backup -# ssh = ssh command line (remote only) +# ssh = ssh command line (remote source only) +# protocol = ssh or rsync (remote source only) # rsync = rsync program # rsync_options = rsync command options # exclude_vserver = vserver-name (valid only if vservers = yes on backupninja.conf) @@ -39,6 +60,28 @@ # compress = if set to 1, compress data on rsync (remote source only) # bandwidthlimit = set a badnwidth limit in kbps (remote source only) # remote_rsync = remote rsync program (remote source only) +# id_file = ssh key file (remote source only) +# batch = set to "yes" to rsync use a batch file as source +# batchbase = folder where the batch file is located +# filelist = set yes if you want rsync to use a file list source +# filelistbase = folder where the file list is placed +# +# [dest] +# dest = backup destination type (local or remote) +# testconnect = when "yes", test the connection for a remote source before backup +# ssh = ssh command line (remote dest only) +# protocol = ssh or rsync (remote dest only) +# numericids = when set to 1, use numeric ids instead of user/group mappings on rsync +# compress = if set to 1, compress data on rsync (remote source only) +# host = destination host name (remote destination only) +# port = remote port number (remote destination only) +# user = remote user name (remote destination only) +# id_file = ssh key file (remote destination only) +# bandwidthlimit = set a badnwidth limit in kbps (remote destination only) +# remote_rsync = remote rsync program (remote dest only) +# batch = set to "yes" to rsync write a batch file from the changes +# batchbase = folder where the batch file should be written +# fakesuper = set to yes so rsync use the --fake-super flag (remote destination only) # # [services] # initscripts = absolute path where scripts are located @@ -56,297 +99,982 @@ # You dont need to manually specify vservers using "include = /vservers". # They are automatically backuped if vserver is set to "yes" on you backupninja.conf. # - -# config file evaluation - -setsection system -getconf rm rm -getconf cp cp -getconf touch touch -getconf mv mv -getconf fsck fsck - -setsection general -getconf log /var/log/backup/rsync.log -getconf partition -getconf fscheck -getconf read_only -getconf mountpoint -getconf backupdir -getconf rotate -getconf days -getconf lockfile -getconf nicelevel 0 -getconf enable_mv_timestamp_bug no -getconf tmp /tmp - -setsection source -getconf from local -getconf testconnect no -getconf rsync $RSYNC -getconf rsync_options "-av --delete" -getconf ssh ssh -getconf user -getconf host -getconf include -getconf exclude -getconf exclude_vserver -getconf numericids 0 -getconf compress 0 -getconf bandwidthlimit -getconf remote_rsync rsync - -setsection services -getconf initscripts -getconf service +# Changelog +# --------- +# +# 20090329 - rhatto at riseup.net +# +# - Added support for: +# - Remote destinations +# - Long rotation format similar to maildir handler +# - Batch files through --read-batch and --write-batch +# - Custom file list using --files-from +# - SSH persistent connection using ControlMaster +# - The rsync:// protocol +# - Metadata folder for each backup folder +# - General refactoring +# - Code cleanup +# # function definitions -function rotate { +function eval_config { + + # system section + + setsection system + getconf rm rm + getconf cp cp + getconf touch touch + getconf mv mv + getconf fsck fsck + + # general section + + setsection general + getconf log /var/log/backup/rsync.log + getconf partition + getconf fscheck + getconf read_only + getconf mountpoint + getconf backupdir + getconf format short + getconf days + getconf keepdaily 5 + getconf keepweekly 3 + getconf keepmonthly 1 + getconf lockfile + getconf nicelevel 0 + getconf enable_mv_timestamp_bug no + getconf tmp /tmp + getconf multiconnection no + + # source section + + setsection source + getconf from local + getconf rsync $RSYNC + getconf rsync_options "-av --delete --recursive" + + if [ "$from" == "remote" ]; then + getconf testconnect no + getconf protocol ssh + getconf ssh ssh + getconf host + + if [ "$protocol" == "ssh" ]; then + # sshd default listen port + getconf port 22 + else + # rsyncd default listen port + getconf port 873 + fi + + getconf user + getconf bandwidthlimit + getconf remote_rsync rsync + getconf id_file /root/.ssh/id_dsa + fi + + getconf batch no + + if [ "$batch" == "yes" ]; then + getconf batchbase + if [ ! -z "$batchbase" ]; then + batch="read" + fi + fi + + getconf filelist no + getconf filelistbase + getconf include + getconf exclude + getconf exclude_vserver + getconf numericids 0 + getconf compress 0 + + # dest section + + setsection dest + getconf dest local + getconf fakesuper no + + if [ "$dest" == "remote" ]; then + getconf testconnect no + getconf protocol ssh + getconf ssh ssh + getconf host + + if [ "$protocol" == "ssh" ]; then + # sshd default listen port + getconf port 22 + else + # rsyncd default listen port + getconf port 873 + fi + + getconf user + getconf bandwidthlimit + getconf remote_rsync rsync + getconf id_file /root/.ssh/id_dsa + fi + + getconf batch no + + if [ "$batch" != "yes" ]; then + getconf batch no + if [ "$batch" == "yes" ]; then + getconf batchbase + if [ ! -z "$batchbase" ]; then + batch="write" + fi + fi + fi + + getconf numericids 0 + getconf compress 0 + + # services section + + setsection services + getconf initscripts /etc/init.d + getconf service + + # config check + + if [ "$dest" != "local" ] && [ "$from" == "remote" ]; then + fatal "When source is remote, destination should be local." + exit 1 + fi + + if [ "$from" != "local" ] && [ "$from" != "remote" ]; then + fatal "Invalid source $from" + exit 1 + fi + + backupdir="$mountpoint/$backupdir" + + if [ "$dest" == "local" ] && [ ! -d "$backupdir" ]; then + error "Backupdir $backupdir does not exist" + exit 1 + fi + + if [ ! -z "$log" ]; then + mkdir -p `dirname $log` + fi + + if [ "$format" == "short" ]; then + if [ -z "$days" ]; then + keep="4" + else + keep="`echo $days - 1 | bc -l`" + fi + fi + + if [ ! -z "$nicelevel" ]; then + nice="nice -n $nicelevel" + else + nice="" + fi + + ssh_cmd="ssh -T -o PasswordAuthentication=no $host -p $port -l $user -i $id_file" + + if [ "$from" == "remote" ] || [ "$dest" == "remote" ]; then + if [ "$testconnect" == "yes" ] && [ "$protocol" == "ssh" ]; then + test_connect $host $port $user $id_file + fi + fi + + if [ "$multiconnection" == "yes" ]; then + ssh_cmd="$ssh_cmd -S $tmp/%r@%h:%p" + fi + + if [ $enable_mv_timestamp_bug == "yes" ]; then + mv=move_files + fi + + for path in $exclude; do + excludes="$excludes --exclude=$path" + done - if [[ "$2" < 4 ]]; then - error "Rotate: minimum of 4 rotations" - exit 1 - fi +} + +function rotate_short { + + local dest + local folder="$1" + local keep="$2" + local metadata="`dirname $folder`/metadata" + + if [[ "$keep" < 4 ]]; then + error "Rotate: minimum of 4 rotations" + exit 1 + fi - if [ -d $1.$2 ]; then - $nice $mv /$1.$2 /$1.tmp - fi + if [ -d $folder.$keep ]; then + $nice $mv /$folder.$keep /$folder.tmp + fi - for ((n=`echo "$2 - 1" | bc`; n >= 0; n--)); do - if [ -d $1.$n ]; then - dest=`echo "$n + 1" | bc` - $nice $mv /$1.$n /$1.$dest - $touch /$1.$dest + for ((n=`echo "$keep - 1" | bc`; n >= 0; n--)); do + if [ -d $folder.$n ]; then + dest=`echo "$n + 1" | bc` + $nice $mv /$folder.$n /$folder.$dest + $touch /$folder.$dest + mkdir -p $metadata/`basename $folder`.$dest + date +%c%n%s > $metadata/`basename $folder`.$dest/rotated + fi + done + + if [ -d $folder.tmp ]; then + $nice $mv /$folder.tmp /$folder.0 + fi + + if [ -d $folder.1 ]; then + $nice $cp -alf /$folder.1/. /$folder.0 + fi + +} + +function rotate_short_remote { + + local folder="$1" + local metadata="`dirname $folder`/metadata" + local keep="$2" + + if [[ "$2" < 4 ]]; then + error "Rotate: minimum of 4 rotations" + exit 1 + fi + +( + $ssh_cmd <= 0; n--)); do + if [ -d $folder.\$n ]; then + dest=\$((\$n + 1)) + $nice mv /$folder.\$n /$folder.\$dest + touch /$folder.\$dest + mkdir -p $metadata/`basename $folder`.\$dest + date +%c%n%s > $metadata/`basename $folder`.\$dest/rotated + fi + done + + if [ -d $folder.tmp ]; then + $nice mv /$folder.tmp /$folder.0 + fi + + if [ -d $folder.1 ]; then + $nice $cp -alf /$folder.1/. /$folder.0 + fi + ##### END REMOTE SCRIPT ####### +EOF +) | (while read a; do passthru $a; done) + +} + +function rotate_long { + + backuproot="$1" + seconds_daily=86400 + seconds_weekly=604800 + seconds_monthly=2628000 + keepdaily=$keepdaily + keepweekly=$keepweekly + keepmonthly=$keepmonthly + now=`date +%s` + + local metadata + + if [ ! -d "$backuproot" ]; then + echo "Debug: skipping rotate of $backuproot as it doesn't exist." + exit + fi + + for rottype in daily weekly monthly; do + seconds=$((seconds_${rottype})) + + dir="$backuproot/$rottype" + metadata="$backuproot/metadata/$rottype.1" + mkdir -p $metadata + if [ ! -d $dir.1 ]; then + echo "Debug: $dir.1 does not exist, skipping." + continue 1 + elif [ ! -f $metadata/created ] && [ ! -f $metadata/rotated ]; then + echo "Warning: metadata does not exist for $dir.1. This backup may be only partially completed. Skipping rotation." + continue 1 + fi + + # Rotate the current list of backups, if we can. + oldest=`find $backuproot -maxdepth 1 -type d -name $rottype'.*' | @SED@ 's/^.*\.//' | sort -n | tail -1` + [ "$oldest" == "" ] && oldest=0 + for (( i=$oldest; i > 0; i-- )); do + if [ -d $dir.$i ]; then + if [ -f $metadata/created ]; then + created=`tail -1 $metadata/created` + elif [ -f $metadata/rotated ]; then + created=`tail -1 $metadata/rotated` + else + created=0 + fi + cutoff_time=$(( now - (seconds*(i-1)) )) + if [ ! $created -gt $cutoff_time ]; then + next=$(( i + 1 )) + if [ ! -d $dir.$next ]; then + echo "Debug: $rottype.$i --> $rottype.$next" + $nice mv $dir.$i $dir.$next + mkdir -p $backuproot/metadata/$rottype.$next + date +%c%n%s > $backuproot/metadata/$rottype.$next/rotated + else + echo "Debug: skipping rotation of $dir.$i because $dir.$next already exists." + fi + else + echo "Debug: skipping rotation of $dir.$i because it was created" $(( (now-created)/86400)) "days ago ("$(( (now-cutoff_time)/86400))" needed)." + fi fi - done + done + done + + max=$((keepdaily+1)) + if [ $keepweekly -gt 0 -a -d $backuproot/daily.$max -a ! -d $backuproot/weekly.1 ]; then + echo "Debug: daily.$max --> weekly.1" + $nice mv $backuproot/daily.$max $backuproot/weekly.1 + mkdir -p $backuproot/metadata/weekly.1 + date +%c%n%s > $backuproot/metadata/weekly.1/rotated + fi + + max=$((keepweekly+1)) + if [ $keepmonthly -gt 0 -a -d $backuproot/weekly.$max -a ! -d $backuproot/monthly.1 ]; then + echo "Debug: weekly.$max --> monthly.1" + $nice mv $backuproot/weekly.$max $backuproot/monthly.1 + mkdir -p $backuproot/metadata/monthly.1 + date +%c%n%s > $backuproot/metadata/monthly.1/rotated + fi + + for rottype in daily weekly monthly; do + max=$((keep${rottype}+1)) + dir="$backuproot/$rottype" + oldest=`find $backuproot -maxdepth 1 -type d -name $rottype'.*' | @SED@ 's/^.*\.//' | sort -n | tail -1` + [ "$oldest" == "" ] && oldest=0 + # if we've rotated the last backup off the stack, remove it. + for (( i=$oldest; i >= $max; i-- )); do + if [ -d $dir.$i ]; then + if [ -d $backuproot/rotate.tmp ]; then + echo "Debug: removing rotate.tmp" + $nice rm -rf $backuproot/rotate.tmp + fi + echo "Debug: moving $rottype.$i to rotate.tmp" + $nice mv $dir.$i $backuproot/rotate.tmp + fi + done + done - if [ -d $1.tmp ]; then - $nice $mv /$1.tmp /$1.0 - fi +} - if [ -d $1.1 ]; then - $nice $cp -alf /$1.1/. /$1.0 - fi +function rotate_long_remote { + + local backuproot="$1" + +( + $ssh_cmd < 0; i-- )); do + if [ -d \$dir.\$i ]; then + if [ -f \$metadata/created ]; then + created=\`tail -1 \$metadata/created\` + elif [ -f \$metadata/rotated ]; then + created=\`tail -1 \$metadata/rotated\` + else + created=0 + fi + cutoff_time=\$(( now - (seconds*(i-1)) )) + if [ ! \$created -gt \$cutoff_time ]; then + next=\$(( i + 1 )) + if [ ! -d \$dir.\$next ]; then + echo "Debug: \$rottype.\$i --> \$rottype.\$next" + $nice mv \$dir.\$i \$dir.\$next + mkdir -p $backuproot/metadata/\$rottype.\$next + date +%c%n%s > $backuproot/metadata/\$rottype.\$next/rotated + else + echo "Debug: skipping rotation of \$dir.\$i because \$dir.\$next already exists." + fi + else + echo "Debug: skipping rotation of \$dir.\$i because it was created" \$(( (now-created)/86400)) "days ago ("\$(( (now-cutoff_time)/86400))" needed)." + fi + fi + done + done + + max=\$((keepdaily+1)) + if [ \$keepweekly -gt 0 -a -d $backuproot/daily.\$max -a ! -d \$backuproot/weekly.1 ]; then + echo "Debug: daily.\$max --> weekly.1" + $nice mv $backuproot/daily.\$max $backuproot/weekly.1 + mkdir -p $backuproot/metadata/weekly.1 + date +%c%n%s > $backuproot/metadata/weekly.1/rotated + fi + + max=\$((keepweekly+1)) + if [ \$keepmonthly -gt 0 -a -d $backuproot/weekly.\$max -a ! -d $backuproot/monthly.1 ]; then + echo "Debug: weekly.\$max --> monthly.1" + $nice mv $backuproot/weekly.\$max $backuproot/monthly.1 + mkdir -p $backuproot/metadata/monthly.1 + date +%c%n%s > $backuproot/metadata/monthly.1/rotated + fi + + for rottype in daily weekly monthly; do + max=\$((keep\${rottype}+1)) + dir="$backuproot/\$rottype" + oldest=\`find $backuproot -maxdepth 1 -type d -name \$rottype'.*' | @SED@ 's/^.*\.//' | sort -n | tail -1\` + [ "\$oldest" == "" ] && oldest=0 + # if we've rotated the last backup off the stack, remove it. + for (( i=\$oldest; i >= \$max; i-- )); do + if [ -d \$dir.\$i ]; then + if [ -d $backuproot/rotate.tmp ]; then + echo "Debug: removing rotate.tmp" + $nice rm -rf $backuproot/rotate.tmp + fi + echo "Debug: moving \$rottype.\$i to rotate.tmp" + $nice mv \$dir.\$i $backuproot/rotate.tmp + fi + done + done + ##### END REMOTE SCRIPT ####### +EOF +) | (while read a; do passthru $a; done) + +} + +function setup_long_dirs { + + local destdir=$1 + local backuptype=$2 + local dir="$destdir/$backuptype" + local tmpdir="$destdir/rotate.tmp" + local metadata="$destdir/metadata/$backuptype.1" + + if [ ! -d $destdir ]; then + echo "Creating destination directory $destdir..." + mkdir -p $destdir + fi + + if [ -d $dir.1 ]; then + if [ -f $metadata/created ]; then + echo "Warning: $dir.1 already exists. Overwriting contents." + else + echo "Warning: we seem to be resuming a partially written $dir.1" + fi + else + if [ -d $tmpdir ]; then + mv $tmpdir $dir.1 + if [ $? == 1 ]; then + echo "Fatal: could mv $destdir/rotate.tmp $dir.1 on host $host" + exit 1 + fi + else + mkdir --parents $dir.1 + if [ $? == 1 ]; then + echo "Fatal: could not create directory $dir.1 on host $host" + exit 1 + fi + fi + if [ -d $dir.2 ]; then + echo "Debug: update links $backuptype.2 --> $backuptype.1" + cp -alf $dir.2/. $dir.1 + #if [ $? == 1 ]; then + # echo "Fatal: could not create hard links to $dir.1 on host $host" + # exit 1 + #fi + fi + fi + [ -f $metadata/created ] && rm $metadata/created + [ -f $metadata/rotated ] && rm $metadata/rotated + +} + +function setup_long_dirs_remote { + + local destdir=$1 + local backuptype=$2 + local dir="$destdir/$backuptype" + local tmpdir="$destdir/rotate.tmp" + local metadata="$destdir/metadata/$backuptype.1" + +( + $ssh_cmd < $backuptype.1" + cp -alf $dir.2/. $dir.1 + #if [ \$? == 1 ]; then + # echo "Fatal: could not create hard links to $dir.1 on host $host" + # exit 1 + #fi + fi + fi + [ -f $metadata/created ] && rm $metadata/created + [ -f $metadata/rotated ] && rm $metadata/rotated + ##### END REMOTE SCRIPT ####### +EOF +) | (while read a; do passthru $a; done) } function move_files { - ref=$tmp/makesnapshot-mymv-$$; - $touch -r $1 $ref; - $mv $1 $2; - $touch -r $ref $2; - $rm $ref; + ref=$tmp/makesnapshot-mymv-$$; + $touch -r $1 $ref; + $mv $1 $2; + $touch -r $ref $2; + $rm $ref; + +} + +function prepare_storage { + + section="`basename $SECTION`" + + if [ "$format" == "short" ]; then + + suffix="$section.0" + info "Rotating $backupdir/$SECTION..." + echo "Rotating $backupdir/$SECTION..." >> $log + + if [ "$dest" == "remote" ]; then + rotate_short_remote $backupdir/$SECTION/$section $keep + else + rotate_short $backupdir/$SECTION/$section $keep + if [ ! -d "$backupdir/$SECTION/$section.0" ]; then + mkdir -p $backupdir/$SECTION/$section.0 + fi + fi + + elif [ "$format" == "long" ]; then + + if [ $keepdaily -gt 0 ]; then + btype=daily + elif [ $keepweekly -gt 0 ]; then + btype=weekly + elif [ $keepmonthly -gt 0 ]; then + btype=monthly + else + fatal "keeping no backups"; + exit 1 + fi + + suffix="$btype.1" + info "Rotating $backupdir/$SECTION/..." + echo "Rotating $backupdir/$SECTION/..." >> $log + + if [ "$dest" == "remote" ]; then + rotate_long_remote $backupdir/$SECTION + setup_long_dirs_remote $backupdir/$SECTION $btype + else + rotate_long $backupdir/$SECTION + setup_long_dirs $backupdir/$SECTION $btype + fi + + elif [ "$format" == "mirror" ]; then + suffix="" + else + fatal "Invalid backup format $format" + exit 1 + fi + +} + +function set_orig { + + if [ "$from" == "local" ]; then + orig="/$SECTION/" + elif [ "$from" == "remote" ]; then + if [ "$protocol" == "rsync" ]; then + orig="rsync://$user@$host:$port/$SECTION/" + else + orig="$user@$host:/$SECTION/" + fi + fi } -backupdir="$mountpoint/$backupdir" +function set_dest { -# does $backupdir exists? + if [ "$dest" == "local" ]; then + dest_path="$backupdir/$SECTION/$suffix/" + else + if [ "$protocol" == "rsync" ]; then + dest_path="rsync://$user@$host:$port/$backupdir/$SECTION/$suffix/" + else + dest_path="$user@$host:$backupdir/$SECTION/$suffix/" + fi + fi -if [ ! -d "$backupdir" ]; then - error "Backupdir $backupdir does not exist" - exit 1 -fi +} -# setup number of increments +function set_batch_mode { -if [ -z "$days" ]; then - keep="4" -else - keep="`echo $days - 1 | bc -l`" -fi + local batch_file="$batchbase/$SECTION/$suffix" -# lockfile setup + if [ "$batch" == "read" ]; then + if [ -e "$batch_file" ]; then + orig="" + excludes="" + batch_option="--read-batch=$batch_file" + else + fatal "Batch file not found: $batch_file" + exit 1 + fi + elif [ "$batch" == "write" ]; then + mkdir -p `dirname $batch_file` + batch_option="--write-batch=$batch_file" + fi -if [ ! -z "$lockfile" ]; then - $touch $lockfile || warning "Could not create lockfile $lockfile" -fi +} -# nicelevel setup +function update_metadata { -if [ ! -z "$nicelevel" ]; then - nice="nice -n $nicelevel" -else - nice="" -fi + local metadata + local folder -# connection test + if [ "$dest" == "local" ]; then + metadata="`dirname $dest_path`/metadata/`basename $dest_path`" + mkdir -p $metadata + date +%c%n%s > $metadata/created + $touch $backupdir/$SECTION/$suffix + else + folder="`echo $dest_path | cut -d : -f 2`" + metadata="`dirname $folder`/metadata/`basename $folder`" -if [ "$from" == "remote" ] && [ "$testconnect" == "yes" ]; then - debug "$ssh -o PasswordAuthentication=no $user@$host 'echo -n 1'" - result=`ssh -o PasswordAuthentication=no $user@$host 'echo -n 1'` - if [ "$result" != "1" ]; then - fatal "Can't connect to $host as $user." - else - debug "Connected to $srchost successfully" - fi -fi +( + $ssh_cmd < $metadata/created + ##### END REMOTE SCRIPT ####### +EOF +) | (while read a; do passthru $a; done) -# rsync options for local sources + fi -if [ "$from" == "local" ]; then +} - rsync_local_options="$rsync_options" +function test_connect { - if [ ! -z "$numericids" ]; then - rsync_local_options="$rsync_local_options --numeric-ids " - fi + local host="$1" + local port="$2" + local user="$3" + local id_file="$4" -fi + if [ -z "$host" ] || [ -z "$user" ]; then + fatal "Remote host or user not set" + exit 1 + fi -# rsync options for remote sources + debug "$ssh_cmd 'echo -n 1'" + result=`$ssh_cmd 'echo -n 1'` -if [ "$from" == "remote" ]; then + if [ "$result" != "1" ]; then + fatal "Can't connect to $host as $user." + exit 1 + else + debug "Connected to $host successfully" + fi - rsync_remote_options="$rsync_options --rsync-path=$remote_rsync" +} - if [ "$compress" == "1" ]; then - rsync_remote_options="$rsync_remote_options --compress" - fi +function set_lockfile { - if [ ! -z "$bandwidthlimit" ]; then - rsync_remote_options="$rsync_remote_options --bwlimit=$bandwidthlimit" - fi + if [ ! -z "$lockfile" ]; then + $touch $lockfile || warning "Could not create lockfile $lockfile" + fi - if [ ! -z "$numericids" ]; then - rsync_remote_options="$rsync_remote_options --numeric-ids" - fi +} -fi +function unset_lockfile { -# set mv procedure + if [ ! -z "$lockfile" ]; then + $rm $lockfile || warning "Could not remove lockfile $lockfile" + fi -if [ $enable_mv_timestamp_bug == "yes" ]; then - mv=move_files -fi +} -# set excludes +function set_filelist { -for path in $exclude; do - EXCLUDES="$EXCLUDES --exclude=$path" -done + filelist_flag="" -# stop services + if [ "$filelist" == "yes" ]; then + if [ ! -z "$filelistbase" ]; then + if [ -e "$filelistbase/$SECTION/$suffix" ]; then + filelist_flag="--files-from=$filelistbase/$SECTION/$suffix" + else + warning "File list $filelistbase/$SECTION/$suffix not found." + fi + else + warning "No filelistbase set." + fi + fi -if [ ! -z "$service" ]; then - for daemon in $service; do +} + +function set_rsync_options { + + if [ ! -z "$numericids" ]; then + rsync_options="$rsync_options --numeric-ids" + fi + + if [ "$from" == "local" ] || [ "$dest" == "local" ]; then + # rsync options for local sources or destinations + rsync_options="$rsync_options" + fi + + if [ "$from" == "remote" ] || [ "$dest" == "remote" ]; then + + # rsync options for remote sources or destinations + + if [ "$compress" == "1" ]; then + rsync_options="$rsync_options --compress" + fi + + if [ ! -z "$bandwidthlimit" ]; then + rsync_options="$rsync_options --bwlimit=$bandwidthlimit" + fi + + if [ "$fakesuper" == "yes" ]; then + remote_rsync="$remote_rsync --fake-super" + fi + + rsync_options=($rsync_options --rsync-path="$remote_rsync") + + if [ "$protocol" == "ssh" ]; then + if [ ! -e "$id_file" ]; then + fatal "SSH Identity file $id_file not found" + exit 1 + else + debug RSYNC_RSH=\"$ssh_cmd\" + echo RSYNC_RSH=\"$ssh_cmd\" >> $log + RSYNC_RSH="$ssh_cmd" + fi + fi + + fi + + include_vservers + +} + +function stop_services { + + if [ ! -z "$service" ]; then + for daemon in $service; do info "Stopping service $daemon..." $initscripts/$daemon stop - done -fi + done + fi -echo "Starting backup at `date`" >> $log +} + +function start_services { + + # restart services + + if [ ! -z "$service" ]; then + for daemon in $service; do + info "Starting service $daemon..." + $initscripts/$daemon start + done + fi + +} + +function mount_rw { + + # mount backup destination folder as read-write + + if [ "$dest" == "local" ]; then + if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then + if [ -d "$mountpoint" ]; then + mount -o remount,rw $mountpoint + if (($?)); then + error "Could not mount $mountpoint" + exit 1 + fi + fi + fi + fi + +} + +function mount_ro { + + # remount backup destination as read-only + + if [ "$dest" == "local" ]; then + if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then + mount -o remount,ro $mountpoint + fi + fi + +} -# mount backup destination folder as read-write +function run_fsck { -if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then - if [ -d "$mountpoint" ]; then - mount -o remount,rw $mountpoint + # check partition for errors + + if [ "$dest" == "local" ]; then + if [ "$fscheck" == "1" ] || [ "$fscheck" == "yes" ]; then + umount $mountpoint if (($?)); then - error "Could not mount $mountpoint" - exit 1 + warning "Could not umount $mountpoint to run fsck" + else + $nice $fsck -v -y $partition >> $log + mount $mountpoint fi - fi -fi + fi + fi + +} -# add vservers to included folders +function include_vservers { -if [ "$vservers_are_available" == "yes" ]; then + # add vservers to included folders - # sane permission on backup - mkdir -p $backupdir/$VROOTDIR - chmod 000 $backupdir/$VROOTDIR + if [ "$vservers_are_available" == "yes" ]; then - for candidate in $found_vservers; do + # sane permission on backup + mkdir -p $backupdir/$VROOTDIR + chmod 000 $backupdir/$VROOTDIR + + for candidate in $found_vservers; do candidate="`basename $candidate`" found_excluded_vserver="0" for excluded_vserver in $exclude_vserver; do - if [ "$excluded_vserver" == "$candidate" ]; then - found_excluded_vserver="1" - break - fi + if [ "$excluded_vserver" == "$candidate" ]; then + found_excluded_vserver="1" + break + fi done if [ "$found_excluded_vserver" == "0" ]; then - include="$include $VROOTDIR/$candidate" + include="$include $VROOTDIR/$candidate" fi - done -fi + done + fi -# the backup procedure +} -for SECTION in $include; do +function start_mux { - section="`basename $SECTION`" + if [ "$multiconnection" == "yes" ]; then + debug "Starting master ssh connection" + $ssh_cmd -M sleep 1d & + sleep 1 + fi - if [ ! -d "$backupdir/$SECTION/$section.0" ]; then - mkdir -p $backupdir/$SECTION/$section.0 - fi +} - info "Rotating $backupdir/$SECTION/$section..." - echo "Rotating $backupdir/$SECTION/$section..." >> $log - rotate $backupdir/$SECTION/$section $keep - info "Syncing $SECTION on $backupdir/$SECTION/$section.0..." +function end_mux { - if [ "$from" == "local" ]; then - debug $rsync $rsync_local_options $EXCLUDES /$SECTION/ $backupdir/$SECTION/$section.0/ - $nice $rsync $rsync_local_options $EXCLUDES /$SECTION/ $backupdir/$SECTION/$section.0/ >> $log - if [ "$?" != "0" ]; then - warning "Rsync error when trying to transfer $SECTION" - fi - elif [ "$from" == "remote" ]; then - if [ -z "$user" ] || [ -z "$host" ]; then - error "Config file error: either user or host was not specified" - exit 1 - else - debug $nice $rsync $rsync_remote_options $EXCLUDES -e "$ssh" $user@$host:/$SECTION/ $backupdir/$SECTION/$section.0 - $nice $rsync $rsync_remote_options $EXCLUDES -e "$ssh" $user@$host:/$SECTION/ $backupdir/$SECTION/$section.0 >> $log - if [ "$?" != "0" ]; then - warning "Rsync error when trying to transfer $SECTION" - fi - fi - else - error "Invalid source $from" - exit 1 - fi + if [ "$multiconnection" == "yes" ]; then + debug "Stopping master ssh connection" + $ssh_cmd pkill sleep + fi - $touch $backupdir/$SECTION/$section.0 +} -done +# the backup procedure -# remount backup destination as read-only +eval_config +set_lockfile +set_rsync_options +start_mux +stop_services +mount_rw -if [ "$read_only" == "1" ] || [ "$read_only" == "yes" ]; then - mount -o remount,ro $mountpoint -fi +echo "Starting backup at `date`" >> $log -# check partition for errors +for SECTION in $include; do -if [ "$fscheck" == "1" ] || [ "$fscheck" == "yes" ]; then - umount $mountpoint - if (($?)); then - warning "Could not umount $mountpoint to run fsck" - else - $nice $fsck -v -y $partition >> $log - mount $mountpoint - fi -fi + prepare_storage + set_orig + set_batch_mode + set_filelist + set_dest -# restart services + info "Syncing $SECTION on $dest_path..." + debug $nice $rsync "${rsync_options[@]}" $filelist_flag $excludes $batch_option $orig $dest_path + $nice $rsync "${rsync_options[@]}" $filelist_flag $excludes $batch_option $orig $dest_path >> $log -if [ ! -z "$service" ]; then - for daemon in $service; do - info "Starting service $daemon..." - $initscripts/$daemon start - done -fi + if [ "$?" != "0" ]; then + warning "Rsync error when trying to transfer $SECTION" + fi + + update_metadata -# removes the lockfile +done -if [ ! -z "$lockfile" ]; then - $rm $lockfile || warning "Could not remove lockfile $lockfile" -fi +mount_ro +run_fsck +start_services +unset_lockfile +end_mux echo "Finnishing backup at `date`" >> $log -- cgit v1.2.3 From f9672647177f771270f40a858fb94283ff1ebcdf Mon Sep 17 00:00:00 2001 From: intrigeri Date: Thu, 19 Nov 2009 20:27:46 +0100 Subject: ldap, mysql, pgsql: use gzip's --rsyncable option --- ChangeLog | 5 +++++ handlers/ldap.in | 2 +- handlers/mysql.in | 4 ++-- handlers/pgsql.in | 8 ++++---- 4 files changed, 12 insertions(+), 7 deletions(-) (limited to 'handlers') diff --git a/ChangeLog b/ChangeLog index c91ca38..4a4a3b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ version 0.9.7 -- UNRELEASED file or in a given backup action file. Thanks Tuomas Jormola for the preliminary patch (Closes: #511299) handler changes + ldap: + . Use gzip's --rsyncable option. maildir: . fix location of deleted_on file . add missing destid_file options to ssh connections @@ -20,6 +22,9 @@ version 0.9.7 -- UNRELEASED does not prevent mysqldump to work. . Fix the error message displayed when mysqld is not running: mysqladmin ping indeed returns 0 when authentication fails. + . Use gzip's --rsyncable option. + pgsql: + . Use gzip's --rsyncable option. sys: . New luksheaders option (default=disabled) to backup the Luks header of every Luks device. diff --git a/handlers/ldap.in b/handlers/ldap.in index 5f402c7..853cefb 100644 --- a/handlers/ldap.in +++ b/handlers/ldap.in @@ -86,7 +86,7 @@ if [ "$ldif" == "yes" ]; then fi if [ "$compress" == "yes" ]; then - execstr="$execstr | $GZIP > $dumpdir/$dbsuffix.ldif.gz" + execstr="$execstr | $GZIP --rsyncable > $dumpdir/$dbsuffix.ldif.gz" else execstr="$execstr > $dumpdir/$dbsuffix.ldif" fi diff --git a/handlers/mysql.in b/handlers/mysql.in index 88ffb1a..e1e89b0 100644 --- a/handlers/mysql.in +++ b/handlers/mysql.in @@ -272,7 +272,7 @@ then fatal "mysqld doesn't appear to be running!" fi if [ "$compress" == "yes" ]; then - execstr="$VSERVER $vsname exec $DUMP | $GZIP > $vroot$dumpdir/${db}.sql.gz" + execstr="$VSERVER $vsname exec $DUMP | $GZIP --rsyncable > $vroot$dumpdir/${db}.sql.gz" else execstr="$VSERVER $vsname exec $DUMP -r $vroot$dumpdir/${db}.sql" fi @@ -283,7 +283,7 @@ then fatal "mysqld doesn't appear to be running!" fi if [ "$compress" == "yes" ]; then - execstr="$DUMP | $GZIP > $dumpdir/${db}.sql.gz" + execstr="$DUMP | $GZIP --rsyncable > $dumpdir/${db}.sql.gz" else execstr="$DUMP -r $dumpdir/${db}.sql" fi diff --git a/handlers/pgsql.in b/handlers/pgsql.in index ff5f7ba..a7e3ec2 100644 --- a/handlers/pgsql.in +++ b/handlers/pgsql.in @@ -75,13 +75,13 @@ chmod 700 $vroot$backupdir if [ "$databases" == "all" ]; then if [ $usevserver = yes ]; then if [ "$compress" == "yes" ]; then - execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMPALL | $GZIP > $backupdir/${vsname}.sql.gz\"" + execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMPALL | $GZIP --rsyncable > $backupdir/${vsname}.sql.gz\"" else execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMPALL > $backupdir/${vsname}.sql\"" fi else if [ "$compress" == "yes" ]; then - execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL | $GZIP > $backupdir/${localhost}-all.sql.gz\"" + execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL | $GZIP --rsyncable > $backupdir/${localhost}-all.sql.gz\"" else execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL > $backupdir/${localhost}-all.sql\"" fi @@ -104,13 +104,13 @@ else for db in $databases; do if [ $usevserver = yes ]; then if [ "$compress" == "yes" ]; then - execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMP $db | $GZIP > $backupdir/${db}.sql.gz\"" + execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMP $db | $GZIP --rsyncable > $backupdir/${db}.sql.gz\"" else execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMP $db | > $backupdir/${db}.sql\"" fi else if [ "$compress" == "yes" ]; then - execstr="su - $PGSQLUSER -c \"$PGSQLDUMP $db | $GZIP > $backupdir/${db}.sql.gz\"" + execstr="su - $PGSQLUSER -c \"$PGSQLDUMP $db | $GZIP --rsyncable > $backupdir/${db}.sql.gz\"" else execstr="su - $PGSQLUSER -c \"$PGSQLDUMP $db > $backupdir/${db}.sql\"" fi -- cgit v1.2.3 From 34d0d30593e09a6d0af06e2f201b879cc391c6af Mon Sep 17 00:00:00 2001 From: Micah Anderson Date: Wed, 2 Dec 2009 17:09:16 -0500 Subject: adjust the comparison operators in the rsync handler, fixes #1473 --- handlers/rsync.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'handlers') diff --git a/handlers/rsync.in b/handlers/rsync.in index 829f148..9e04efe 100644 --- a/handlers/rsync.in +++ b/handlers/rsync.in @@ -306,7 +306,7 @@ function rotate_short { local keep="$2" local metadata="`dirname $folder`/metadata" - if [[ "$keep" < 4 ]]; then + if [[ "$keep" -lt 4 ]]; then error "Rotate: minimum of 4 rotations" exit 1 fi @@ -341,7 +341,7 @@ function rotate_short_remote { local metadata="`dirname $folder`/metadata" local keep="$2" - if [[ "$2" < 4 ]]; then + if [[ "$2" -lt 4 ]]; then error "Rotate: minimum of 4 rotations" exit 1 fi -- cgit v1.2.3 From 5da707b309c08de3fa7d3792d98f337eb5169141 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Fri, 25 Dec 2009 02:28:55 +0100 Subject: rsync: added vim and Emacs modelines for consistency's sake --- handlers/rsync.in | 2 ++ 1 file changed, 2 insertions(+) (limited to 'handlers') diff --git a/handlers/rsync.in b/handlers/rsync.in index 9e04efe..8f638d7 100644 --- a/handlers/rsync.in +++ b/handlers/rsync.in @@ -1,3 +1,5 @@ +# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*- +# vim: set filetype=sh sw=3 sts=3 expandtab autoindent: # # backupninja handler for incremental backups using rsync and hardlinks # feedback: rhatto at riseup.net -- cgit v1.2.3 From f4ab3148f175f8ac415b01fea61d14a80f4de969 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Fri, 25 Dec 2009 02:33:13 +0100 Subject: mysql, pgsql: Quote output filenames ... to support shell meta-characters in database names. Closes Redmine bug #617. --- ChangeLog | 4 ++++ NEWS | 9 +++++++++ handlers/mysql.in | 8 ++++---- handlers/pgsql.in | 16 ++++++++-------- 4 files changed, 25 insertions(+), 12 deletions(-) (limited to 'handlers') diff --git a/ChangeLog b/ChangeLog index 9a6ccaa..97d4353 100644 --- a/ChangeLog +++ b/ChangeLog @@ -26,8 +26,12 @@ version 0.9.7 -- UNRELEASED . Fix the error message displayed when mysqld is not running: mysqladmin ping indeed returns 0 when authentication fails. . Use gzip's --rsyncable option. + . Quote output filenames to support shell meta-characters in + database names. pgsql: . Use gzip's --rsyncable option. + . Quote output filenames to support shell meta-characters in + database names. sys: . New luksheaders option (default=disabled) to backup the Luks header of every Luks device. diff --git a/NEWS b/NEWS index 361cf3c..ef8592e 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,12 @@ +backupninja (0.9.7-1) UNRELEASED + + * mysql: output filenames to support shell meta-characters in + database names. This change was not heavily tested, please + report any breakage. + * pgsql: output filenames to support shell meta-characters in + database names. This change was not heavily tested, please + report any breakage. + backupninja (0.9.4-1) UNRELEASED * duplicity: Old (pre-0.9.4) example.dup file used to give false diff --git a/handlers/mysql.in b/handlers/mysql.in index e1e89b0..0aa3abb 100644 --- a/handlers/mysql.in +++ b/handlers/mysql.in @@ -272,9 +272,9 @@ then fatal "mysqld doesn't appear to be running!" fi if [ "$compress" == "yes" ]; then - execstr="$VSERVER $vsname exec $DUMP | $GZIP --rsyncable > $vroot$dumpdir/${db}.sql.gz" + execstr="$VSERVER $vsname exec $DUMP | $GZIP --rsyncable > '$vroot$dumpdir/${db}.sql.gz'" else - execstr="$VSERVER $vsname exec $DUMP -r $vroot$dumpdir/${db}.sql" + execstr="$VSERVER $vsname exec $DUMP -r '$vroot$dumpdir/${db}.sql'" fi else # Test to make sure mysqld is running, if it is not sqldump will not work @@ -283,9 +283,9 @@ then fatal "mysqld doesn't appear to be running!" fi if [ "$compress" == "yes" ]; then - execstr="$DUMP | $GZIP --rsyncable > $dumpdir/${db}.sql.gz" + execstr="$DUMP | $GZIP --rsyncable > '$dumpdir/${db}.sql.gz'" else - execstr="$DUMP -r $dumpdir/${db}.sql" + execstr="$DUMP -r '$dumpdir/${db}.sql'" fi fi debug "su $user -c \"$execstr\"" diff --git a/handlers/pgsql.in b/handlers/pgsql.in index a7e3ec2..d7839fb 100644 --- a/handlers/pgsql.in +++ b/handlers/pgsql.in @@ -75,15 +75,15 @@ chmod 700 $vroot$backupdir if [ "$databases" == "all" ]; then if [ $usevserver = yes ]; then if [ "$compress" == "yes" ]; then - execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMPALL | $GZIP --rsyncable > $backupdir/${vsname}.sql.gz\"" + execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMPALL | $GZIP --rsyncable > '$backupdir/${vsname}.sql.gz'\"" else - execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMPALL > $backupdir/${vsname}.sql\"" + execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMPALL > '$backupdir/${vsname}.sql'\"" fi else if [ "$compress" == "yes" ]; then - execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL | $GZIP --rsyncable > $backupdir/${localhost}-all.sql.gz\"" + execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL | $GZIP --rsyncable > '$backupdir/${localhost}-all.sql.gz'\"" else - execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL > $backupdir/${localhost}-all.sql\"" + execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL > '$backupdir/${localhost}-all.sql'\"" fi fi debug "$execstr" @@ -104,15 +104,15 @@ else for db in $databases; do if [ $usevserver = yes ]; then if [ "$compress" == "yes" ]; then - execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMP $db | $GZIP --rsyncable > $backupdir/${db}.sql.gz\"" + execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMP $db | $GZIP --rsyncable > '$backupdir/${db}.sql.gz'\"" else - execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMP $db | > $backupdir/${db}.sql\"" + execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMP $db | > '$backupdir/${db}.sql'\"" fi else if [ "$compress" == "yes" ]; then - execstr="su - $PGSQLUSER -c \"$PGSQLDUMP $db | $GZIP --rsyncable > $backupdir/${db}.sql.gz\"" + execstr="su - $PGSQLUSER -c \"$PGSQLDUMP $db | $GZIP --rsyncable > '$backupdir/${db}.sql.gz'\"" else - execstr="su - $PGSQLUSER -c \"$PGSQLDUMP $db > $backupdir/${db}.sql\"" + execstr="su - $PGSQLUSER -c \"$PGSQLDUMP $db > '$backupdir/${db}.sql'\"" fi fi debug "$execstr" -- cgit v1.2.3 From d4c5f73ad70bedbf54ee86dcbafead39f6318d55 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Thu, 31 Dec 2009 17:05:47 +0100 Subject: dup.helper: do not propose to exclude /home/*/.gnupg twice anymore (Closes: #563044) --- ChangeLog | 4 ++++ handlers/dup.helper.in | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'handlers') diff --git a/ChangeLog b/ChangeLog index d0f7011..5f6d51b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -41,6 +41,10 @@ version 0.9.7 -- UNRELEASED dup: . Fixed bandwidthlimit syntax error. Thanks to Ian Beckwith for the patch. + helper changes + dup: + . Do not propose to exclude /home/*/.gnupg twice anymore + (Closes: #563044) autotools . Added the stat command to the automagically replaced ones, hoping it will help supporting *BSD some day. diff --git a/handlers/dup.helper.in b/handlers/dup.helper.in index 3c08a2f..2fafb99 100644 --- a/handlers/dup.helper.in +++ b/handlers/dup.helper.in @@ -508,7 +508,7 @@ dup_wizard() { # Global variables whose '*' shall not be expanded set -o noglob dup_default_includes="/var/spool/cron/crontabs /var/backups /etc /root /home /usr/local/*bin /var/lib/dpkg/status*" - dup_default_excludes="/home/*/.gnupg /home/*/.gnupg /home/*/.local/share/Trash /home/*/.Trash /home/*/.thumbnails /home/*/.beagle /home/*/.aMule /home/*/gtk-gnutella-downloads" + dup_default_excludes="/home/*/.gnupg /home/*/.local/share/Trash /home/*/.Trash /home/*/.thumbnails /home/*/.beagle /home/*/.aMule /home/*/gtk-gnutella-downloads" set +o noglob dup_main_menu -- cgit v1.2.3 From d65fa0c058b6a2e91126e1634aafd130807f58bd Mon Sep 17 00:00:00 2001 From: intrigeri Date: Tue, 5 Jan 2010 13:09:38 +0100 Subject: Cherry-picked "fixes for mysql handler for mysqld inside a vserver" This commit (64edfccf7684d9c080e734b25fa9361f0190afec) was wrongly committed to the debian branch. Conflicts: handlers/mysql.in --- handlers/mysql.in | 119 +++++++++++++++++++++++++++++------------------------- 1 file changed, 63 insertions(+), 56 deletions(-) (limited to 'handlers') diff --git a/handlers/mysql.in b/handlers/mysql.in index 0aa3abb..3b7423f 100644 --- a/handlers/mysql.in +++ b/handlers/mysql.in @@ -88,29 +88,35 @@ defaultsfile="" if [ "$dbusername" != "" -a "$dbpassword" != "" ] then - if [ $usevserver = yes ] - then - vhome=`$VSERVER $vsname exec getent passwd "root" | @AWK@ -F: '{print $6}'` - home="$vroot$vhome" - else - home=`getent passwd "root" | @AWK@ -F: '{print $6}'` - fi + if [ $usevserver = yes ] + then + home=`$VSERVER $vsname exec getent passwd "root" | @AWK@ -F: '{print $6}'` + else + home=`getent passwd "root" | @AWK@ -F: '{print $6}'` + fi - [ -d $home ] || fatal "Can't find root's home directory ($home)." + [ -d $home ] || fatal "Can't find root's home directory ($home)." + + mycnf="$home/.my.cnf" - mycnf="$home/.my.cnf" - - if [ -f $mycnf ] - then - # rename temporarily - tmpcnf="$home/my.cnf.disable" - debug "mv $mycnf $tmpcnf" - mv $mycnf $tmpcnf - fi + if [ $usevserver = yes ] + then + workcnf="$vroot$mycnf" + else + workcnf="$mycnf" + fi - oldmask=`umask` - umask 077 - cat > $mycnf < $workcnf < Date: Tue, 5 Jan 2010 13:11:57 +0100 Subject: Fix indentation of previously cherry-picked patch --- handlers/mysql.in | 98 +++++++++++++++++++++++++++---------------------------- 1 file changed, 49 insertions(+), 49 deletions(-) (limited to 'handlers') diff --git a/handlers/mysql.in b/handlers/mysql.in index 3b7423f..f3230ad 100644 --- a/handlers/mysql.in +++ b/handlers/mysql.in @@ -88,35 +88,35 @@ defaultsfile="" if [ "$dbusername" != "" -a "$dbpassword" != "" ] then - if [ $usevserver = yes ] - then - home=`$VSERVER $vsname exec getent passwd "root" | @AWK@ -F: '{print $6}'` - else - home=`getent passwd "root" | @AWK@ -F: '{print $6}'` - fi + if [ $usevserver = yes ] + then + home=`$VSERVER $vsname exec getent passwd "root" | @AWK@ -F: '{print $6}'` + else + home=`getent passwd "root" | @AWK@ -F: '{print $6}'` + fi - [ -d $home ] || fatal "Can't find root's home directory ($home)." + [ -d $home ] || fatal "Can't find root's home directory ($home)." - mycnf="$home/.my.cnf" + mycnf="$home/.my.cnf" - if [ $usevserver = yes ] - then + if [ $usevserver = yes ] + then workcnf="$vroot$mycnf" - else + else workcnf="$mycnf" - fi + fi - if [ -f $workcnf ] - then + if [ -f $workcnf ] + then # rename temporarily tmpcnf="$workcnf.disable" debug "mv $workcnf $tmpcnf" mv $workcnf $tmpcnf - fi + fi - oldmask=`umask` - umask 077 - cat > $workcnf < $workcnf < Date: Tue, 5 Jan 2010 06:44:36 +0100 Subject: Add duplicity output line by line instead of with a whole at one time. Should help fix #536360 --- handlers/dup.in | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'handlers') diff --git a/handlers/dup.in b/handlers/dup.in index 59aa90a..198eef7 100644 --- a/handlers/dup.in +++ b/handlers/dup.in @@ -263,18 +263,23 @@ fi ### Backup command debug "$precmd duplicity $execstr_command $execstr_options $execstr_source --exclude '**' / $execstr_serverpart" if [ ! $test ]; then + outputfile=`maketemp backupout` export PASSPHRASE=$password output=`nice -n $nicelevel \ su -c \ - "$precmd duplicity $execstr_command $execstr_options $execstr_source --exclude '**' / $execstr_serverpart 2>&1"` + "$precmd duplicity $execstr_command $execstr_options $execstr_source --exclude '**' / $execstr_serverpart >$outputfile 2>&1"` exit_code=$? + debug $output + cat $outputfile | (while read output ; do + debug $output + done + ) if [ $exit_code -eq 0 ]; then - debug $output info "Duplicity finished successfully." else - debug $output fatal "Duplicity failed." fi + rm $outputfile fi return 0 -- cgit v1.2.3 From 480ace739c54147c86d7905fb58068da7710b4a8 Mon Sep 17 00:00:00 2001 From: olivier Date: Tue, 5 Jan 2010 08:28:52 +0100 Subject: Convert from debug to info so that it can be reported in the email --- handlers/dup.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'handlers') diff --git a/handlers/dup.in b/handlers/dup.in index 198eef7..6e0f698 100644 --- a/handlers/dup.in +++ b/handlers/dup.in @@ -271,7 +271,7 @@ if [ ! $test ]; then exit_code=$? debug $output cat $outputfile | (while read output ; do - debug $output + info $output done ) if [ $exit_code -eq 0 ]; then -- cgit v1.2.3 From 47313bca65de105145f2168538b294a9bcc0e98d Mon Sep 17 00:00:00 2001 From: intrigeri Date: Fri, 8 Jan 2010 23:40:23 +0100 Subject: ldap,mysql,pgsql: use bash pipefail option so that failed dumps are reported as such This should fix Redmine bug #1340. This option makes pipelines return as status the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands exit successfully. See bash(1) for details. E.g. this prevents the following from exiting with status 0 (!) if pg_dumpall fails: pg_dumpall | gzip --- ChangeLog | 6 ++++++ handlers/ldap.in | 2 +- handlers/mysql.in | 8 ++++---- handlers/pgsql.in | 8 ++++---- 4 files changed, 15 insertions(+), 9 deletions(-) (limited to 'handlers') diff --git a/ChangeLog b/ChangeLog index 130a544..18ed157 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,8 @@ version 0.9.7 -- UNRELEASED handler changes ldap: . Use gzip's --rsyncable option. + . Use bash pipefail option when needed so that failed dumps are + reported as such. maildir: . fix location of deleted_on file . add missing destid_file options to ssh connections @@ -32,10 +34,14 @@ version 0.9.7 -- UNRELEASED . Use gzip's --rsyncable option. . Quote output filenames to support shell meta-characters in database names. + . Use bash pipefail option when needed so that failed dumps are + reported as such. pgsql: . Use gzip's --rsyncable option. . Quote output filenames to support shell meta-characters in database names. + . Use bash pipefail option when needed so that failed dumps are + reported as such. sys: . New luksheaders option (default=disabled) to backup the Luks header of every Luks device. diff --git a/handlers/ldap.in b/handlers/ldap.in index 853cefb..fda24d0 100644 --- a/handlers/ldap.in +++ b/handlers/ldap.in @@ -91,7 +91,7 @@ if [ "$ldif" == "yes" ]; then execstr="$execstr > $dumpdir/$dbsuffix.ldif" fi debug "$execstr" - output=`su root -c "$execstr" 2>&1` + output=`su root -c "set -o pipefail ; $execstr" 2>&1` code=$? if [ "$code" == "0" ]; then debug $output diff --git a/handlers/mysql.in b/handlers/mysql.in index f3230ad..3488c51 100644 --- a/handlers/mysql.in +++ b/handlers/mysql.in @@ -237,14 +237,14 @@ then then if [ $usevserver = yes ] then - debug 'echo show databases | $VSERVER $vsname exec su $user -c \"$MYSQL $defaultsfile\" | grep -v Database' - databases=`echo 'show databases' | $VSERVER $vsname exec su $user -c "$MYSQL $defaultsfile" | grep -v Database` + debug 'set -o pipefail ; echo show databases | $VSERVER $vsname exec su $user -c \"$MYSQL $defaultsfile\" | grep -v Database' + databases=`set -o pipefail ; echo 'show databases' | $VSERVER $vsname exec su $user -c "$MYSQL $defaultsfile" | grep -v Database` if [ $? -ne 0 ] then fatal "Authentication problem, maybe user/password is wrong or mysqld is not running?" fi else - databases=$(su $user -c "$MYSQL $defaultsfile -N -B -e 'show databases'" | sed 's/|//g;/\+----/d') + databases=$(set -o pipefail ; su $user -c "$MYSQL $defaultsfile -N -B -e 'show databases'" | sed 's/|//g;/\+----/d') if [ $? -ne 0 ] then fatal "Authentication problem, maybe user/password is wrong or mysqld is not running?" @@ -298,7 +298,7 @@ then debug "su $user -c \"$execstr\"" if [ ! $test ] then - output=`su $user -c "$execstr" 2>&1` + output=`su $user -c "set -o pipefail ; $execstr" 2>&1` code=$? if [ "$code" == "0" ] then diff --git a/handlers/pgsql.in b/handlers/pgsql.in index d7839fb..77a73fe 100644 --- a/handlers/pgsql.in +++ b/handlers/pgsql.in @@ -75,13 +75,13 @@ chmod 700 $vroot$backupdir if [ "$databases" == "all" ]; then if [ $usevserver = yes ]; then if [ "$compress" == "yes" ]; then - execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMPALL | $GZIP --rsyncable > '$backupdir/${vsname}.sql.gz'\"" + execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"set -o pipefail ; $PGSQLDUMPALL | $GZIP --rsyncable > '$backupdir/${vsname}.sql.gz'\"" else execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMPALL > '$backupdir/${vsname}.sql'\"" fi else if [ "$compress" == "yes" ]; then - execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL | $GZIP --rsyncable > '$backupdir/${localhost}-all.sql.gz'\"" + execstr="su - $PGSQLUSER -c \"set -o pipefail ; $PGSQLDUMPALL | $GZIP --rsyncable > '$backupdir/${localhost}-all.sql.gz'\"" else execstr="su - $PGSQLUSER -c \"$PGSQLDUMPALL > '$backupdir/${localhost}-all.sql'\"" fi @@ -104,13 +104,13 @@ else for db in $databases; do if [ $usevserver = yes ]; then if [ "$compress" == "yes" ]; then - execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMP $db | $GZIP --rsyncable > '$backupdir/${db}.sql.gz'\"" + execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"set -o pipefail ; $PGSQLDUMP $db | $GZIP --rsyncable > '$backupdir/${db}.sql.gz'\"" else execstr="$VSERVER $vsname exec su - $PGSQLUSER -c \"$PGSQLDUMP $db | > '$backupdir/${db}.sql'\"" fi else if [ "$compress" == "yes" ]; then - execstr="su - $PGSQLUSER -c \"$PGSQLDUMP $db | $GZIP --rsyncable > '$backupdir/${db}.sql.gz'\"" + execstr="su - $PGSQLUSER -c \"set -o pipefail ; $PGSQLDUMP $db | $GZIP --rsyncable > '$backupdir/${db}.sql.gz'\"" else execstr="su - $PGSQLUSER -c \"$PGSQLDUMP $db > '$backupdir/${db}.sql'\"" fi -- cgit v1.2.3 From 4e0519e390137b18b545f0ad256d03941cdd7bac Mon Sep 17 00:00:00 2001 From: intrigeri Date: Sat, 9 Jan 2010 00:44:43 +0100 Subject: rdiff,dup: fix include/exclude paths with spaces (Closes: #398435) This also fixes Redmine bug #1021. --- ChangeLog | 3 +++ handlers/dup.in | 9 +++++++++ handlers/rdiff.in | 9 +++++++++ 3 files changed, 21 insertions(+) (limited to 'handlers') diff --git a/ChangeLog b/ChangeLog index 18ed157..fb6b622 100644 --- a/ChangeLog +++ b/ChangeLog @@ -42,6 +42,8 @@ version 0.9.7 -- UNRELEASED database names. . Use bash pipefail option when needed so that failed dumps are reported as such. + rdiff: + . Fix include/exclude paths with spaces (Closes: #398435) sys: . New luksheaders option (default=disabled) to backup the Luks header of every Luks device. @@ -55,6 +57,7 @@ version 0.9.7 -- UNRELEASED one time (Closes: #536360) . Report duplicity output as "info" so that it can be included in report e-mail when reportinfo is on (Closes: #563734) + . Fix include/exclude paths with spaces helper changes dup: . Do not propose to exclude /home/*/.gnupg twice anymore diff --git a/handlers/dup.in b/handlers/dup.in index 6e0f698..2f55b9c 100644 --- a/handlers/dup.in +++ b/handlers/dup.in @@ -189,26 +189,35 @@ fi set -o noglob # excludes +SAVEIFS=$IFS +IFS=$(echo -en "\n\b") for i in $exclude; do str="${i//__star__/*}" execstr_source="${execstr_source} --exclude '$str'" done +IFS=$SAVEIFS # includes +SAVEIFS=$IFS +IFS=$(echo -en "\n\b") for i in $include; do [ "$i" != "/" ] || fatal "Sorry, you cannot use 'include = /'" str="${i//__star__/*}" execstr_source="${execstr_source} --include '$str'" done +IFS=$SAVEIFS # vsincludes if [ $usevserver = yes ]; then for vserver in $vsnames; do + SAVEIFS=$IFS + IFS=$(echo -en "\n\b") for vi in $vsinclude; do str="${vi//__star__/*}" str="$VROOTDIR/$vserver$str" execstr_source="${execstr_source} --include '$str'" done + IFS=$SAVEIFS done fi diff --git a/handlers/rdiff.in b/handlers/rdiff.in index 45d5096..98a53a3 100644 --- a/handlers/rdiff.in +++ b/handlers/rdiff.in @@ -209,20 +209,28 @@ symlinks_warning="Maybe you have mixed symlinks and '*' in this statement, which # TODO: order the includes and excludes # excludes +SAVEIFS=$IFS +IFS=$(echo -en "\n\b") for i in $exclude; do str="${i//__star__/*}" execstr="${execstr}--exclude '$str' " done +IFS=$SAVEIFS # includes +SAVEIFS=$IFS +IFS=$(echo -en "\n\b") for i in $include; do [ "$i" != "/" ] || fatal "Sorry, you cannot use 'include = /'" str="${i//__star__/*}" execstr="${execstr}--include '$str' " done +IFS=$SAVEIFS # vsinclude if [ $usevserver = yes ]; then for vserver in $vsnames; do + SAVEIFS=$IFS + IFS=$(echo -en "\n\b") for vi in $vsinclude; do str="${vi//__star__/*}" str="$VROOTDIR/$vserver$str" @@ -232,6 +240,7 @@ if [ $usevserver = yes ]; then warning "vsinclude statement '${vi//__star__/*}' will be ignored for VServer $vserver. $symlinks_warning" fi done + IFS=$SAVEIFS done fi -- cgit v1.2.3 From 64c4d190a3ab6b4fa60b10208b32f3b270a72482 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Sat, 9 Jan 2010 23:14:17 +0100 Subject: dup: support backups to Amazon S3 buckets Thanks to stefan for the patch. This fixes Redmine bug #658. --- AUTHORS | 3 ++- ChangeLog | 1 + README | 10 ++++++++++ examples/example.dup | 12 ++++++++++++ handlers/dup.helper.in | 6 ++++++ handlers/dup.in | 11 +++++++++++ 6 files changed, 42 insertions(+), 1 deletion(-) (limited to 'handlers') diff --git a/AUTHORS b/AUTHORS index 89b505f..c8686eb 100644 --- a/AUTHORS +++ b/AUTHORS @@ -30,4 +30,5 @@ Matthew Palmer -- halt loglevel feature dan@garthwaite.org -- reportspace bugfix Tuomas Jormola -- "when = manual" option Ian Beckwith -- dup bandwidthlimit fix -Olivier Berger -- dup debug output bugfix, reportinfo option \ No newline at end of file +Olivier Berger -- dup debug output bugfix, reportinfo option +stefan -- dup support for Amazon S3 buckets diff --git a/ChangeLog b/ChangeLog index 12c1436..f4009d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -59,6 +59,7 @@ version 0.9.7 -- UNRELEASED . Report duplicity output as "info" so that it can be included in report e-mail when reportinfo is on (Closes: #563734) . Fix include/exclude paths with spaces + . Support backups to Amazon S3 buckets, thanks to stefan for the patch. helper changes dup: . Do not propose to exclude /home/*/.gnupg twice anymore diff --git a/README b/README index 03d96fe..04eda2f 100644 --- a/README +++ b/README @@ -182,6 +182,16 @@ blank by hitting return. The included helper program "ninjahelper" will walk you through creating an rdiff-backup configuration, and will set up the ssh keys for you. + +Amazon Simple Storage Service (S3) +================================== + +Duplicity can store backups on Amazon S3 buckets, taking care of encryption. +Since it performs incremental backups it minimizes the number of request per +operation therefore reducing the costs. The boto Python interface to Amazon +Web Services is needed to use duplicity with S3 (Debian package: python-boto). + + INSTALLATION ============ diff --git a/examples/example.dup b/examples/example.dup index 2b59fe5..ea4d66e 100644 --- a/examples/example.dup +++ b/examples/example.dup @@ -8,6 +8,8 @@ ## passed directly to duplicity, e.g. to increase verbosity set this to: ## options = --verbosity 8 +## when using the Amazon S3 backend to create buckets in Europe: +## options = --s3-european-buckets --s3-use-new-style ## ## Default: # options = @@ -158,11 +160,21 @@ exclude = /home/*/.gnupg ## examples include: ## desturl = file:///usr/local/backup ## desturl = rsync://user@other.host//var/backup/bla +## desturl = s3+http:// ## the default value of this configuration option is not set: ## ## Default: # desturl = +## Amazon Web Services Access Key ID and Secret Access Key, needed for backups +## to S3 buckets. +## awsaccesskeyid = YOUR_AWS_ACCESS_KEY_ID +## awssecretaccesskey = YOUR_AWS_SECRET_KEY +## +## Default: +# awsaccesskeyid = +# awssecretaccesskey = + ## bandwith limit, in kbit/s ; default is 0, i.e. no limit an example ## setting would be: ## bandwidthlimit = 128 diff --git a/handlers/dup.helper.in b/handlers/dup.helper.in index 2fafb99..ae48e4c 100644 --- a/handlers/dup.helper.in +++ b/handlers/dup.helper.in @@ -403,6 +403,12 @@ keep = $dup_keep # bandwithlimit. For details, see duplicity manpage, section "URL FORMAT". #desturl = file:///usr/local/backup #desturl = rsync://user@other.host//var/backup/bla +#desturl = s3+http://your_bucket + +# Amazon Web Services Access Key ID and Secret Access Key, needed for backups +# to S3 buckets. +#awsaccesskeyid = YOUR_AWS_ACCESS_KEY_ID +#awssecretaccesskey = YOUR_AWS_SECRET_KEY # bandwith limit, in kbit/s ; default is 0, i.e. no limit #bandwidthlimit = 128 diff --git a/handlers/dup.in b/handlers/dup.in index 2f55b9c..ffae48c 100644 --- a/handlers/dup.in +++ b/handlers/dup.in @@ -26,6 +26,8 @@ setsection dest getconf incremental yes getconf keep 60 getconf desturl +getconf awsaccesskeyid +getconf awssecretaccesskey getconf sshoptions getconf bandwidthlimit 0 getconf desthost @@ -38,6 +40,9 @@ destdir=${destdir%/} [ -n "$desturl" -o -n "$destdir" ] || fatal "The destination directory (destdir) must be set when desturl is not used." [ -n "$include" -o -n "$vsinclude" ] || fatal "No source includes specified" [ -n "$password" ] || fatal "The password option must be set." +if [ "`echo $desturl | @AWK@ -F ':' '{print $1}'`" == "s3+http" ]; then + [ -n "$awsaccesskeyid" -a -n "$awssecretaccesskey" ] || fatal "AWS access keys must be set for S3 backups." +fi ### VServers # If vservers are configured, check that the ones listed in $vsnames do exist. @@ -227,6 +232,12 @@ set +o noglob execstr_source=${execstr_source//\\*/\\\\\\*} +### If desturl is an S3 URL export the AWS environment variables +if [ "`echo $desturl | @AWK@ -F ':' '{print $1}'`" == "s3+http" ]; then + export AWS_ACCESS_KEY_ID="$awsaccesskeyid" + export AWS_SECRET_ACCESS_KEY="$awssecretaccesskey" +fi + ### Cleanup commands (duplicity >= 0.4.4) # cleanup -- cgit v1.2.3 From 46eccf2fd0c894790405b2e3aae8dfb99f5a5d98 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Sat, 9 Jan 2010 23:25:03 +0100 Subject: rdiff: fix confusing error if rdiff-backup cannot be found on remote server. Thanks to maniacmartin for the patch on which this one is based. This closes Redmine bug #1209. --- AUTHORS | 1 + ChangeLog | 1 + handlers/rdiff.in | 8 +++++++- 3 files changed, 9 insertions(+), 1 deletion(-) (limited to 'handlers') diff --git a/AUTHORS b/AUTHORS index c8686eb..07d55c0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -32,3 +32,4 @@ Tuomas Jormola -- "when = manual" option Ian Beckwith -- dup bandwidthlimit fix Olivier Berger -- dup debug output bugfix, reportinfo option stefan -- dup support for Amazon S3 buckets +maniacmartin -- rdiff confusing error message fix diff --git a/ChangeLog b/ChangeLog index f4009d7..b1e140b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -45,6 +45,7 @@ version 0.9.7 -- UNRELEASED reported as such. rdiff: . Fix include/exclude paths with spaces (Closes: #398435) + . Fix confusing error if rdiff-backup cannot be found on remote server. sys: . New luksheaders option (default=disabled) to backup the Luks header of every Luks device. diff --git a/handlers/rdiff.in b/handlers/rdiff.in index 98a53a3..60386fa 100644 --- a/handlers/rdiff.in +++ b/handlers/rdiff.in @@ -31,6 +31,7 @@ function get_version() { # given no arguments, returns the local version. # given a user and host, returns the remote version. # if user or host is missing, returns the local version. + local version if [ "$#" -lt 2 ]; then debug "$RDIFFBACKUP -V" echo `$RDIFFBACKUP -V` @@ -38,7 +39,12 @@ function get_version() { local user=$1 local host=$2 debug "ssh $sshoptions $host -l $user '$RDIFFBACKUP -V'" - echo `ssh $sshoptions $host -l $user "$RDIFFBACKUP -V | grep rdiff-backup"` + version=`ssh $sshoptions $host -l $user "$RDIFFBACKUP -V"` + if [ $? = 127 ]; then + fatal "Unable to execute rdiff-backup on remote server. It probably isn't installed" + else + echo "$version" | grep rdiff-backup + fi fi } -- cgit v1.2.3