From 674b44dd84cffb18239a9132f3dc41a150e2b02d Mon Sep 17 00:00:00 2001 From: david Date: Mon, 1 Jul 2013 21:48:55 +0200 Subject: [PATCH] added bandwidth limitation feature --- sshbackup | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sshbackup b/sshbackup index 80e3487..14c4b5d 100755 --- a/sshbackup +++ b/sshbackup @@ -20,6 +20,8 @@ localcmd="/usr/bin/rsync" versions=999 config=0 sshkey=0 +bandwidth=0 +limit=0 list=0 options=$* @@ -46,6 +48,7 @@ usage() echo " -l, --list list of sources and destinations" echo " -c, --config alternate config file [~/.sshbackup]" echo " -s, --sshkey alternate sshkey [~/.ssh/id_rsa]" + echo " -b, --bandwidth bandwidth limit in kbit/s" echo } @@ -156,6 +159,12 @@ sshbackup() cmdopt="$cmdopt --link-dest=$destpath/1" fi + #bandwidth limit + if [ $limit -gt 0 ]; then + limit=$((limit/8)) + cmdopt="$cmdopt --bwlimit=$limit" + fi + #run rsync $localcmd $cmdopt -e "ssh -q -i $sshkeyfile" --rsync-path="$remotecmd" $sourcepath $destpath/0 if [ $? -ne "0" ]; then @@ -205,6 +214,9 @@ for option in $options; do -s|--sshkey) sshkey=1 ;; + -b|--bandwidth) + bandwidth=1 + ;; *) if [ $config -eq 1 ]; then if [ -r "$option" ]; then @@ -222,6 +234,13 @@ for option in $options; do echo "aborting mission. cannot read sshkeyfile. [$option]" exit 1 fi + elif [ $bandwidth -eq 1 ]; then + if [ -z "${option//[0-9]/}" ]; then + limit=$option + else + echo "aborting mission. unknown bandwidth limit given. [$option]" + exit 1 + fi elif [ $list -eq 1 ]; then if [ -r $option ]; then listfile=$option