]> arthur.barton.de Git - backup-script.git/blobdiff - bin/backup-script
Update copyright notices for 2016
[backup-script.git] / bin / backup-script
index 5c8ea3f33c73b24e612eb26b626cafb0c5e4000b..1099f0c73b2bc1d5d7b1b561d2f350d0e4499768 100755 (executable)
@@ -1,7 +1,7 @@
 #!/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
@@ -33,6 +33,7 @@ pre_exec=""
 post_exec=""
 default_backup_type="rsync"
 default_source_root="/"
+default_files="running-config"
 default_target="/var/backups"
 default_user="root"
 default_ssh_args_add=""
@@ -375,6 +376,7 @@ for f in $sys; do
        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"
@@ -550,6 +552,7 @@ for f in $sys; do
                                && cmd="$cmd --info=progress2" \
                                || cmd="$cmd --progress"
                fi
+               set -f
                if [ "$source_root" = "$default_source_root" ]; then
                        for dir in \
                                "/dev/**" \
@@ -572,10 +575,17 @@ for f in $sys; do
                        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
@@ -588,11 +598,22 @@ for f in $sys; do
        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
 
@@ -649,7 +670,7 @@ for f in $sys; do
                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