external db

Sites with external DB cannot be imported.
Fixed some minor errors.
This commit is contained in:
Cristhian Martínez Ochoa 2022-02-27 13:21:01 -07:00
parent 770287953b
commit d2c58e71dc
3 changed files with 48 additions and 26 deletions

48
lib/bkp
View file

@ -728,28 +728,40 @@ export_site() {
fi
# Include database backup for this site!
if [[ $(is_wp_installed $siteto $subfolder) == "true" ]]; then
# We use dbnames instead of domains because is easier to include subfolders
if [[ -z $export_db_list ]]; then
local export_db_list="$( wp_config_read $siteto DB_NAME $subfolder )"
else
local export_db_list="$export_db_list,$( wp_config_read $siteto DB_NAME $subfolder )"
fi
fi
# Check if site contains WP in subfolders and include these db's.
for sit in "/etc/nginx/apps.d/${siteto}_"*-wpcommon.conf
do
local suby="/$(echo $sit | cut -f 2- -d "_" -s | cut -f -1 -d "-" -s | sed "s/_/\//g")"
if [[ -n $suby && -f /var/www/$siteto/htdocs$suby/wp-config.php ]]; then
if [[ -z $skip_db ]]; then
if [[ $(conf_read mysql) == "true" && $(is_wp $siteto $subfolder) == "true" && $( wp_config_read $siteto DB_HOST $subfolder ) == "localhost" && $(is_wp_installed $siteto $subfolder) == "true" ]]; then
# We use dbnames instead of domains because is easier to include subfolders
if [[ -z $export_db_list ]]; then
local export_db_list="$( wp_config_read $siteto DB_NAME $suby )"
local export_db_list="$( wp_config_read $siteto DB_NAME $subfolder )"
else
local export_db_list="$export_db_list,$( wp_config_read $siteto DB_NAME $suby )"
local export_db_list="$export_db_list,$( wp_config_read $siteto DB_NAME $subfolder )"
fi
echo "${blu}${dim}Database included: ${siteto}${subfolder} ${end}"
elif [[ $(is_wp $siteto $subfolder) == "true" && $( wp_config_read $siteto DB_HOST $subfolder ) == "localhost" ]]; then
echo "${red}${dim}Database not found or empty: ${siteto}${subfolder} ${end}"
elif [[ $(is_wp $siteto $subfolder) == "true" && $( wp_config_read $siteto DB_HOST $subfolder ) != "localhost" ]]; then
echo "${red}${dim}External database not included: ${siteto}${subfolder} ${end}"
fi
local suby=""
done
# Check if site contains WP in subfolders
for sit in "/etc/nginx/apps.d/${siteto}_"*-wpcommon.conf
do
local suby="/$(echo $sit | cut -f 2- -d "_" -s | cut -f -1 -d "-" -s | sed "s/_/\//g")"
if [[ -n $suby && $(conf_read mysql) == "true" && -f /var/www/$siteto/htdocs$suby/wp-config.php && $( wp_config_read $siteto DB_HOST $suby ) == "localhost" && $(is_wp_installed $siteto $suby) == "true" ]]; then
if [[ -z $export_db_list ]]; then
local export_db_list="$( wp_config_read $siteto DB_NAME $suby )"
else
local export_db_list="$export_db_list,$( wp_config_read $siteto DB_NAME $suby )"
fi
echo "${blu}${dim}Database included: ${siteto}${suby} ${end}"
elif [[ -n $suby && -f /var/www/$siteto/htdocs$suby/wp-config.php && $( wp_config_read $siteto DB_HOST $suby ) == "localhost" ]]; then
echo "${red}${dim}Database not found or empty: ${siteto}${suby} ${end}"
elif [[ -n $suby && -f /var/www/$siteto/htdocs$suby/wp-config.php && $( wp_config_read $siteto DB_HOST $suby ) != "localhost" ]]; then
echo "${red}${dim}External database not included: ${siteto}${suby} ${end}"
fi
local suby=""
done
fi
[[ -z $multi_export ]] && break
done

View file

@ -472,13 +472,13 @@ wp_conf_retrieve() {
wp_dbhost=$( wp_config_read $1 DB_HOST $4 )
wp_dbpass=$( wp_config_read $1 DB_PASSWORD $4 )
wp_dbpref=$( grep -F "table_prefix" $wp_config | cut -f 2 -d "'" -s)
extdb_url=$(echo "$wp_dbhost" | cut -f 1 -d ':')
extdb_port=$(echo "$wp_dbhost" | cut -f 2 -d ':' -s)
wp_extdb_url=$(echo "$wp_dbhost" | cut -f 1 -d ':')
wp_extdb_port=$(echo "$wp_dbhost" | cut -f 2 -d ':' -s)
wp_dbpref_main=${wp_dbpref} # In case of domain mapping this variable always remains with the main site info
[[ ${wp_dbhost,,} == "localhost" ]] && wp_dbhost=${wp_dbhost,,}
[[ -z $extdb_port ]] && extdb_port="3306"
[[ -z $wp_extdb_port ]] && wp_extdb_port="3306"
# In case of parked sites with WP domain mapping
if [[ $3 != "false" && $(is_parked $1) == "true" ]]; then
@ -519,14 +519,24 @@ wp_conf_retrieve() {
if [[ -n $external_db ]]; then
external_db_parse
[[ "${wp_dbhost}:${wp_dbport}" != $extdb_host ]] && unset external_db
if [[ $wp_dbhost != $extdb_host ]]; then
unset external_db
unset extdb_user
unset extdb_pass
unset extdb_host
unset extdb_url
unset extdb_port
fi
fi
if [[ -z $external_db && -n $wp_dbhost && $wp_dbhost != "localhost" ]]; then
echo "" >&2
echo "${gre}External DB${blu} '${extdb_url}:${extdb_port}' ${gre}found in${blu} $1 ${gre}(Press 'Enter' key twice to skip)" >&2
echo "${gre}External DB${blu} '${wp_dbhost}' ${gre}found in${blu} ${1}${4} ${gre}(Press 'Enter' key twice to skip)" >&2
read -p "${blu}External DB username: " extdb_user
read -p "External DB password: " extdb_pass
external_db="[$extdb_user,$extdb_pass,${wp_dbhost}:${wp_dbport}]"
extdb_host=$wp_dbhost
extdb_url=$wp_extdb_url
extdb_port=$wp_extdb_port
external_db="[${extdb_user},${extdb_pass},${extdb_host}]"
fi
fi
}

View file

@ -490,10 +490,10 @@ db_delete() {
[[ $wp_dbhost != "localhost" ]] && check_for_mysql_client
if [[ -z $wp_dbhost || -z $wp_dbname || -z $wp_dbuser ]]; then
echo "${red}[ERROR] Database${blu} $domain ${red}cannot be deleted! ${dim}(WP configuration corrupted)${end}"
echo "${red}[ERROR] Database${blu} ${domain}${subfolder} ${red}cannot be deleted! ${dim}(WP configuration corrupted)${end}"
return
elif [[ ( $wp_dbhost == "localhost" && ( $(conf_read mysql) != "true" || $(check_mysql_connection localhost) != "true" )) || ( $wp_dbhost != "localhost" && $(check_mysql_connection $extdb_url $extdb_port $extdb_user $extdb_pass) != "true" ) ]]; then
echo "${red}[ERROR] Database${blu} $domain ${red}cannot be deleted! ${dim}(DB Connection failed)${end}"
echo "${red}[ERROR] Database${blu} ${domain}${subfolder} ${red}cannot be deleted! ${dim}(DB Connection failed)${end}"
return
fi