]> arthur.barton.de Git - backup-script.git/commitdiff
Implement "scp" backup type
authorAlexander Barton <alex@barton.de>
Wed, 18 Nov 2015 16:12:20 +0000 (17:12 +0100)
committerAlexander Barton <alex@barton.de>
Wed, 18 Nov 2015 16:12:20 +0000 (17:12 +0100)
This backup type is handy to save router configuration files, for
example. The defaults are suitable for Cisco IOS devices.

README.md
bin/backup-script

index 8c5340b99d964ce302bc6392cb8588d2c9bbacfb..e0595ce4739a330289c029e70e907c509f08849f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -72,6 +72,22 @@ System host name. Default: file name.
 
 *Note:* There is no `default_system` variable!
 
+### [default_]backup_type
+
+Backup type to use. Default: `rsync`.
+
+- `rsync`: system backup using rsync(1).
+  Use `source_root` to specify the root directory to save.
+
+- `scp`: file backup using scp(1).
+  Use `files` to specify the files to copy.
+
+Please note that neither `ssh_args_add`, `rsync_args_add`, `compress`, nor any
+"exclude" parameters are supported when using the "scp" backup type! And There
+"scp" backup type never _deletes_ files from the backup store; so if you reduce
+the list of files to backup, old files will still be kept, because they were
+already saved in an older generation (but no longer updated).
+
 ### [default_]user
 
 Remote user. Default: `root`.
@@ -83,6 +99,11 @@ Remote *root* directory, must end with a slash ("/") character! Default: "/".
 When saving the whole (remote) system ("/"), default excludes are set up
 automatically, which exclude standard system directories like /sys and /proc.
 
+### [default_]file
+
+Space separated list of files to copy when using the "scp" `backup_type`.
+Default: "running-config".
+
 ### [default_]target
 
 Local backup directory. The backup of each system is stored in a folder named
@@ -112,7 +133,7 @@ separated by spaces. Default: none.
 
 ### [default_]compress
 
-Enable (1) or disable (0) compression. Default: 1 (on).
+Enable (1) or disable (0) rsync transfer compression. Default: 1 (on).
 
 ### [default_]ping
 
index 5c8ea3f33c73b24e612eb26b626cafb0c5e4000b..71a17cf8c12aae63017a6e1b4c74285bc3abf74c 100755 (executable)
@@ -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"
@@ -576,6 +578,12 @@ for f in $sys; do
                [ "$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