restore_nextcloud.sh: drop database tables befor restoring it.
This commit is contained in:
parent
e502bd1965
commit
0e9148d6a4
@ -5,7 +5,7 @@ script_dir="$(dirname $(realpath $0))"
|
||||
|
||||
conf_dir="${script_dir}/conf"
|
||||
|
||||
declare -a unsorted_website_arr+
|
||||
declare -a unsorted_website_arr
|
||||
declare -a website_arr
|
||||
|
||||
log_file="$(mktemp)"
|
||||
@ -202,7 +202,7 @@ else
|
||||
terminal=false
|
||||
fi
|
||||
|
||||
clear
|
||||
#clear
|
||||
|
||||
echo ""
|
||||
echo -e "\033[32m-----\033[m"
|
||||
@ -512,6 +512,55 @@ elif [[ "$DATABASE_TYPE" = 'postgres' ]]; then
|
||||
fi
|
||||
|
||||
|
||||
if [[ "$DATABASE_TYPE" = 'mysql' ]]; then
|
||||
|
||||
echononl " Get table list from database '$DATABASE_NAME' .."
|
||||
_TABLES="$(mysql $MYSQL_CREDENTIALS $DATABASE_NAME -N -s -e "show tables" 2> $log_file)"
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
echo_failed
|
||||
fatal "$(cat $log_file)"
|
||||
else
|
||||
echo_ok
|
||||
fi
|
||||
|
||||
if [[ -z "$_TABLES" ]]; then
|
||||
|
||||
warn "No tables found in database '$DATABASE_NAME'."
|
||||
|
||||
else
|
||||
|
||||
echononl " Drop tables from database '$DATABASE_NAME' .."
|
||||
_failed=false
|
||||
> $log_file
|
||||
for _table in $_TABLES ; do
|
||||
mysql $MYSQL_CREDENTIALS $DATABASE_NAME -N -s -e "DROP TABLE \`$_table\`" >> $log_file 2>&1
|
||||
if [[ $? -ne 0 ]] ; then
|
||||
_failed=true
|
||||
_tables_not_deleted+=("$_table")
|
||||
fi
|
||||
done
|
||||
if $_failed ; then
|
||||
|
||||
echo_failed
|
||||
error "$(cat $log_file)"
|
||||
|
||||
if [[ ${#_tables_not_deleted[@]} -gt 0 ]] ; then
|
||||
echo ""
|
||||
echo "Tables NOT deleted:"
|
||||
for _table in "${_tables_not_deleted[@]}" ; do
|
||||
echo " $_table"
|
||||
done
|
||||
echo ""
|
||||
fi
|
||||
else
|
||||
echo_ok
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
|
||||
# - Backup current data directory
|
||||
# -
|
||||
echononl " Backup current data directory"
|
||||
|
Loading…
Reference in New Issue
Block a user