60 lines
1.7 KiB
Bash
Executable File
60 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Configure mysql for further usage
|
|
credentialsFile="/opt/bin/mysql-credentials.cnf"
|
|
dump_file=""
|
|
progress_msg=""
|
|
default_db_name="maison_alexandra_lv"
|
|
load_single_table_by_title=""
|
|
|
|
# Set passed arguments
|
|
for i in "$@"; do
|
|
case $i in
|
|
-db=*|--db_name=*) default_db_name="${i#*=}" ;;
|
|
-file=*|--dump_file=*) dump_file="${i#*=}" ;;
|
|
-progress-title=*) progress_msg="${i#*=}" ;;
|
|
-reload-table=*) load_single_table_by_title="${i#*=}" ;;
|
|
|
|
*) echo "Unknown parameter passed: $i"; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
# Show progress bar
|
|
function ProgressBar {
|
|
# Process data
|
|
let _progress=(${1}*100/${2}*100)/100
|
|
let _done=(${_progress}*4)/10
|
|
let _left=40-$_done
|
|
# Build progressbar string lengths
|
|
_fill=$(printf "%${_done}s")
|
|
_empty=$(printf "%${_left}s")
|
|
printf "\rProgress : ${_fill// /█}${_empty// / } | ${_progress}%% \t$progress_msg"
|
|
if [ $_progress -eq 100 ]; then
|
|
echo -e
|
|
fi
|
|
}
|
|
|
|
if [[ -e /opt/data/$default_db_name ]]; then
|
|
# Check if table specified & load it
|
|
if [[ "$load_single_table_by_title" ]]; then
|
|
if [[ -e "/opt/data/$default_db_name/$load_single_table_by_title.txt" ]]; then
|
|
mysqlimport --defaults-extra-file=$credentialsFile -d $default_db_name "/opt/data/$default_db_name/$load_single_table_by_title.txt" >/dev/null;
|
|
ProgressBar 1 1
|
|
exit 0
|
|
fi
|
|
else
|
|
# Setup progressbar
|
|
loaded_files=0
|
|
total_files=$(find /opt/data/$default_db_name -type f -name "*.txt" -printf x | wc -c)
|
|
|
|
# Load table data
|
|
for file in /opt/data/$default_db_name/*.txt;
|
|
do
|
|
if [[ -e $file ]]; then
|
|
mysqlimport --defaults-extra-file=$credentialsFile -d $default_db_name $file >/dev/null;
|
|
let loaded_files++
|
|
ProgressBar ${loaded_files} ${total_files}
|
|
fi
|
|
done
|
|
fi
|
|
fi |