rsync: First version of rsync backup jobs
This commit is contained in:
parent
d785e48a55
commit
30d8c44c6f
3 changed files with 220 additions and 0 deletions
35
rsync/templates/rsync-backup.sh.erb
Normal file
35
rsync/templates/rsync-backup.sh.erb
Normal file
|
@ -0,0 +1,35 @@
|
|||
#!/bin/bash
|
||||
|
||||
LOGFILE="/srv/rsync-log/<%= @source_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 -%>"
|
||||
|
||||
(
|
||||
$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 %>
|
||||
RSYNCEXIT=$?
|
||||
if [ $RSYNCEXIT -ne 0 ]; then
|
||||
echo "ERROR: rsync job (<%= @name -%>) process returned $RSYNCEXIT"
|
||||
fi
|
||||
/usr/bin/printf "\n***** Backup ended %s\n" "$(date +"%F %T UTC")"
|
||||
) 200>$FLOCK_FILE >$LOGFILE 2>&1
|
||||
|
||||
FLOCKEXIT=$? # flock's return code
|
||||
|
||||
# Look for unknown lines in log
|
||||
/bin/egrep -v "^$|([^ ]{11} )|([*]{5} )|(real|user|sys)" $LOGFILE >/dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
/bin/egrep -v "^([^ ]{11} )" $LOGFILE
|
||||
fi
|
||||
|
||||
if [ $FLOCKEXIT -ne 0 ]; then
|
||||
echo "ERROR: Rsync job (<%= @name -%>) already running or other error (exit code $FLOCKEXIT)"
|
||||
exit $FLOCKEXIT
|
||||
fi
|
Loading…
Add table
Add a link
Reference in a new issue