diff --git a/rsync/manifests/init.pp b/rsync/manifests/init.pp index 0ee5090..45f0a8d 100644 --- a/rsync/manifests/init.pp +++ b/rsync/manifests/init.pp @@ -144,7 +144,8 @@ define rsync::backup_job ( false => $source_dirs, } $_source = "${source_host}:${_source_dirs}" - } elsif $source_dir { + $_log_host = $source_host + } elsif $source_dirs { $_source = is_array($source_dirs) ? { true => inline_template("<%= @source_dirs.join(\" \") -%>"), false => $source_dirs, @@ -155,17 +156,22 @@ define rsync::backup_job ( if $target_host and $target_dir { $_target = "${target_host}:${target_dir}" + $_log_host = $target_host } elsif $target_dir { $_target = "${target_dir}" } else { fail("You need to specify target_dir (and optionally target_host)") } + if !$_log_host { + $_log_host = "localhost" + } + if is_array($excludes) { - $_excludes = inline_template('<%= @excludes.map {|x| "--exclude=\"" + x + "\""}.join(" ") -%>') + $_excludes = inline_template('<%= @excludes.map {|x| "--exclude \'" + x + "\'"}.join(" ") -%>') } elsif $excludes { # We assume string here - $_excludes = '--exclude="$excludes"' + $_excludes = "--exclude='$excludes'" } else { $_excludes = "" } diff --git a/rsync/templates/rsync-backup.sh.erb b/rsync/templates/rsync-backup.sh.erb index c7e2b4a..8b45655 100644 --- a/rsync/templates/rsync-backup.sh.erb +++ b/rsync/templates/rsync-backup.sh.erb @@ -1,19 +1,19 @@ #!/bin/bash -LOGFILE="/srv/rsync-log/<%= @source_host -%>-$(date +"%F-%T").log" +LOGFILE="/srv/rsync-log/<%= @_log_host -%>-$(date +"%F-%T").log" FLOCK="/usr/bin/flock" FLOCK_OPTS="--exclusive --nonblock" FLOCK_FILE="/var/lock/<%= @name -%>" RSYNC="/usr/bin/rsync" -RSYNC_OPTS="-ax <%= @acl ? "-A" : "" -%> --delete --itemize-changes <%= @_excludes -%>" +RSYNC_OPTS=( -ax <%= @acl ? "-A" : "" -%> --delete --itemize-changes <%= @_excludes -%> ) ( $FLOCK $FLOCK_OPTS 200 || exit $? /usr/bin/printf "***** <%= @_source -%> -> <%= @_target -%>\n" /usr/bin/printf "***** Backup started %s\n\n" "$(date +"%F %T UTC")" - /usr/bin/time -p $RSYNC $RSYNC_OPTS <%= @_source -%> <%= @_target %> + /usr/bin/time -p $RSYNC "${RSYNC_OPTS[@]}" <%= @_source -%> <%= @_target %> RSYNCEXIT=$? if [ $RSYNCEXIT -ne 0 ]; then echo "ERROR: rsync job (<%= @name -%>) process returned $RSYNCEXIT"