From 4de0812ce777764d9c65dad25fc1d5bb40075bf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Thu, 23 Jun 2016 15:51:12 +0800 Subject: [PATCH] Support gz for mysqls --- bash/bashrc/sources/30_mysql | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/bash/bashrc/sources/30_mysql b/bash/bashrc/sources/30_mysql index 3f02cf9..cd29eef 100755 --- a/bash/bashrc/sources/30_mysql +++ b/bash/bashrc/sources/30_mysql @@ -1,15 +1,14 @@ #!/bin/bash function mysqlo () { - if [[ -z "$1" ]]; then + if [ -z "$1" ]; then __func_head "SERVER_NAME" echo else PASS=$(grepmysql $1 true) - if [[ -z "$PASS" ]]; then + if [ -z "$PASS" ]; then echo "Server not found in config: $1" return 1 - fi PS_SQL=$(grep -i $1 ~/.mysql_pass | awk 'BEGIN{FS=":"}{ print $4 }') @@ -26,20 +25,29 @@ function mysqlo () { } function mysqls () { - if [[ -z "$1" ]]; then - __func_head "SERVER_NAME DATABASE_NAME SQL_FILE" + if [ -z "$1" ]; then + __func_head "[z] SERVER_NAME DATABASE_NAME SQL_FILE" echo else + GZIP=false + if [ "$1" == "z" ]; then + GZIP=true + shift + fi + USER=$(grep -i $1 ~/.mysql_pass | awk 'BEGIN{FS=":"}{ print $5 }') PASS=$(grepmysql $1 true) - if [[ -z "$PASS" ]]; then + if [ -z "$PASS" ]; then echo "Server not found in config: $1" return 1 - fi - mysql -u $USER --password=$PASS -D $2 < $3 + if $GZIP; then + gunzip -c $3 | mysql -u $USER --password=$PASS -D $2 + else + mysql -u $USER --password=$PASS -D $2 < $3 + fi + fi } -