add limit

This commit is contained in:
Jochen Welzel 2021-01-06 11:07:05 +01:00
parent dfaeaac441
commit 6dee2475b2

View File

@ -8,22 +8,24 @@ helpFunction()
echo -e "\t-t Backup target host name" echo -e "\t-t Backup target host name"
echo -e "\t-s VM source zfs dataset" echo -e "\t-s VM source zfs dataset"
echo -e "\t-d Backup target zfs dataset" echo -e "\t-d Backup target zfs dataset"
echo -e "\t-l Limit Bandwith"
exit 1 # Exit script after printing help exit 1 # Exit script after printing help
} }
while getopts "v:t:s:d:" opt while getopts "v:t:s:d:l:" opt
do do
case "$opt" in case "$opt" in
v ) VM="$OPTARG" ;; v ) VM="$OPTARG" ;;
t ) DESTHOST="$OPTARG" ;; t ) DESTHOST="$OPTARG" ;;
s ) SRCZFS="$OPTARG" ;; s ) SRCZFS="$OPTARG" ;;
d ) DESTZFS="$OPTARG" ;; d ) DESTZFS="$OPTARG" ;;
l ) LIMIT="$OPTARG" ;;
? ) helpFunction ;; # Print helpFunction in case parameter is non-existent ? ) helpFunction ;; # Print helpFunction in case parameter is non-existent
esac esac
done done
# Print helpFunction in case parameters are empty # Print helpFunction in case parameters are empty
if [ -z "$VM" ] || [ -z "$DESTHOST" ] || [ -z "$DESTZFS" ] || [ -z "$SRCZFS" ] if [ -z "$VM" ] || [ -z "$DESTHOST" ] || [ -z "$DESTZFS" ] || [ -z "$SRCZFS" ] || [ -z "$LIMIT" ]
then then
echo "Some or all of the parameters are empty"; echo "Some or all of the parameters are empty";
helpFunction helpFunction
@ -86,7 +88,7 @@ then
LASTSNAP="backup_$LASTBACKUP" LASTSNAP="backup_$LASTBACKUP"
zfs send -i "$SRCZFS"@"$LASTSNAP" "$SRCZFS"@"$SNAPNAME" | pv -L 500M | ssh $DESTHOST sudo zfs recv -F $DESTZFS zfs send -i "$SRCZFS"@"$LASTSNAP" "$SRCZFS"@"$SNAPNAME" | pv -L 500M | ssh $DESTHOST sudo zfs recv -F $DESTZFS
else else
zfs send "$SRCZFS"@"$SNAPNAME" | pv -L 500M | ssh $DESTHOST sudo zfs recv -F $DESTZFS zfs send "$SRCZFS"@"$SNAPNAME" | pv -L $LIMIT | ssh $DESTHOST sudo zfs recv -F $DESTZFS
fi fi
if [ $? -eq 0 ] if [ $? -eq 0 ]
then then