Only one configuration file for all database creation/drop scripts.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
working_dir="$(dirname $(realpath $0))"
|
||||
log_dir="${working_dir}/log"
|
||||
|
||||
conf_file="${working_dir}/conf/drop_tables.conf"
|
||||
conf_file="${working_dir}/conf/mysql_credetials.conf"
|
||||
|
||||
tmp_log_file="$(mktemp)"
|
||||
|
||||
@@ -11,8 +11,7 @@ tmp_log_file="$(mktemp)"
|
||||
# - Variable settings
|
||||
# -------------
|
||||
|
||||
#DEFAULT_ACTION='create'
|
||||
DEFAULT_MYSQL_CREDENTIAL_ARGS="--login-path=local"
|
||||
DEFAULT_MYSQL_CREDENTIAL_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
|
||||
|
||||
DATABASE_NAME=""
|
||||
DATABASE_NAME_NEEDED=true
|
||||
@@ -183,7 +182,7 @@ fi
|
||||
|
||||
|
||||
# -------------
|
||||
# - Load Settings from configuration file create_drop_database.conf
|
||||
# - Load Settings from configuration file mysql_credetials.conf
|
||||
# -------------
|
||||
|
||||
if ! $QUIET_MODE ; then
|
||||
@@ -203,7 +202,7 @@ else
|
||||
warn "No Configuration File found. Loading defaults.."
|
||||
fi
|
||||
|
||||
[[ -n "$MYSQL_CREDENTIAL_ARGS" ]] || MYSQL_CREDENTIAL_ARGS="$DEFAULT_MYSQL_CREDENTIAL_ARGS"
|
||||
[[ -n "$mysql_credential_args" ]] || MYSQL_CREDENTIAL_ARGS="$DEFAULT_MYSQL_CREDENTIAL_ARGS"
|
||||
|
||||
|
||||
if ! $NON_INTERACTIVE_MODE ; then
|
||||
@@ -284,26 +283,55 @@ for _table in $_TABLES ; do
|
||||
mysql $MYSQL_CREDENTIAL_ARGS $DATABASE_NAME -N -s -e "DROP TABLE \`$_table\`" >> $tmp_log_file 2>&1
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
_failed=true
|
||||
_tables_not_deleted+=("$_table")
|
||||
_tables_not_yet_deleted+=("$_table")
|
||||
fi
|
||||
done
|
||||
if $_failed ; then
|
||||
|
||||
echo_failed
|
||||
error "$(cat $tmp_log_file)"
|
||||
warn "$(cat $tmp_log_file)"
|
||||
|
||||
if [[ ${#_tables_not_deleted[@]} -gt 0 ]] ; then
|
||||
if [[ ${#_tables_not_yet_deleted[@]} -gt 0 ]] ; then
|
||||
echo ""
|
||||
echo "Tables are NOT deleted:"
|
||||
for _table in "${_tables_not_deleted[@]}" ; do
|
||||
echo " $_table"
|
||||
echo " Tables are NOT YET deleted:"
|
||||
for _table in "${_tables_not_yet_deleted[@]}" ; do
|
||||
echo " $_table"
|
||||
done
|
||||
echo ""
|
||||
|
||||
echononl " Mybe some contrains causes the problem. Try again.."
|
||||
_failed_again=false
|
||||
: > $tmp_log_file
|
||||
for _table in "${_tables_not_yet_deleted[@]}" ; do
|
||||
mysql $MYSQL_CREDENTIAL_ARGS $DATABASE_NAME -N -s -e "DROP TABLE \`$_table\`" >> $tmp_log_file 2>&1
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
_failed_again=true
|
||||
_tables_not_deleted+=("$_table")
|
||||
fi
|
||||
done
|
||||
if $_failed_again ; then
|
||||
|
||||
echo_failed
|
||||
error "$(cat $tmp_log_file)"
|
||||
if [[ ${#_tables_not_deleted[@]} -gt 0 ]] ; then
|
||||
echo ""
|
||||
echo " Tables are NOT deleted:"
|
||||
for _table in "${_tables_yet_deleted[@]}" ; do
|
||||
echo " $_table"
|
||||
done
|
||||
echo ""
|
||||
fi
|
||||
else
|
||||
echo_ok
|
||||
info "All tables from database '$DATABASE_NAME' are now deleted."
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo_ok
|
||||
fi
|
||||
|
||||
|
||||
|
||||
if ! $QUIET_MODE ; then
|
||||
echo ""
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user