added bandwidth limitation feature
This commit is contained in:
parent
79bbba78d1
commit
674b44dd84
19
sshbackup
19
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 <file> list of sources and destinations"
|
||||
echo " -c, --config <file> alternate config file [~/.sshbackup]"
|
||||
echo " -s, --sshkey <file> alternate sshkey [~/.ssh/id_rsa]"
|
||||
echo " -b, --bandwidth <kbps> 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
|
||||
|
|
Reference in New Issue