declare -i count_ok_vanished=0
destinations=""
+
+# Default settings, can be overwritten in backup-script.conf:
pre_exec=""
post_exec=""
default_target=""
default_user="root"
+default_ssh_args_add=""
+default_rsync_args_add=""
+default_exclude_args_add=""
+default_compress=1
+default_ping=1
+default_local=0
Usage() {
echo "Usage: $NAME [<options>] [<system> [<system> [...]]]"
exit 1
}
-Log() {
- logger -t "$NAME" "$*"
-}
-
-Message() {
- echo "$*"
-}
-
-MessageLog() {
- Log "$*"
- Message "$*"
-}
-
CleanUp() {
if [ -n "$post_exec" ]; then
echo "Executing \"$post_exec\" ..."
[ -r "$f" -a -f "$f" ] || continue
system=`basename $f`
- user="$default_user"
- target="$default_target"
- ssh_args_add=""
- rsync_args_add=""
- compress=1
- ping=1
- local=0
-
case "$system" in
"backup-script.conf"|*.sh)
continue
;;
esac
- # Read in configuration file
+ # Set global defaults
+ user="$default_user"
+ target="$default_target"
+ ssh_args_add="$default_ssh_args_add"
+ rsync_args_add="$default_rsync_args_add"
+ exclude_args_add="$default_exclude_args_add"
+ compress="$default_compress"
+ ping="$default_ping"
+ local="$default_local"
+
+ # Read in system configuration file
source "$f"
[ "$local" -eq 0 ] \
- && MessageLog "Working on \"$system\" ..." \
- || MessageLog "Working on \"$system\" (local system) ..."
+ && echo "Working on \"$system\" ..." \
+ || echo "Working on \"$system\" (local system) ..."
count_all=$count_all+1
# Check target directory
if [ -z "$target" ]; then
- MessageLog "No target directory specified for \"$system\"!? Skipped!"
+ echo "No target directory specified for \"$system\"!? Skipped!"
echo; continue
fi
if [ ! -d "$target" ]; then
- MessageLog "Target \"$target\" is not a directory!? \"$system\" skipped!"
+ echo "Target \"$target\" is not a directory!? \"$system\" skipped!"
echo; continue
fi
# Check if system is alive
ping -c 1 "$system" >/dev/null 2>&1
if [ $? -ne 0 ]; then
- MessageLog "Host \"$system\" seems not to be alive!? Skipped."
+ echo "Host \"$system\" seems not to be alive!? Skipped."
echo; continue
fi
- Message "OK, host \"$system\" seems to be alive."
+ echo "OK, host \"$system\" seems to be alive."
fi
ssh_cmd="ssh"
[ "$compress" -ne 0 ] && cmd="$cmd --compress"
cmd="$cmd --rsh=\"$ssh_cmd\" --delete --delete-excluded --sparse"
[ "$VERBOSE" -gt 0 ] && cmd="$cmd --progress"
- cmd="$cmd --exclude=/BACKUP --exclude=/backup --exclude=/mnt"
cmd="$cmd --exclude=/dev --exclude=/proc --exclude=/sys"
- cmd="$cmd --exclude=/usr/src --exclude=/usr/local/src"
- cmd="$cmd --exclude=/var/cache/apt --exclude=/var/amavis/blocked"
- cmd="$cmd --exclude=/var/log --exclude=/tmp --exclude=/var/tmp"
+ cmd="$cmd --exclude=/run --exclude=/tmp --exclude=/var/tmp"
+ cmd="$cmd --exclude=/media --exclude=/mnt --exclude=/net"
+ cmd="$cmd --exclude=/var/cache/apt --exclude=/var/log"
+ [ -n "$exclude_args_add" ] && cmd="$cmd $exclude_args_add"
[ -n "$rsync_args_add" ] && cmd="$cmd $rsync_args_add"
[ "$local" -eq 0 ] \
&& cmd="$cmd ${user}@${system}:/ $target" \
|| cmd="$cmd / $target"
- Message "Calling: $cmd"
+ echo "Calling: $cmd"
echo -n "Start date: "; date
count_started=$count_started+1
rm -f "$target/.stamp"
$SHELL -c "$cmd"; ret=$?
echo "code=$ret" >"$target/.stamp"
else
- MessageLog " *** Trial run, not executing synchronization command!"
+ echo " *** Trial run, not executing synchronization command!"
ret=0
fi
if [ $ret -eq 20 ]; then
- MessageLog "Backup of \"$system\" interrupted. Aborting ..."
+ echo "Backup of \"$system\" interrupted. Aborting ..."
CleanUp
exit 1
fi
if [ $ret -eq 0 -o $ret -eq 24 ]; then
[ $ret -eq 24 ] && count_ok_vanished=$count_ok_vanished+1
- MessageLog "System \"$system\" completed with status $ret, OK."
+ echo "System \"$system\" completed with status $ret, OK."
[ "$DRYRUN" -gt 0 ] || count_ok=$count_ok+1
else
- MessageLog "System \"$system\" completed with ERRORS, code $ret!"
+ echo "System \"$system\" completed with ERRORS, code $ret!"
fi
echo -n "End date: "; date