]> gitweb.fluxo.info Git - puppet-backup.git/commitdiff
Managing rsync handler again
authorSilvio Rhatto <rhatto@riseup.net>
Thu, 26 Dec 2013 23:16:58 +0000 (21:16 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Thu, 26 Dec 2013 23:16:58 +0000 (21:16 -0200)
files/handlers/rsync
manifests/init.pp

index 6262af04ce25326ba8b8bff70e269749231c165f..634f0365028559c60b2f9a84c3cdadd95eb80545 100644 (file)
@@ -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
 
index 07031de5e8d1e8cb8d47cf69abf47093e4804ec9..9c29d271834e5d2666507cd26fe4997f4fcce49b 100644 (file)
@@ -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":