From f2bcdebc38ee9db76e53d5d5f025057b16f1f3e0 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Tue, 13 Mar 2018 15:07:19 -0300 Subject: [PATCH] =?UTF-8?q?Ajusta=20scripts=20p=20migra=C3=A7=C3=A3o=20em?= =?UTF-8?q?=20paralelo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/legacy/scripts/migra_dbs.sh | 5 +++++ sapl/legacy/scripts/migra_um_db.sh | 16 +++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/sapl/legacy/scripts/migra_dbs.sh b/sapl/legacy/scripts/migra_dbs.sh index 25a78e01c..3620da089 100755 --- a/sapl/legacy/scripts/migra_dbs.sh +++ b/sapl/legacy/scripts/migra_dbs.sh @@ -2,8 +2,13 @@ # rodar esse script na raiz do projeto + if [ $# -ge 1 ]; then + # mysql com senha parallel -eta --verbose -j+0 ./sapl/legacy/scripts/migra_um_db.sh :::: <(mysql -u $1 -p$2 -e 'show databases;' | grep '^sapl_') ::: $1 ::: $2 +elif [ $# -ge 0 ]; then + # mysql sem senha + parallel -eta --verbose -j+0 ./sapl/legacy/scripts/migra_um_db.sh :::: <(mysql -u $1 -e 'show databases;' | grep '^sapl_') ::: $1 else echo "USO:" echo " $0 [senha mysql]" diff --git a/sapl/legacy/scripts/migra_um_db.sh b/sapl/legacy/scripts/migra_um_db.sh index aab47c20e..eca35f0a3 100755 --- a/sapl/legacy/scripts/migra_um_db.sh +++ b/sapl/legacy/scripts/migra_um_db.sh @@ -6,11 +6,13 @@ if [ $# -ge 2 ]; then # proteje pasta com dumps de alterações acidentais # chmod -R -w ~/migracao_sapl/sapl_dumps + DIR_MIGRACAO=~/migracao_sapl + DATE=$(date +%Y-%m-%d) - DIR=~/${DATE}_logs_migracao - mkdir -p $DIR + DIR_LOGS=$DIR_MIGRACAO/logs/$DATE + mkdir -p $DIR_LOGS - LOG="$DIR/$1.migracao.log" + LOG="$DIR_LOGS/$1.migracao.log" rm -f $LOG echo "########################################" | tee -a $LOG @@ -20,12 +22,12 @@ if [ $# -ge 2 ]; then if [ $3 ]; then # se há senha do mysql - mysql -u $2 -p "$3" -N -s -e "DROP DATABASE IF EXISTS $1; CREATE DATABASE $1;" - mysql -u $2 -p "$3" < ~/migracao_sapl/sapl_dumps/$1.sql + mysql -u$2 -p"$3" -N -s -e "DROP DATABASE IF EXISTS $1; CREATE DATABASE $1;" + mysql -u$2 -p"$3" < $DIR_MIGRACAO/dumps_mysql/$1.sql else # se não há senha do mysql - mysql -u $2 -N -s -e "DROP DATABASE IF EXISTS $1; CREATE DATABASE $1;" - mysql -u $2 < ~/migracao_sapl/sapl_dumps/$1.sql + mysql -u$2 -N -s -e "DROP DATABASE IF EXISTS $1; CREATE DATABASE $1;" + mysql -u$2 < $DIR_MIGRACAO/dumps_mysql/$1.sql fi; echo "O banco legado foi restaurado" |& tee -a $LOG echo >> $LOG