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
|
versions=999
|
||||||
config=0
|
config=0
|
||||||
sshkey=0
|
sshkey=0
|
||||||
|
bandwidth=0
|
||||||
|
limit=0
|
||||||
list=0
|
list=0
|
||||||
options=$*
|
options=$*
|
||||||
|
|
||||||
|
@ -46,6 +48,7 @@ usage()
|
||||||
echo " -l, --list <file> list of sources and destinations"
|
echo " -l, --list <file> list of sources and destinations"
|
||||||
echo " -c, --config <file> alternate config file [~/.sshbackup]"
|
echo " -c, --config <file> alternate config file [~/.sshbackup]"
|
||||||
echo " -s, --sshkey <file> alternate sshkey [~/.ssh/id_rsa]"
|
echo " -s, --sshkey <file> alternate sshkey [~/.ssh/id_rsa]"
|
||||||
|
echo " -b, --bandwidth <kbps> bandwidth limit in kbit/s"
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +159,12 @@ sshbackup()
|
||||||
cmdopt="$cmdopt --link-dest=$destpath/1"
|
cmdopt="$cmdopt --link-dest=$destpath/1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#bandwidth limit
|
||||||
|
if [ $limit -gt 0 ]; then
|
||||||
|
limit=$((limit/8))
|
||||||
|
cmdopt="$cmdopt --bwlimit=$limit"
|
||||||
|
fi
|
||||||
|
|
||||||
#run rsync
|
#run rsync
|
||||||
$localcmd $cmdopt -e "ssh -q -i $sshkeyfile" --rsync-path="$remotecmd" $sourcepath $destpath/0
|
$localcmd $cmdopt -e "ssh -q -i $sshkeyfile" --rsync-path="$remotecmd" $sourcepath $destpath/0
|
||||||
if [ $? -ne "0" ]; then
|
if [ $? -ne "0" ]; then
|
||||||
|
@ -205,6 +214,9 @@ for option in $options; do
|
||||||
-s|--sshkey)
|
-s|--sshkey)
|
||||||
sshkey=1
|
sshkey=1
|
||||||
;;
|
;;
|
||||||
|
-b|--bandwidth)
|
||||||
|
bandwidth=1
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
if [ $config -eq 1 ]; then
|
if [ $config -eq 1 ]; then
|
||||||
if [ -r "$option" ]; then
|
if [ -r "$option" ]; then
|
||||||
|
@ -222,6 +234,13 @@ for option in $options; do
|
||||||
echo "aborting mission. cannot read sshkeyfile. [$option]"
|
echo "aborting mission. cannot read sshkeyfile. [$option]"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
elif [ $list -eq 1 ]; then
|
||||||
if [ -r $option ]; then
|
if [ -r $option ]; then
|
||||||
listfile=$option
|
listfile=$option
|
||||||
|
|
Reference in New Issue