aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2013-12-26 21:16:58 -0200
committerSilvio Rhatto <rhatto@riseup.net>2013-12-26 21:16:58 -0200
commit5dba68ca20097b6ce8e2b6e72565e81f60855ba3 (patch)
treee1c095722a741f1ed66055ec935967b0cc1b15ce
parent3acc0743e3bd61869aaeba861ad25efdaf19b6e9 (diff)
downloadpuppet-backup-5dba68ca20097b6ce8e2b6e72565e81f60855ba3.tar.gz
puppet-backup-5dba68ca20097b6ce8e2b6e72565e81f60855ba3.tar.bz2
Managing rsync handler again
-rw-r--r--files/handlers/rsync41
-rw-r--r--manifests/init.pp14
2 files changed, 40 insertions, 15 deletions
diff --git a/files/handlers/rsync b/files/handlers/rsync
index 6262af0..634f036 100644
--- a/files/handlers/rsync
+++ b/files/handlers/rsync
@@ -275,8 +275,15 @@ function eval_config {
mv=move_files
fi
- excludes=`echo "$exclude" | /bin/sed -e "s/^/--exclude='/g" -e "s/ /' --exclude='/g" -e "s/$/'/"`
-
+ set -o noglob
+ SAVEIFS=$IFS
+ IFS=$(echo -en "\n\b")
+ for i in $exclude; do
+ str="${i//__star__/*}"
+ excludes="${excludes} --exclude='$str'"
+ done
+ IFS=$SAVEIFS
+ set +o noglob
}
function rotate_short {
@@ -1089,6 +1096,26 @@ function restore_pipefail {
}
+function check_rsync_exit_status {
+
+ if [ -z "$1" ]; then
+ return
+ fi
+
+ case $1 in
+ 0)
+ return
+ ;;
+ 1|2|3|4|5|6|10|11|12|13|14|21)
+ fatal "Rsync error $1 when trying to transfer $SECTION"
+ ;;
+ *)
+ warning "Rsync error $1 when trying to transfer $SECTION"
+ ;;
+ esac
+
+}
+
# the backup procedure
eval_config
@@ -1109,14 +1136,12 @@ for SECTION in $include; do
set_dest
info "Syncing $SECTION on $dest_path..."
- debug $nice $rsync "${rsync_options[@]}" $filelist_flag "$excludes" $batch_option $orig $dest_path
+ command="$rsync ${rsync_options[@]} --delete-excluded $filelist_flag $excludes $batch_option $orig $dest_path"
+ debug $nice su -c "$command"
set_pipefail
- $nice $rsync "${rsync_options[@]}" $filelist_flag "$excludes" $batch_option $orig $dest_path | tee -a $log
-
- if [ "$?" != "0" ]; then
- fatal "Rsync error when trying to transfer $SECTION"
- fi
+ $nice su -c "$command" | tee -a $log
+ check_rsync_exit_status $?
restore_pipefail
update_metadata
diff --git a/manifests/init.pp b/manifests/init.pp
index 07031de..9c29d27 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -120,13 +120,13 @@ class backup(
# we have to keep that as we have custom changes that
# might not be merged and released in backupninja
- #file { "/usr/share/backupninja/rsync":
- # ensure => present,
- # owner => "root",
- # group => "root",
- # mode => 0644,
- # source => "puppet:///modules/backup/handlers/rsync",
- #}
+ file { "/usr/share/backupninja/rsync":
+ ensure => present,
+ owner => "root",
+ group => "root",
+ mode => 0644,
+ source => "puppet:///modules/backup/handlers/rsync",
+ }
# sync-backups script
file { "/usr/local/sbin/sync-backups":