Change handling od database files.

This commit is contained in:
Christoph 2017-09-23 01:59:34 +02:00
parent e04e224888
commit ce28ffd467
3 changed files with 92 additions and 3 deletions

View File

@ -212,7 +212,14 @@ fi
if [[ -n "$DATABASE_NAME" ]] ; then if [[ -n "$DATABASE_NAME" ]] ; then
if [[ -z "$DATABASE_USER" || -z "$DATABASE_PASSWD" ]] ; then if [[ -z "$DATABASE_USER" || -z "$DATABASE_PASSWD" ]] ; then
if [[ -f "${working_dir}/databases/$DATABASE_NAME" ]]; then read_file=""
if [[ -f "${working_dir}/databases/DELETED/$DATABASE_NAME" ]]; then
read_file="${working_dir}/databases/DELETED/$DATABASE_NAME"
elif [[ -f "${working_dir}/databases/$DATABASE_NAME" ]]; then
read_file="${working_dir}/databases/$DATABASE_NAME"
fi
if [[ -n "$read_file" ]]; then
while read -r _db_name _db_user _db_pass ; do while read -r _db_name _db_user _db_pass ; do
# - if var '_db_name' begins with '#', that means the readed line # - if var '_db_name' begins with '#', that means the readed line
@ -231,11 +238,12 @@ if [[ -n "$DATABASE_NAME" ]] ; then
break break
fi fi
done < "${working_dir}/databases/$DATABASE_NAME" done < "$read_file"
fi fi
fi fi
fi fi
if $NON_INTERACTIVE_MODE ; then if $NON_INTERACTIVE_MODE ; then
if [[ -z "$DATABASE_USER" ]]; then if [[ -z "$DATABASE_USER" ]]; then
fatal "Database user not given. Maybe missing or wrong file '${working_dir}/databases/$DATABASE_NAME'." fatal "Database user not given. Maybe missing or wrong file '${working_dir}/databases/$DATABASE_NAME'."
@ -429,6 +437,36 @@ else
echo_ok echo_ok
fi fi
if ! $QUIET_MODE ; then
echo ""
fi
echononl " Create directory '${working_dir}/databases'.."
if [[ -d "${working_dir}/databases" ]]; then
echo_skipped
else
mkdir ${working_dir}/databases > $tmp_log_file 2>&1
if [[ $? -ne 0 ]] ; then
echo_failed
error "$(cat $tmp_log_file)"
else
echo_ok
fi
fi
echononl " Remove file '${working_dir}/databases/DELETED/$DATABASE_NAME'"
if [[ -f "${working_dir}/databases/DELETED/$DATABASE_NAME" ]] ; then
rm "${working_dir}/databases/DELETED/$DATABASE_NAME" > $tmp_log_file 2>&1
if [[ $? -ne 0 ]] ; then
echo_failed
error "$(cat $tmp_log_file)"
else
echo_ok
fi
else
echo_skipped
fi
echononl " Create/Renew file '${working_dir}/databases/$DATABASE_NAME'" echononl " Create/Renew file '${working_dir}/databases/$DATABASE_NAME'"
cat <<EOF > "${working_dir}/databases/$DATABASE_NAME" 2> $tmp_log_file 2>&1 cat <<EOF > "${working_dir}/databases/$DATABASE_NAME" 2> $tmp_log_file 2>&1
# <db-name> <db-user> <dp-pass> # <db-name> <db-user> <dp-pass>

View File

@ -211,7 +211,14 @@ fi
if [[ -n "$DATABASE_NAME" ]] ; then if [[ -n "$DATABASE_NAME" ]] ; then
if [[ -z "$DATABASE_USER" || -z "$DATABASE_PASSWD" ]] ; then if [[ -z "$DATABASE_USER" || -z "$DATABASE_PASSWD" ]] ; then
read_file=""
if [[ -f "${working_dir}/databases/$DATABASE_NAME" ]]; then if [[ -f "${working_dir}/databases/$DATABASE_NAME" ]]; then
read_file="${working_dir}/databases/$DATABASE_NAME"
elif [[ -f "${working_dir}/databases/DELETED/$DATABASE_NAME" ]]; then
read_file="${working_dir}/databases/DELETED/$DATABASE_NAME"
fi
if [[ -n "$read_file" ]]; then
while read -r _db_name _db_user _db_pass ; do while read -r _db_name _db_user _db_pass ; do
# - if var '_db_name' begins with '#', that means the readed line # - if var '_db_name' begins with '#', that means the readed line
@ -230,7 +237,7 @@ if [[ -n "$DATABASE_NAME" ]] ; then
break break
fi fi
done < "${working_dir}/databases/$DATABASE_NAME" done < "$read_file"
fi fi
fi fi
fi fi
@ -416,6 +423,48 @@ else
echo_ok echo_ok
fi fi
if ! $QUIET_MODE ; then
echo ""
fi
echononl " Create directory '${working_dir}/databases/DELETED'.."
if [[ -d "${working_dir}/databases/DELETED" ]]; then
echo_skipped
else
mkdir -p "${working_dir}/databases/DELETED" > $tmp_log_file 2>&1
if [[ $? -ne 0 ]] ; then
echo_failed
error "$(cat $tmp_log_file)"
else
echo_ok
fi
fi
echononl " Remove file '${working_dir}/databases/$DATABASE_NAME'"
if [[ -f "${working_dir}/databases/$DATABASE_NAME" ]] ; then
rm "${working_dir}/databases/$DATABASE_NAME" > $tmp_log_file 2>&1
if [[ $? -ne 0 ]] ; then
echo_failed
error "$(cat $tmp_log_file)"
else
echo_ok
fi
else
echo_skipped
fi
echononl " Create/Renew file '${working_dir}/databases/DELETED/$DATABASE_NAME'"
cat <<EOF > "${working_dir}/databases/DELETED/$DATABASE_NAME" 2> $tmp_log_file 2>&1
# <db-name> <db-user> <dp-pass>
$DATABASE_NAME $DATABASE_USER $DATABASE_PASSWD
EOF
if [[ $? -ne 0 ]] ; then
echo_failed
error "$(cat $tmp_log_file)"
else
echo_ok
fi
if ! $QUIET_MODE ; then if ! $QUIET_MODE ; then
echo "" echo ""

View File

@ -3,6 +3,8 @@
src_dir=/root src_dir=/root
dst_dir="/root/bin/mysql/databases" dst_dir="/root/bin/mysql/databases"
mkdir -p $dst_dir
while IFS='' read -r -d '' _file || [[ -n $_file ]] ; do while IFS='' read -r -d '' _file || [[ -n $_file ]] ; do
mv "$_file" "${dst_dir}/${_file##*.}" mv "$_file" "${dst_dir}/${_file##*.}"
done < <(find "$src_dir" -maxdepth 1 -type f -name "databases.txt.*" -print0) done < <(find "$src_dir" -maxdepth 1 -type f -name "databases.txt.*" -print0)