rsync: bug fixes.

This commit is contained in:
Ossi Herrala 2013-11-05 12:59:20 +00:00
parent faa453c544
commit a8a1ba59a0
2 changed files with 12 additions and 6 deletions

View file

@ -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 = ""
}

View file

@ -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"