Added pv support for mysqls

This commit is contained in:
斟酌 鵬兄 2018-12-14 05:52:33 +08:00
parent d81aed5899
commit 3846e51f53

View File

@ -30,10 +30,19 @@ function mysqls () {
echo echo
else else
GZIP=false GZIP=false
if [ "$1" == "z" ]; then PV=false
_ANY=false
if [[ "$1" == *z* ]]; then
GZIP=true GZIP=true
shift _ANY=true
fi fi
if [[ "$1" == *p* ]]; then
PV=true
_ANY=true
fi
if $_ANY; then
shift
fi
USER=$(grep -i $1 ~/.mysql_pass | awk 'BEGIN{FS=":"}{ print $5 }') USER=$(grep -i $1 ~/.mysql_pass | awk 'BEGIN{FS=":"}{ print $5 }')
PASS=$(grepmysql $1 true) PASS=$(grepmysql $1 true)
@ -44,10 +53,17 @@ function mysqls () {
fi fi
if $GZIP; then if $GZIP; then
gunzip -c $3 | mysql -u $USER --password=$PASS -D $2 if $PV; then
pv $3 | gunzip | mysql -u $USER --password=$PASS -D $2
else
gunzip -c $3 | mysql -u $USER --password=$PASS -D $2
fi
else else
mysql -u $USER --password=$PASS -D $2 < $3 if $PV; then
pv $3 | mysql -u $USER --password=$PASS -D $2
else
mysql -u $USER --password=$PASS -D $2 < $3
fi
fi fi
fi fi
} }