Compare commits

...

8 Commits

4 changed files with 1846 additions and 100 deletions

View File

@ -25,7 +25,7 @@ mkdir -p ${log_dir}
# - ...
# - "
# -
sync_mysql_databases="ALL"
sync_mysql_databases=""
# - mysql_source_credential_args
# - mysql_target_credential_args
@ -121,6 +121,13 @@ echo_skipped() {
echo -e "\033[80G[ \033[33m\033[1mskipped\033[m ]"
}
trim() {
local var="$*"
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
echo -n "$var"
}
service_exists() {
local n=$1
if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | cut -f1 -d' ') == $n.service ]]; then
@ -217,7 +224,7 @@ sync_mysql_databases="${sync_mysql_databases%%*( )}"
if [[ -z "$sync_mysql_databases" ]]; then
warn "No MySQL databases for syncing configured."
elif [[ "$sync_mysql_databases" = "ALL" ]]; then
elif [[ "$(trim "${sync_mysql_databases}")" = "ALL" ]]; then
echononl " Get MySQL databases from source Installation.."
_mysql_databases_remote="$(${mysql_source_exe} ${mysql_source_credential_args} -N -s -e "show databases" 2> /dev/null)"
if [[ $? -eq 0 ]];then
@ -249,6 +256,43 @@ if $_got_mysql_databases ; then
fi
# - GET current (global) value for 'unique_checks'
# -
echononl " GET current (global) 'unique_checks' value"
CUR_UNIQUE_CHECKS="$(${mysql_target_exe} ${mysql_target_credential_args} -N -s -e "SHOW GLOBAL VARIABLES LIKE 'unique_checks'" | awk '{print$2}')" >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
echo_ok
else
echo_failed
error "$(cat $tmp_err_msg)"
fi
# - GET current (global) value for 'foreign_key_checks'
# -
echononl " GET current (global) 'foreign_key_checks' value"
CUR_FOREIGN_KEY_CHECKS="$(${mysql_target_exe} ${mysql_target_credential_args} -N -s -e "SHOW GLOBAL VARIABLES LIKE 'foreign_key_checks'" | awk '{print$2}')" >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
echo_ok
else
echo_failed
error "$(cat $tmp_err_msg)"
fi
# - GET current (global) value for 'innodb_flush_log_at_trx_commit'
# -
echononl " GET current (global) 'innodb_flush_log_at_trx_commit' value"
CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT="$(${mysql_target_exe} ${mysql_target_credential_args} -N -s -e "SHOW GLOBAL VARIABLES LIKE 'innodb_flush_log_at_trx_commit'" | awk '{print$2}')" >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
echo_ok
else
echo_failed
error "$(cat $tmp_err_msg)"
fi
echo ""
# - Set Autocommit OFF
# -
echononl " Set Autocommit to OFF"
@ -260,8 +304,45 @@ if $_got_mysql_databases ; then
echo_failed
error "$(cat $tmp_err_msg)"
fi
# - Set UNIQUE_CHECKS OFF
# -
echononl " Set 'unique_checks' to OFF"
${mysql_target_exe} ${mysql_target_credential_args} -N -s -e "SET GLOBAL unique_checks='OFF'" >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
echo_ok
else
echo_failed
error "$(cat $tmp_err_msg)"
fi
# - Set FOREIGN_KEY_CHECKS OFF
# -
echononl " Set 'foreign_key_checks' to OFF"
${mysql_target_exe} ${mysql_target_credential_args} -N -s -e "SET GLOBAL foreign_key_checks='OFF'" >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
echo_ok
else
echo_failed
error "$(cat $tmp_err_msg)"
fi
# - Set innodb_flush_log_at_trx_commit OFF
# -
echononl " Set 'innodb_flush_log_at_trx_commit' to 2"
${mysql_target_exe} ${mysql_target_credential_args} -N -s -e "SET GLOBAL innodb_flush_log_at_trx_commit=2" >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
echo_ok
else
echo_failed
error "$(cat $tmp_err_msg)"
fi
echo ""
for _val in $_mysql_databases_remote ; do
IFS=':' read -a _val_arr <<< "${_val}"
@ -336,6 +417,39 @@ if $_got_mysql_databases ; then
error "$(cat $tmp_err_msg)"
fi
# - Reset (global) value for 'unique_checks'
# -
echononl " Reset (global) 'unique_checks' value to '$CUR_UNIQUE_CHECKS'"
${mysql_target_exe} ${mysql_target_credential_args} -N -s -e "SET GLOBAL unique_checks='$CUR_UNIQUE_CHECKS'" >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
echo_ok
else
echo_failed
error "$(cat $tmp_err_msg)"
fi
# - Reset (global) value for 'foreign_key_checks'
# -
echononl " Reset (global) 'foreign_key_checks' value to '$CUR_FOREIGN_KEY_CHECKS'"
${mysql_target_exe} ${mysql_target_credential_args} -N -s -e "SET GLOBAL foreign_key_checks='$CUR_FOREIGN_KEY_CHECKS'" >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
echo_ok
else
echo_failed
error "$(cat $tmp_err_msg)"
fi
# - Reset (global) value for 'innodb_flush_log_at_trx_commit'
# -
echononl " Reset (global) 'innodb_flush_log_at_trx_commit' value to '$CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT'"
${mysql_target_exe} ${mysql_target_credential_args} -N -s -e "SET GLOBAL innodb_flush_log_at_trx_commit=$CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT" >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
echo_ok
else
echo_failed
error "$(cat $tmp_err_msg)"
fi
fi
rm $tmp_err_msg

View File

@ -0,0 +1,343 @@
#!/usr/bin/env bash
script_name="$(basename $(realpath $0))"
script_dir="$(dirname $(realpath $0))"
conf_dir="${script_dir}/conf"
tmp_err_msg=$(mktemp)
log_dir=/root/sync_from_old_server_logs
mkdir -p ${log_dir}
# - Sync MySQL databases
# -
# - Note:
# - Set to "ALL" if all databases from old server should be synced
# - Leave empty if no databases should be synced.
# -
# - Example:
# - To sync database 'shop19' aot source host to database 'shop19_dev'
# - at destination host:
# - sync_mysql_databases="
# - ...
# - shop19:shop19_dev
# - ...
# - "
# -
sync_mysql_databases="ALL"
# - mysql_source_credential_args
# - mysql_target_credential_args
# -
# - Example
# - mysql_credential_args="-u root -S /run/mysqld/mysqld.sock"
# - mysql_credential_args="--defaults-file=/usr/local/mysql/sys-maint.cnf"
# - mysql_credential_args="--login-path=local"
# - mysql_credential_args="-u <db_name> -p'<db_passwd>'"
# -
mysql_source_credential_args="-u root -pbuz111 -S /run/mysqld/mysqld-5.7.sock"
mysql_target_credential_args="-u root -S /run/mysqld/mysqld.sock"
mysqldump_exe="/usr/local/mysql/bin/mysqldump"
mysql_source_exe="/usr/local/mysql/bin/mysql"
mysql_target_exe="/usr/bin/mysql"
mysql_source_version="$(${mysql_source_exe} -V | awk '{print$5}')"
mysql_target_version="$(${mysql_target_exe} -V | awk '{print$5}')"
# Remove leading / trailling point sign ','
#
mysql_source_version="${mysql_source_version%\,}"
mysql_target_version="${mysql_target_version%\,}"
# - mysqldump parameters/options
# -
mysql_max_allowed_packet="1024M"
# -------------
# --- Some functions
# -------------
echononl(){
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
echo -e -n "$*\\c" 1>&2
else
echo -e -n "$*" 1>&2
fi
rm /tmp/shprompt$$
}
fatal(){
echo ""
if [[ -z "$*" ]] ; then
echo -e "\t\033[31m\033[1mScript will be interrupted\033[m\033[m"
else
echo -e "\t[ \033[31m\033[1mFatal Error\033[m ]: $*"
echo ""
echo -e "\t\033[31m\033[1mScript will be interrupted\033[m\033[m"
fi
echo ""
exit 1
}
error(){
echo ""
echo -e "\t[ \033[31m\033[1mFehler\033[m ]: $*"
echo ""
}
warn (){
echo ""
echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*"
echo ""
}
info (){
echo ""
echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*"
echo ""
}
echo_done() {
echo -e "\033[80G[ \033[32mdone\033[m ]"
}
echo_ok() {
echo -e "\033[80G[ \033[32mok\033[m ]"
}
echo_ok() {
echo -e "\033[80G[ \033[32mok\033[m ]"
}
echo_warning() {
echo -e "\033[80G[ \033[33m\033[1mwarn\033[m ]"
}
echo_failed(){
echo -e "\033[80G[ \033[1;31mfailed\033[m ]"
}
echo_skipped() {
echo -e "\033[80G[ \033[33m\033[1mskipped\033[m ]"
}
service_exists() {
local n=$1
if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | cut -f1 -d' ') == $n.service ]]; then
return 0
else
return 1
fi
}
# ----------
# - Is this a systemd system?
# -
if [[ "X$(which systemd)" = "X" ]]; then
systemd_exists=false
else
systemd_exists=true
fi
echo ""
# ==========
# - Begin Main Script
# ==========
# ----------
# - Headline
# ----------
clear
if $terminal ; then
echo ""
echo -e "\033[1m----------\033[m"
echo -e "\033[32m\033[1mRunning script \033[m\033[1m$script_name\033[32m .. \033[m"
echo -e "\033[1m----------\033[m"
fi
echo ""
echo -e " \033[32mParameter Summary:\033[m"
echo ""
echo -e " MySQL source version..................: ${mysql_source_version}"
echo -e " MySQL target version..................: ${mysql_target_version}"
echo ""
echo -e " MySQL client binary source version....: ${mysql_source_exe}"
echo -e " MySQL client binary target version....: ${mysql_target_exe}"
echo ""
echo -e " MySQL credentials source versions.....: ${mysql_source_credential_args}"
echo -e " MySQL credentials target versions.....: ${mysql_target_credential_args}"
echo ""
_error=false
if [[ ! -x "${mysql_source_exe}" ]] ; then
error "No mysql binary \033[1m${mysql_source_exe}\033[m found (VAR mysql_source_exe)."
_error=true
fi
if [[ ! -x "${mysql_target_exe}" ]] ; then
error "No mysql binary \033[1m${mysql_target_exe}\033[m found (VAR mysql_target_exe)."
_error=true
fi
if $_error ; then
fatal Wrong or Missing Parameter..
fi
echo ""
echononl " \033[33mContinue with this parameters? [\033[1myes/no\033[m]: "
read OK
while [[ "${OK,,}" != "yes" ]] && [[ "${OK,,}" != "no" ]] ; do
echononl " \033[33mWrong entry!\033[m [\033[1myes/no\033[m]: "
read OK
done
[[ "${OK,,}" = "yes" ]] || fatal "Canceled by user input."
if $terminal ; then
echo ""
echo ""
echo -e " \033[32m-----\033[m"
echo -e " \033[1mSyncing MySQL Databases from Version '${mysql_source_version}' to Version '${mysql_target_version} ..\033[m"
echo -e " \033[32m-----\033[m"
fi
echo ""
_got_mysql_databases=false
sync_mysql_databases="${sync_mysql_databases##*( )}"
sync_mysql_databases="${sync_mysql_databases%%*( )}"
if [[ -z "$sync_mysql_databases" ]]; then
warn "No MySQL databases for syncing configured."
elif [[ "$sync_mysql_databases" = "ALL" ]]; then
echononl " Get MySQL databases from source Installation.."
_mysql_databases_remote="$(${mysql_source_exe} ${mysql_source_credential_args} -N -s -e "show databases" 2> /dev/null)"
if [[ $? -eq 0 ]];then
echo_ok
_got_mysql_databases=true
else
echo_failed
fi
else
_mysql_databases_remote="$sync_mysql_databases"
_got_mysql_databases=true
fi
if $_got_mysql_databases ; then
log_file=${log_dir}/sync_mysql.log
> $log_file
mysqldump_flags="--protocol=SOCKET --max-allowed-packet=${mysql_max_allowed_packet} --skip-opt --add-drop-table --add-locks --create-options --quick --set-charset --disable-keys --lock-tables --routines"
# - GET current (global) Autocommit value
# -
echononl " GET current (global) Autocommit value"
CUR_AUTOCOMMIT="$(${mysql_target_exe} ${mysql_target_credential_args} -N -s -e "SHOW GLOBAL VARIABLES LIKE 'autocommit'" | awk '{print$2}')" >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
echo_ok
else
echo_failed
error "$(cat $tmp_err_msg)"
fi
# - Set Autocommit OFF
# -
echononl " Set Autocommit to OFF"
${mysql_target_exe} ${mysql_target_credential_args} -N -s -e "SET GLOBAL AUTOCOMMIT='OFF'" \
>> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
echo_ok
else
echo_failed
error "$(cat $tmp_err_msg)"
fi
echo ""
for _val in $_mysql_databases_remote ; do
IFS=':' read -a _val_arr <<< "${_val}"
_src_db="${_val_arr[0]}"
if [[ -n "${_val_arr[1]}" ]] ; then
_dst_db="${_val_arr[1]}"
echononl " Sync Database '$_src_db' --> '$_dst_db'.. "
else
echononl " Sync Database '$_src_db'.. "
_dst_db="$_src_db"
fi
if [[ "${_src_db}" = "information_schema" ]]; then
echo_skipped
continue
fi
if [[ "${_src_db}" = "performance_schema" ]]; then
echo_skipped
continue
fi
if [[ "${_src_db}" = "mysql" ]]; then
echo_skipped
continue
fi
if [[ "${_src_db}" = "sys" ]]; then
echo_skipped
continue
fi
if [[ "${_src_db}" = "test" ]] || [[ "${_src_db}" = "mysqltest" ]] ; then
echo_skipped
continue
fi
${mysqldump_exe} ${mysql_source_credential_args} $_src_db 2> /dev/null \
| ${mysql_target_exe} ${mysql_target_credential_args} ${_dst_db} >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
echo_ok
else
echo_failed
error "$(cat $tmp_err_msg)"
echo -e "
\033[33mcommand was:\033[m
\033[1m${mysqldump_exe} ${mysql_source_credential_args} $_src_db 2> /dev/null \\
| ${mysql_target_exe} ${mysql_target_credential_args} ${_dst_db}\033[m
"
echononl "\n continue anyway [yes/no]: "
read OK
OK=${OK,,}
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
echononl "Wrong entry! - repeat [yes/nno]: "
read OK
done
[[ $OK = "yes" ]] || fatal "Abbruch durch User"
fi
done
# - Reset (global) Autocommit value
# -
echo ""
echononl " Reset (global) Autocommit value to '$CUR_AUTOCOMMIT'"
${mysql_target_exe} ${mysql_target_credential_args} -N -s -e "SET GLOBAL AUTOCOMMIT='${CUR_AUTOCOMMIT}'" \
>> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
echo_ok
else
echo_failed
error "$(cat $tmp_err_msg)"
fi
fi
rm $tmp_err_msg
echo ""
exit 0

View File

@ -1,6 +1,8 @@
#!/usr/bin/env bash
ipv4_old="83.223.86.121"
# give old IPv4 address here - its mandatory"
#
ipv4_old="<SRC-IP_ADDRESS>"
old_server_ip=$ipv4_old
tmp_err_msg=$(mktemp)
@ -45,15 +47,21 @@ sync_web_dirs=""
# - Sync Apache virtual host configurations
# -
# - Note:
# - Note - following files are excluded:
# -
# - 000-default.conf
# - 000-dehydrated.conf
# - 000-logformat.conf
# - 000-deflate.conf
# - 000-additional-ssl-settings.conf
# -
sync_vhost_dirs=""
# - Only needed to replace ip-addresse in virtual host configuration files
# -
ipv4_new="83.223.90.20"
ipv6_old="2a01:30:0:13:2e0:7bff:fe9a:b18a"
ipv6_new="2a01:31:0:2::f851:1"
ipv4_new=""
ipv6_old=""
ipv6_new=""
# - Sync dehydrated cert directory
@ -72,6 +80,14 @@ sync_dehydrated_dirs=""
# - ...
# - "
# -
# - Examples:
# -
# - sync_other_dirs="
# - /etc/cron.d:/data/old-server/etc/cron.d
# - /opt:/data/old-server/opt
# - /root/crontab
# - /usr/local/bin
# - "
# -
# - Note:
# - the basename of the destination directory must be the same as
@ -120,13 +136,26 @@ sync_mysql_databases=""
# - mysql_credential_args="--login-path=local"
# - mysql_credential_args="-u <db_name> -p'<db_passwd>'"
# -
mysql_remote_credential_args=""
mysql_local_credential_args=""
mysql_remote_credential_args="--login-path=local"
mysql_local_credential_args="-S /run/mysqld/mysqld.sock"
# -------------
# --- Some functions
# -------------
clean_up() {
# Perform program exit housekeeping
#rm -rf "$LOCK_DIR"
rm $tmp_err_msg
blank_line
exit $1
}
echononl(){
if $terminal ; then
echo X\\c > /tmp/shprompt$$
if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then
echo -e -n "$*\\c" 1>&2
@ -134,52 +163,96 @@ echononl(){
echo -e -n "$*" 1>&2
fi
rm /tmp/shprompt$$
fi
}
fatal(){
echo ""
echo -e "fatal error: $*"
if $terminal ; then
echo -e " [ \033[31m\033[1mFatal\033[m ]: $*"
echo ""
echo -e "\t\033[31m\033[1mInstalllation will be interrupted\033[m\033[m"
echo -e " \033[31m\033[1mScript was interupted\033[m!"
else
echo " [ Fatal ]: $*"
echo ""
exit 1
echo " Script was terminated...."
fi
echo ""
clean_up 1
}
error(){
echo ""
if $terminal ; then
echo -e "\t[ \033[31m\033[1mFehler\033[m ]: $*"
else
echo "[ Error ]: $*"
fi
echo ""
}
warn (){
echo ""
if $terminal ; then
echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*"
else
echo "[ Warning ]: $*"
fi
echo ""
}
warn_only_terminal () {
if $terminal ; then
echo ""
echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*"
echo ""
fi
}
info (){
if $terminal ; then
echo ""
echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*"
echo ""
fi
}
echo_done() {
if $terminal ; then
echo -e "\033[80G[ \033[32mdone\033[m ]"
fi
}
echo_ok() {
if $terminal ; then
echo -e "\033[80G[ \033[32mok\033[m ]"
fi
}
echo_ok() {
if $terminal ; then
echo -e "\033[80G[ \033[32mok\033[m ]"
fi
}
echo_warning() {
if $terminal ; then
echo -e "\033[80G[ \033[33m\033[1mwarn\033[m ]"
fi
}
echo_failed(){
if $terminal ; then
echo -e "\033[80G[ \033[1;31mfailed\033[m ]"
fi
}
echo_skipped() {
if $terminal ; then
echo -e "\033[80G[ \033[33m\033[1mskipped\033[m ]"
fi
}
blank_line() {
if $terminal ; then
echo ""
fi
}
detect_mysql_version () {
@ -199,6 +272,7 @@ detect_mysql_version () {
elif [[ -d "/usr/local/mysql" ]] && [[ "$(basename "$(realpath "/usr/local/mysql")")" =~ mariadb- ]]; then
MYSQL_CUR_DISTRIBUTION="MariaDB"
else
if $terminal ; then
error "MySQL Instalation found, but cannot determin the distribution!"
MYSQL_CUR_DISTRIBUTION=
@ -227,6 +301,9 @@ detect_mysql_version () {
;;
esac
done
else
fatal "MySQL Instalation found, but cannot determin the distribution!"
fi
fi
MYSQL_VERSION="$(echo $_MYSQLD_VERSION | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?" | head -n 1)"
@ -239,7 +316,7 @@ detect_mysql_version () {
service_exists() {
local n=$1
if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | cut -f1 -d' ') == $n.service ]]; then
if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | awk '{print$1}') == $n.service ]]; then
return 0
else
return 1
@ -247,6 +324,20 @@ service_exists() {
}
# ----------
# - Some checks ..
# ----------
# - Running in a terminal?
# -
if [[ -t 1 ]] ; then
terminal=true
else
terminal=false
fi
# ----------
@ -265,7 +356,8 @@ else
systemd_exists=true
fi
echo ""
blank_line
echononl " Test ssh connection to $old_server_ip"
ssh $old_server_ip "ls" > /dev/null 2> $tmp_err_msg
@ -277,6 +369,68 @@ else
fi
echononl " Backup file /root/bin/.ssh/config"
if [[ -f "/root/.ssh/config" ]] ; then
mv "/root/.ssh/config" "/root/.ssh/config.${cur_date}" > /dev/null 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
echo_ok
else
echo_failed
if $terminal ; then
error "$(cat $tmp_err_msg)"
echononl "continue anyway [yes/no]: "
read OK
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
echononl "Wrong entry! - repeat [yes/no]: "
read OK
done
[[ $OK = "yes" ]] || fatal "Interupted by user"
else
fatal "$(cat $tmp_err_msg)"
fi
fi
else
echo_skipped
fi
echononl " Create temporary file \033[1m/root/.ssh/config\033[m .."
cat <<EOF > "/root/.ssh/config"
Host *
ControlMaster auto
ControlPath ~/.ssh/%r@%h:%p
ControlPersist 30
StrictHostKeyChecking no
LogLevel FATAL
EOF
if [[ $? -eq 0 ]];then
echo_ok
ssh_config_exists=true
else
echo_failed
if $terminal ; then
error "$(cat $tmp_err_msg)"
echononl "continue anyway [yes/no]: "
read OK
OK="$(echo "$OK" | tr '[:upper:]' '[:lower:]')"
while [[ "$OK" != "yes" ]] && [[ "$OK" != "no" ]] ; do
echononl "Wrong entry! - repeat [yes/no]: "
read OK
done
[[ $OK = "yes" ]] || fatal "Interupted by user"
else
fatal "$(cat $tmp_err_msg)"
fi
fi
# - Create log directory
# -
@ -296,14 +450,16 @@ fi
# - Syncing PostgreSQL Databases.."
# -
if $terminal ; then
echo -e "\n\n \033[37m\033[1mSyncing PostgreSQL Databases..\033[m\n"
fi
_got_pgsql_databases=false
sync_pgsql_databases="${sync_pgsql_databases##*( )}"
sync_pgsql_databases="${sync_pgsql_databases%%*( )}"
if [[ -z "$sync_pgsql_databases" ]]; then
warn "No PostgreSQL databases for syncing configured."
warn_only_terminal "No PostgreSQL databases for syncing configured."
elif [[ "$sync_pgsql_databases" = "ALL" ]]; then
echononl " Get (all) PostgreSQL databases from $old_server_ip.."
_psql_databases=$(ssh $old_server_ip "cd /tmp ; sudo -u postgres psql -lt" 2> $tmp_err_msg | grep -v -e"^$" | awk '{print$1}')
@ -340,7 +496,7 @@ if $_got_pgsql_databases ; then
sudo=$(ssh $old_server_ip which sudo 2> /dev/null)
su=$(ssh $old_server_ip which su 2> /dev/null)
echo ""
blank_line
for _db in $_pgsql_databases_remote ; do
echononl " Sync Database '$_db'.."
if [[ "${_db}" = "template0" ]] || [[ "${_db}" = "template1" ]] || [[ "${_db}" = "postgres" ]]; then
@ -368,10 +524,12 @@ fi
# - Syncing MySQL Databases.."
# -
if $terminal; then
echo -e "\n\n \033[37m\033[1mSyncing MySQL Databases..\033[m\n"
fi
if [[ -z "$sync_mysql_databases" ]]; then
warn "No MySQL databases for syncing configured."
warn_only_terminal "No MySQL databases for syncing configured."
else
detect_mysql_version
@ -481,7 +639,7 @@ if $_got_mysql_databases ; then
echo_failed
error "$(cat $tmp_err_msg)"
fi
echo ""
blank_line
# - Set Autocommit OFF
@ -563,7 +721,7 @@ if $_got_mysql_databases ; then
continue
fi
echo ""
blank_line
if [[ -n "${_val_arr[1]}" ]] ; then
echononl " Sync Database '$_src_db' --> '$_dst_db'.. "
else
@ -577,7 +735,9 @@ if $_got_mysql_databases ; then
echo_failed
error "$(cat $tmp_err_msg)"
if $terminal ; then
echo -e "\n\n \033[33mSomething went wromg! I'm trying an alternative way ..\033[m\n"
fi
echononl " Read remote DB '${_src_db}' into local file '/tmp/${_dst_db}-${cur_date}.sql'.."
@ -625,7 +785,7 @@ if $_got_mysql_databases ; then
# - Reset (global) Autocommit value
# -
echo ""
blank_line
echononl " Reset (global) Autocommit value to '$CUR_AUTOCOMMIT'"
${l_mysql} $mysql_local_credential_args -N -s -e "SET GLOBAL AUTOCOMMIT='$CUR_AUTOCOMMIT'" >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
@ -637,7 +797,7 @@ if $_got_mysql_databases ; then
# - Reset (global) value for 'unique_checks'
# -
echo ""
blank_line
echononl " Reset (global) 'unique_checks' value to '$CUR_UNIQUE_CHECKS'"
${l_mysql} $mysql_local_credential_args -N -s -e "SET GLOBAL unique_checks='$CUR_UNIQUE_CHECKS'" >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
@ -649,7 +809,7 @@ if $_got_mysql_databases ; then
# - Reset (global) value for 'foreign_key_checks'
# -
echo ""
blank_line
echononl " Reset (global) 'foreign_key_checks' value to '$CUR_FOREIGN_KEY_CHECKS'"
${l_mysql} $mysql_local_credential_args -N -s -e "SET GLOBAL foreign_key_checks='$CUR_FOREIGN_KEY_CHECKS'" >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
@ -661,7 +821,7 @@ if $_got_mysql_databases ; then
# - Reset (global) value for 'innodb_flush_log_at_trx_commit'
# -
echo ""
blank_line
echononl " Reset (global) 'innodb_flush_log_at_trx_commit' value to '$CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT'"
${l_mysql} $mysql_local_credential_args -N -s -e "SET GLOBAL innodb_flush_log_at_trx_commit=$CUR_INNODB_FLUSH_LOG_AT_TRX_COMMIT" >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
@ -674,14 +834,15 @@ if $_got_mysql_databases ; then
fi
if $terminal ; then
echo -e "\n\n \033[37m\033[1mSyncing Home Directories..\033[m\n"
fi
_got_home_dirs=false
sync_home_dirs="${sync_home_dirs##*( )}"
sync_home_dirs="${sync_home_dirs%%*( )}"
if [[ -z "${sync_home_dirs,,}" ]] ; then
warn "No Home Directories for syncing configured"
warn_only_terminal "No Home Directories for syncing configured"
else
_got_home_dirs=true
fi
@ -701,15 +862,16 @@ if $_got_home_dirs ; then
done
fi
if $terminal ; then
echo -e "\n\n \033[37m\033[1mSyncing Files..\033[m\n"
fi
_got_files=false
sync_files="${sync_files##*( )}"
sync_files="${sync_files%%*( )}"
if [[ -z "${sync_files,,}" ]] ; then
warn "No Files for syncing configured"
warn_only_terminal "No Files for syncing configured"
else
_got_files=true
fi
@ -729,14 +891,15 @@ if $_got_files ; then
done
fi
if $terminal ; then
echo -e "\n\n \033[37m\033[1mSyncing Web Directories..\033[m\n"
fi
_got_web_dirs=false
sync_web_dirs="${sync_web_dirs##*( )}"
sync_web_dirs="${sync_web_dirs%%*( )}"
if [[ -z "${sync_web_dirs,,}" ]] ; then
warn "No Web Directories for syncing configured"
warn_only_terminal "No Web Directories for syncing configured"
else
_got_web_dirs=true
fi
@ -750,8 +913,10 @@ if $_got_web_dirs ; then
_src_dir="${_val_arr[0]}"
if [[ -n "${_val_arr[1]}" ]] ; then
_dst_dir="${_val_arr[1]}"
if $terminal ; then
echo -e " Syncinc directory \"${_src_dir}\""
echononl " --> ${_dst_dir} .."
fi
else
_dst_dir="$_src_dir"
echononl " Syncinc directory \"${_src_dir}\".."
@ -776,14 +941,15 @@ fi
if $terminal ; then
echo -e "\n\n \033[37m\033[1mSyncing Vhost Configurations..\033[m\n"
fi
_got_vhost_dirs=false
sync_vhost_dirs="${sync_vhost_dirs##*( )}"
sync_vhost_dirs="${sync_vhost_dirs%%*( )}"
if [[ -z "${sync_vhost_dirs,,}" ]] ; then
warn "No Vhost Configurations for syncing configured"
warn_only_terminal "No Vhost Configurations for syncing configured"
else
_got_vhost_dirs=true
fi
@ -798,6 +964,7 @@ if $_got_vhost_dirs ; then
--exclude 000-dehydrated.conf \
--exclude 000-logformat.conf \
--exclude 000-deflate.conf \
--exclude 000-additional-ssl-settings.conf \
$old_server_ip:$sync_dir $(dirname $sync_dir)/ >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
echo_ok
@ -809,8 +976,9 @@ if $_got_vhost_dirs ; then
fi
if $terminal ; then
echo -e "\n\n \033[37m\033[1mConvert IP's in Vhost Configurations..\033[m\n"
fi
if $_got_vhost_dirs ; then
log_file=${log_dir}/convert_vhost_configs.log
@ -829,6 +997,7 @@ if $_got_vhost_dirs ; then
[[ "$(basename $_file)" = "000-dehydrated.conf" ]] && continue
[[ "$(basename $_file)" = "000-logformat.conf" ]] && continue
[[ "$(basename $_file)" = "000-deflate.conf" ]] && continue
[[ "$(basename $_file)" = "000-additional-ssl-settings.conf" ]] && continue
if [[ -f "$_file" ]]; then
@ -869,17 +1038,18 @@ if $_got_vhost_dirs ; then
fi
done
else
warn "No Vhost Configurations for syncing configured, so no IP conversion done.."
warn_only_terminal "No Vhost Configurations for syncing configured, so no IP conversion done.."
fi
if $terminal ; then
echo -e "\n\n \033[37m\033[1mSyncing Dehydrated Certs Dirs ..\033[m\n"
fi
_got_dehydrated_dirs_dirs=false
sync_dehydrated_dirs="${sync_dehydrated_dirs##*( )}"
sync_dehydrated_dirs="${sync_dehydrated_dirs%%*( )}"
if [[ -z "${sync_dehydrated_dirs,,}" ]] ; then
warn "No other Directories for syncing configured"
warn_only_terminal "No dehydrated Directories for syncing configured"
else
_got_dehydrated_dirs_dirs=true
fi
@ -899,14 +1069,15 @@ if $_got_dehydrated_dirs_dirs ; then
done
fi
if $terminal ; then
echo -e "\n\n \033[37m\033[1mSyncing other Directories..\033[m\n"
fi
_got_other_dirs=false
sync_other_dirs="${sync_other_dirs##*( )}"
sync_other_dirs="${sync_other_dirs%%*( )}"
if [[ -z "${sync_other_dirs,,}" ]] ; then
warn "No other Directories for syncing configured"
warn_only_terminal "No other Directories for syncing configured"
else
_got_other_dirs=true
fi
@ -920,8 +1091,10 @@ if $_got_other_dirs ; then
_src_dir="${_val_arr[0]}"
if [[ -n "${_val_arr[1]}" ]] ; then
_dst_dir="${_val_arr[1]}"
if $terminal ; then
echo -e " Syncinc directory \"${_src_dir}\""
echononl " --> ${_dst_dir} .."
fi
else
_dst_dir="$_src_dir"
echononl " Syncinc directory \"${_src_dir}\".."
@ -943,7 +1116,9 @@ if $_got_other_dirs ; then
done
fi
if $terminal ; then
echo -e "\n\n \033[37m\033[1mSome post syncing stuff..\033[m\n"
fi
echononl " Recreate PureFTPd's password database"
if [[ -f "/etc/pure-ftpd/pureftpd.passwd" ]]; then
@ -959,7 +1134,24 @@ else
fi
echononl " Restore file \033\033[1m/root/.ssh/config\033[m .."
if [[ -f "/root/.ssh/config.${cur_date}" ]] ; then
mv "/root/.ssh/config.${cur_date}" "/root/.ssh/config" > /dev/null 2> $tmp_err_msg
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $tmp_err_msg)"
fi
else
echo_skipped
fi
if $terminal ; then
echo -e "\n\n \033[37m\033[1mRestart Services..\033[m\n"
fi
echononl " (Re)start PureFTPd daemon (pure-ftpd)"
if $systemd_exists ; then
@ -1015,6 +1207,4 @@ fi
rm $tmp_err_msg
echo ""
exit 0
clean_up 0

1099
sync_from_old_server.sh.00 Executable file

File diff suppressed because it is too large Load Diff