Created
September 29, 2017 01:30
-
-
Save paolooo/e1ad95b099e9c33166afe9e429d8a9fd to your computer and use it in GitHub Desktop.
Move imported tables to a tmp dir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat service-crew.sh | |
#!/bin/bash | |
################################################ | |
# @author Nino Paolo Amarillento # | |
################################################ | |
# Usage : | |
# | |
# $ ./service-crew.sh localhost root db_name dir | |
################################################ | |
[ $# -lt 3 ] && echo "Usage: $(basename $0) <DB_HOST> <DB_USER> <DB_NAME> <DIR>" && exit 1 | |
HOST=$1 | |
USER=$2 | |
DB=$3 | |
DIR=$4 | |
[ -n "$DIR" ] || DIR=. | |
_DIR=$DIR | |
DIR+="/*.sql" | |
echo "DB password: " | |
read -s DB_PASS | |
TABLES=$(mysql -u $USER -h $HOST -p$DB_PASS -D $DB -e "SHOW TABLES;") | |
if [ ! -d $_DIR/tmp ]; then | |
echo "Creating tmp directory..." | |
mkdir -p "$_DIR/tmp" | |
fi | |
for t in $TABLES | |
do | |
if [ -f $_DIR/$t.sql ]; then | |
continue | |
fi | |
echo "moving table \"$t.sql\" -> $_DIR/tmp" | |
mv "$_DIR/$t.sql" "$_DIR/tmp" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment