sync_from_old_server.sh: replace 'mysql_credential_args' with 'mysql_remote_credential_args' and 'mysql_local_credential_args'.

This commit is contained in:
Christoph 2023-03-04 22:22:43 +01:00
parent f32a8e1369
commit 0d891f7c88

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
ipv4_old="83.223.86.98"
ipv4_old="<old-ipv4-address>"
old_server_ip=$ipv4_old
tmp_err_msg=$(mktemp)
@ -14,7 +14,7 @@ log_dir=/root/sync_from_old_server_logs
# /data/home/max
#"
sync_home_dirs="
/home/ilker
/home/confluence
"
@ -40,28 +40,24 @@ sync_home_dirs="
# - /home/chris
# - "
# -
sync_web_dirs="
"
sync_web_dirs=""
# - Sync Apache virtual host configurations
# -
# - Note:
# -
sync_vhost_dirs="
/usr/local/apache2/conf/vhosts
"
sync_vhost_dirs=""
# - Only needed to replace ip-addresse in virtual host configuration files
# -
ipv4_new="162.55.82.78"
ipv6_old="2a01:30:0:13:211:84ff:feb7:7f9c"
ipv6_new="2a01:4f8:271:1266::78"
ipv4_new="<new-ipv4-address>"
ipv6_old="<old-ipv6-address>"
ipv6_new="<new-ipv6-address>"
# - Sync dehydrated cert directory
# -
sync_dehydrated_dirs=""
sync_dehydrated_dirs="
/var/lib/dehydrated/certs
"
@ -85,13 +81,13 @@ sync_dehydrated_dirs="
# -
sync_other_dirs="
/root/bin/mysql/databases
/usr/local/webalizer/etc
"
# - Sync files
# -
sync_files="
/var/lib/dehydrated/domains.txt
/etc/pure-ftpd/pureftpd.passwd
"
@ -121,15 +117,17 @@ sync_pgsql_databases=""
# -
sync_mysql_databases="ALL"
# - mysql_credential_args
# - mysql_remote_credential_args
# - mysql_local_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_credential_args="--login-path=local"
mysql_remote_credential_args="--login-path=local"
mysql_local_credential_args="-u root -S /run/mysqld/mysqld.sock"
# -------------
# --- Some functions
@ -317,7 +315,7 @@ if [[ -z "$sync_mysql_databases" ]]; then
warn "No MySQL databases for syncing configured."
elif [[ "$sync_mysql_databases" = "ALL" ]]; then
echononl " Get MySQL databases from $old_server_ip.."
_mysql_databases_remote=$(ssh $old_server_ip "/usr/local/mysql/bin/mysql $mysql_credential_args -N -s -e \"show databases\"")
_mysql_databases_remote=$(ssh $old_server_ip "/usr/local/mysql/bin/mysql $mysql_remote_credential_args -N -s -e \"show databases\"")
if [[ $? -eq 0 ]];then
echo_ok
_got_mysql_databases=true
@ -338,7 +336,7 @@ if $_got_mysql_databases ; then
# - GET current (global) Autocommit value
# -
echononl " GET current (global) Autocommit value"
CUR_AUTOCOMMIT="$(/usr/local/mysql/bin/mysql $mysql_credential_args -N -s -e "SHOW GLOBAL VARIABLES LIKE 'autocommit'" | awk '{print$2}')" >> $log_file 2> $tmp_err_msg
CUR_AUTOCOMMIT="$(mysql $mysql_local_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
@ -350,7 +348,7 @@ if $_got_mysql_databases ; then
# - Set Autocommit OFF
# -
echononl " Set Autocommit to OFF"
mysql $mysql_credential_args -N -s -e "SET GLOBAL AUTOCOMMIT='OFF'" >> $log_file 2> $tmp_err_msg
mysql $mysql_local_credential_args -N -s -e "SET GLOBAL AUTOCOMMIT='OFF'" >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
echo_ok
else
@ -391,7 +389,7 @@ if $_got_mysql_databases ; then
echo_skipped
continue
fi
ssh $old_server_ip "/usr/local/mysql/bin/mysqldump $mysql_credential_args $_src_db" | mysql $mysql_credential_args $_dst_db >> $log_file 2> $tmp_err_msg
ssh $old_server_ip "/usr/local/mysql/bin/mysqldump $mysql_remote_credential_args $_src_db" | mysql $mysql_local_credential_args $_dst_db >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
echo_ok
else
@ -405,7 +403,7 @@ if $_got_mysql_databases ; then
# -
echo ""
echononl " Reset (global) Autocommit value to '$CUR_AUTOCOMMIT'"
mysql $mysql_credential_args -N -s -e "SET GLOBAL AUTOCOMMIT='$CUR_AUTOCOMMIT'" >> $log_file 2> $tmp_err_msg
mysql $mysql_local_credential_args -N -s -e "SET GLOBAL AUTOCOMMIT='$CUR_AUTOCOMMIT'" >> $log_file 2> $tmp_err_msg
if [[ $? -eq 0 ]];then
echo_ok
else