From 83bd3db9b9a87e1d3cfe2cbce961d0e74475703b Mon Sep 17 00:00:00 2001 From: Christoph Date: Tue, 23 Jan 2018 02:54:48 +0100 Subject: [PATCH] Add support of databases from more than one MySQL installation. --- .gitignore | 1 + hosts/backup_script.sh.sample | 18 ++++++++++++++++-- hosts/scripts/main_part.include | 21 ++++++++++++++++++--- hosts/scripts/mysql_backup.sh | 2 +- rcopy.sh | 1 + 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 51b9f49..ae12556 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.swp /conf/logrotate.conf /conf/rcopy.conf /conf/*.key diff --git a/hosts/backup_script.sh.sample b/hosts/backup_script.sh.sample index 638df72..2ceae1b 100644 --- a/hosts/backup_script.sh.sample +++ b/hosts/backup_script.sh.sample @@ -98,12 +98,26 @@ mysql_backup=false ## - encrypted option file instead. ## - ## - 1.) Create (encrypted) option file: -## - $ mysql_config_editor set --login-path=local --socket=/var/run/mysqld/mysqld.sock --user=backup --password -## - $ Password: +## - $ mysql_config_editor set --login-path=local --socket=/tmp/mysql.sock --user=backup --password +## - $ Password: +## - +## - Its possible to hold more than one credentials in this (encrypted) option file: +## - $ mysql_config_editor set --login-path=local-5.6 --socket=/tmp/mysql-5.6.sock --user=backup --password +## - ## - ## - 2.) Set environment variable mysql_credential_args="--login-path=local" ## - Now, the backup script uses the encrypted option file instead of (unencrypt) password ## - on command line. +## - +## - You can backup databases from different mysql installations i.e. for a (main) +## - MySQL installation and a second one using variable 'mysql_credential_args_arr': +## - +## - mysql_credential_args_arr=(":" "":" ... +## - +## - Example: +## - mysql_credential_args_arr=("5.7:--login-path=local" "5.6:--login-path=local-5.6") +## - +#mysql_credential_args_arr="" mysql_credential_args="--login-path=local" mysql_user=backup mysql_password=backup diff --git a/hosts/scripts/main_part.include b/hosts/scripts/main_part.include index f11c13a..f129d6d 100644 --- a/hosts/scripts/main_part.include +++ b/hosts/scripts/main_part.include @@ -266,9 +266,24 @@ if [ "$found" = "true" -o "$pgsql_backup" = "true" -o "$mysql_backup" = "true" $script_dir/svn_backup.sh fi if $mysql_backup ;then - echolog "\nGoing to backup mysql databases.. ( `$date +%H`:`$date +%M` h )" - export mysql_user mysql_password mysql_credential_args mysql_gzip - $script_dir/mysql_backup.sh + + if [[ ${#mysql_credential_args_arr[@]} -gt 0 ]] ; then + for _val in "${mysql_credential_args_arr[@]}" ; do + + IFS=':' read -a _val_arr <<< "${_val}" + + mysql_version="${_val_arr[0]}" + mysql_credential_args="${_val_arr[1]}" + + echolog "\nGoing to backup mysql databases ${_val_arr[0]} .. ( `$date +%H`:`$date +%M` h )" + export mysql_version mysql_credential_args mysql_gzip + $script_dir/mysql_backup.sh + done + else + echolog "\nGoing to backup mysql databases.. ( `$date +%H`:`$date +%M` h )" + export mysql_user mysql_password mysql_credential_args mysql_gzip + $script_dir/mysql_backup.sh + fi ## - !! if $restart_apache ;then $ssh ${ssh_user}@$srcHost "sudo /etc/init.d/apache2 restart" diff --git a/hosts/scripts/mysql_backup.sh b/hosts/scripts/mysql_backup.sh index 6292805..287f943 100755 --- a/hosts/scripts/mysql_backup.sh +++ b/hosts/scripts/mysql_backup.sh @@ -74,7 +74,7 @@ err_Log=${LOCK_DIR}/mysql.err.log # -------------------- Variable --------------------- # # -_backupDestArchiveDir="${script_backup_dir}/MySQL" +_backupDestArchiveDir="${script_backup_dir}/MySQL-${mysql_version}" if [ $srcHost != "localhost" ] || $_via_ssh_tunnel ;then diff --git a/rcopy.sh b/rcopy.sh index dddbeef..67ee756 100755 --- a/rcopy.sh +++ b/rcopy.sh @@ -198,6 +198,7 @@ fi ## - if $manual ; then host_scripts="${hosts_base_dir}/localhost.sh" + host_scripts="${hosts_base_dir}/devel-php5.wf.netz.sh ${hosts_base_dir}/devel-db.wf.netz.sh" else host_scripts=`$find $hosts_base_dir -maxdepth 1 -type f -perm -700 | $sort` fi