mysqldumpでファイルをエクスポートして、データを抽出する

#!/bin/sh
while getopts lf:dst:h ACT
do
case $ACT in
l) LTBL="Y";;
f) FLE=$OPTARG;;
t) TBL=$OPTARG;;
d) TBLD="Y";;
s) TBLS="Y";;
esac
done
######OPTIONS -h — help
usage(){
echo “USAGE:`basename $0` -f dumpfile [-lds][-t tablename]"
echo " -f dumpfile Dump file(with mydump)"
echo " -l List all tables in dumpfile"
echo " -t tablename Table Name(\" -t 1 \" list all table name,\" -t 2 \"list all table structure)"
echo " -s Export table structure"
echo " -d Export table data"
echo " -h Help,this massage"
echo " MySQL(5.0|5.1) mysqldump file splitor V1.0.11,BUG report to startnews24@arkgame.com"
}

if [ ${#} -lt 3 -o “$1" = “-h" ];then
usage
exit
fi

########OPTION -l —List All Tables
if [ “$LTBL" = “Y" ];then
awk '/^CREATE TABLE/{print $3}’ $FLE|sed -e 's/`//gi’|nl
exit
fi

########OPTION -t
if [ “X$TBL" != “X" ];then
if [ “$TBL" = “1" ];then
awk '/^CREATE TABLE.+/{print $3}’ $FLE|nl
exit
elif [ “$TBL" = “2" ];then
awk '/^CREATE TABLE.+/,/ENGINE=/{print $0}’ $FLE
exit
fi
########OPTION -s
if [ “$TBLS" = “Y" ];then
CMDSTR="awk '/^CREATE TABLE \`$TBL\`[( )|\(]+.+/,/ENGINE=/{print \$0}’ $FLE"
eval $CMDSTR
exit
fi
########OPTION -d
if [ “$TBLD" = “Y" -o “X${TBLS}${TBLD}" = “X" ];then
CMDSTR="awk '/^INSERT INTO \`$TBL\`.*\(.+\).+\);$/{print \$0}’ $FLE"
#echo $CMDSTR
eval $CMDSTR
exit
fi
fi

Source

Posted by arkgame