From d368bca81a38049088fc1b26a12b3010ff32a536 Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Wed, 18 Nov 2015 17:12:20 +0100 Subject: [PATCH] Implement "scp" backup type This backup type is handy to save router configuration files, for example. The defaults are suitable for Cisco IOS devices. --- README.md | 23 ++++++++++++++++++++++- bin/backup-script | 8 ++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8c5340b..e0595ce 100644 --- 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 diff --git a/bin/backup-script b/bin/backup-script index 5c8ea3f..71a17cf 100755 --- a/bin/backup-script +++ b/bin/backup-script @@ -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 -- 2.39.2