#!/bin/bash
#
# backup-script system for cloning systems using rsync
-# Copyright (c)2008-2015 Alexander Barton <alex@barton.de>
+# Copyright (c)2008-2016 Alexander Barton <alex@barton.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
post_exec=""
default_backup_type="rsync"
default_source_root="/"
+default_files="running-config"
default_target="/var/backups"
default_user="root"
default_ssh_args_add=""
backup_type="$default_backup_type"
user="$default_user"
source_root="$default_source_root"
+ files="$default_files"
target="$default_target"
ssh_args_add="$default_ssh_args_add"
rsync_args_add="$default_rsync_args_add"
&& cmd="$cmd --info=progress2" \
|| cmd="$cmd --progress"
fi
+ set -f
if [ "$source_root" = "$default_source_root" ]; then
for dir in \
"/dev/**" \
cmd="$cmd --exclude=$dir"
done
[ -n "$rsync_args_add" ] && cmd="$cmd $rsync_args_add"
+ set +f
[ "$local" -eq 0 ] \
&& cmd="$cmd ${user}@${system}:$source_root $sys_target/" \
|| cmd="$cmd $source_root $sys_target/"
+ elif [[ "$backup_type" == "scp" ]]; then
+ cmd="scp"
+ [ "$VERBOSE" -eq 0 ] && cmd="$cmd -q"
+ for file in $files; do
+ cmd="$cmd ${user}@${system}:$file $sys_target/"
+ done
else
echo "Backup type \"$backup_type\" undefined, \"$system\" skipped!"
echo; continue
ok=0
if [ "$DRYRUN" -eq 0 ]; then
- rm -f "$sys_target/.stamp"
+ stamp_file="$sys_target/.stamp"
+ rm -f "$stamp_file"
+
+ # Execute backup command:
+ start_t=$(date "+%s")
$SHELL -c "$cmd"; ret=$?
- echo "code=$ret" >"$sys_target/.stamp"
+ end_t=$(date "+%s")
+
+ echo "code=$ret" >"$stamp_file"
+ echo "start_t=$start_t" >>"$stamp_file"
+ echo "end_t=$end_t" >>"$stamp_file"
+ echo "cmd='$cmd'" >>"$stamp_file"
+ echo "backup_host='`hostname -f`'" >>"$stamp_file"
+ echo "backup_user='`id -un`'" >>"$stamp_file"
else
- echo " *** Trial run, not executing synchronization command!"
+ echo " *** Trial run, not executing save command!"
ret=0
fi
elif [ -n "$to_delete" ]; then
echo "There have been errors, not cleaning up old generations!"
else
- echo "Nothing to clean up."
+ echo "Nothing to clean up (keep up to $generations generations)."
fi
fi