diff options
author | Julius Goryavsky <julius.goryavsky@mariadb.com> | 2021-04-15 13:53:28 +0200 |
---|---|---|
committer | Julius Goryavsky <julius.goryavsky@mariadb.com> | 2021-05-03 18:08:13 +0200 |
commit | e0324bf300a57e84e5fdeca995c91b9efa3dc62c (patch) | |
tree | b9dc6091e71e281e99ee610fab7ace98975bb4c6 | |
parent | 562c88257f574d297ca0d9c284ed80390a3c927b (diff) | |
download | mariadb-git-e0324bf300a57e84e5fdeca995c91b9efa3dc62c.tar.gz |
wsrep sst scripts: removing extra blank lines and spaces
Removed numerous extra blank lines and spaces that interfere with
reading and understanding program code, making it more difficult to
find errors in scripts. I also removed all extra trailing spaces at
the ends of lines, which lead to marking extra lines as changes
(in subsequent changes). The amount of indentation in some parts
of the code has also been normalized.
-rw-r--r-- | scripts/wsrep_sst_common.sh | 10 | ||||
-rw-r--r-- | scripts/wsrep_sst_mariabackup.sh | 248 | ||||
-rw-r--r-- | scripts/wsrep_sst_mysqldump.sh | 32 | ||||
-rw-r--r-- | scripts/wsrep_sst_rsync.sh | 55 | ||||
-rw-r--r-- | scripts/wsrep_sst_xtrabackup-v2.sh | 214 | ||||
-rw-r--r-- | scripts/wsrep_sst_xtrabackup.sh | 147 |
6 files changed, 329 insertions, 377 deletions
diff --git a/scripts/wsrep_sst_common.sh b/scripts/wsrep_sst_common.sh index 443cb26ab64..51f811bda78 100644 --- a/scripts/wsrep_sst_common.sh +++ b/scripts/wsrep_sst_common.sh @@ -194,9 +194,9 @@ case "$1" in shift ;; '--binlog-index') - WSREP_SST_OPT_BINLOG_INDEX="$2" - shift - ;; + WSREP_SST_OPT_BINLOG_INDEX="$2" + shift + ;; '--gtid-domain-id') readonly WSREP_SST_OPT_GTID_DOMAIN_ID="$2" shift @@ -298,11 +298,11 @@ fi wsrep_defaults="$WSREP_SST_OPT_DEFAULT" if [ -n "$wsrep_defaults" ]; then - wsrep_defaults="$wsrep_defaults " + wsrep_defaults="$wsrep_defaults " fi wsrep_defaults="$wsrep_defaults$WSREP_SST_OPT_EXTRA_DEFAULT" if [ -n "$wsrep_defaults" ]; then - wsrep_defaults="$wsrep_defaults " + wsrep_defaults="$wsrep_defaults " fi readonly WSREP_SST_OPT_CONF="$wsrep_defaults$WSREP_SST_OPT_SUFFIX_DEFAULT" readonly MY_PRINT_DEFAULTS="$MY_PRINT_DEFAULTS $WSREP_SST_OPT_CONF" diff --git a/scripts/wsrep_sst_mariabackup.sh b/scripts/wsrep_sst_mariabackup.sh index 29c527d8ff3..c9a990a661d 100644 --- a/scripts/wsrep_sst_mariabackup.sh +++ b/scripts/wsrep_sst_mariabackup.sh @@ -87,8 +87,8 @@ set +e INNOBACKUPEX_BIN=$(which mariabackup) if test -z $INNOBACKUPEX_BIN then - wsrep_log_error 'mariabackup binary not found in $PATH' - exit 42 + wsrep_log_error 'mariabackup binary not found in $PATH' + exit 42 fi set -e XBSTREAM_BIN=mbstream @@ -111,7 +111,7 @@ timeit(){ local cmd="$@" local x1 x2 took extcode - if [[ $ttime -eq 1 ]];then + if [[ $ttime -eq 1 ]];then x1=$(date +%s) wsrep_log_info "Evaluating $cmd" eval "$cmd" @@ -120,7 +120,7 @@ timeit(){ took=$(( x2-x1 )) wsrep_log_info "NOTE: $stage took $took seconds" totime=$(( totime+took )) - else + else wsrep_log_info "Evaluating $cmd" eval "$cmd" extcode=$? @@ -131,11 +131,11 @@ timeit(){ get_keys() { # $encrypt -eq 1 is for internal purposes only - if [[ $encrypt -ge 2 || $encrypt -eq -1 ]];then - return + if [[ $encrypt -ge 2 || $encrypt -eq -1 ]];then + return fi - if [[ $encrypt -eq 0 ]];then + if [[ $encrypt -eq 0 ]];then if $MY_PRINT_DEFAULTS xtrabackup | grep -q encrypt;then wsrep_log_error "Unexpected option combination. SST may fail. Refer to http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html" fi @@ -175,18 +175,18 @@ get_keys() get_transfer() { - if [[ -z $SST_PORT ]];then + if [[ -z $SST_PORT ]];then TSST_PORT=4444 - else + else TSST_PORT=$SST_PORT fi if [[ $tfmt == 'nc' ]];then - wsrep_check_programs nc - + wsrep_check_programs nc wsrep_log_info "Using netcat as streamer" + if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then - if nc -h 2>&1 | grep -q ncat;then + if nc -h 2>&1 | grep -q ncat;then # Ncat tcmd="nc -l ${TSST_PORT}" elif nc -h 2>&1 | grep -qw -- '-d\>';then @@ -215,9 +215,8 @@ get_transfer() tcmd_extra="" if nc -h 2>&1 | grep -qw -- -N; then tcmd_extra+="-N" - wsrep_log_info "Using nc -N" + wsrep_log_info "Using nc -N" fi - # netcat doesn't understand [] around IPv6 address if nc -h 2>&1 | grep -q ncat;then # Ncat @@ -235,7 +234,7 @@ get_transfer() fi else tfmt='socat' - wsrep_check_programs socat + wsrep_check_programs socat wsrep_log_info "Using socat as streamer" if [[ $encrypt -eq 2 || $encrypt -eq 3 ]] && ! socat -V | grep -q "WITH_OPENSSL 1";then @@ -243,9 +242,9 @@ get_transfer() exit 2 fi - if [[ $encrypt -eq 2 ]];then + if [[ $encrypt -eq 2 ]];then wsrep_log_info "Using openssl based encryption with socat: with crt and pem" - if [[ -z $tpem || -z $tcert ]];then + if [[ -z $tpem || -z $tcert ]];then wsrep_log_error "Both PEM and CRT files required" exit 22 fi @@ -281,8 +280,7 @@ get_transfer() tcmd="socat -u stdio openssl-connect:${REMOTEIP}:${TSST_PORT},cert=${tpem},key=${tkey},cafile=${tcert}${sockopt}" fi fi - - else + else if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then tcmd="socat -u TCP-LISTEN:${TSST_PORT},reuseaddr${sockopt} stdio" else @@ -290,7 +288,6 @@ get_transfer() fi fi fi - } parse_cnf() @@ -302,7 +299,7 @@ parse_cnf() # then grep for needed variable # finally get the variable value (if variables has been specified multiple time use the last value only) reval=$($MY_PRINT_DEFAULTS $group | awk -F= '{if ($1 ~ /_/) { gsub(/_/,"-",$1); print $1"="$2 } else { print $0 }}' | grep -- "--$var=" | cut -d= -f2- | tail -1) - if [[ -z $reval ]];then + if [[ -z $reval ]];then [[ -n $3 ]] && reval=$3 fi echo $reval @@ -312,7 +309,7 @@ get_footprint() { pushd $WSREP_SST_OPT_DATA 1>/dev/null payload=$(find . -regex '.*\.ibd$\|.*\.MYI$\|.*\.MYD$\|.*ibdata1$' -type f -print0 | du --files0-from=- --block-size=1 -c | awk 'END { print $1 }') - if $MY_PRINT_DEFAULTS xtrabackup | grep -q -- "--compress";then + if $MY_PRINT_DEFAULTS xtrabackup | grep -q -- "--compress";then # QuickLZ has around 50% compression ratio # When compression/compaction used, the progress is only an approximate. payload=$(( payload*1/2 )) @@ -324,7 +321,6 @@ get_footprint() adjust_progress() { - if ! command -v pv >/dev/null;then wsrep_log_error "pv not found in path: $PATH" wsrep_log_error "Disabling all progress/rate-limiting" @@ -334,16 +330,16 @@ adjust_progress() return fi - if [[ -n $progress && $progress != '1' ]];then - if [[ -e $progress ]];then + if [[ -n $progress && $progress != '1' ]];then + if [[ -e $progress ]];then pcmd+=" 2>>$progress" - else + else pcmd+=" 2>$progress" fi - elif [[ -z $progress && -n $rlimit ]];then + elif [[ -z $progress && -n $rlimit ]];then # When rlimit is non-zero pcmd="pv -q" - fi + fi if [[ -n $rlimit && "$WSREP_SST_OPT_ROLE" == "donor" ]];then wsrep_log_info "Rate-limiting SST to $rlimit" @@ -371,7 +367,7 @@ read_cnf() scomp=$(parse_cnf sst compressor "") sdecomp=$(parse_cnf sst decompressor "") - # Refer to http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html + # Refer to http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html if [[ -z $ealgo ]];then ealgo=$(parse_cnf sst encrypt-algo "") ekey=$(parse_cnf sst encrypt-key "") @@ -391,13 +387,13 @@ read_cnf() sstlogarchive=$(parse_cnf sst sst-log-archive 1) sstlogarchivedir=$(parse_cnf sst sst-log-archive-dir "/tmp/sst_log_archive") - if [[ $speciald -eq 0 ]];then + if [[ $speciald -eq 0 ]];then wsrep_log_error "sst-special-dirs equal to 0 is not supported, falling back to 1" speciald=1 - fi + fi - if [[ $ssyslog -ne -1 ]];then - if $MY_PRINT_DEFAULTS mysqld_safe | tr '_' '-' | grep -q -- "--syslog";then + if [[ $ssyslog -ne -1 ]];then + if $MY_PRINT_DEFAULTS mysqld_safe | tr '_' '-' | grep -q -- "--syslog";then ssyslog=1 fi fi @@ -426,7 +422,6 @@ get_stream() else strmcmd="tar cf - \${INFO_FILE} " fi - fi } @@ -448,33 +443,32 @@ cleanup_joiner() { # Since this is invoked just after exit NNN local estatus=$? - if [[ $estatus -ne 0 ]];then + if [[ $estatus -ne 0 ]];then wsrep_log_error "Cleanup after exit with status:$estatus" elif [ "${WSREP_SST_OPT_ROLE}" = "joiner" ];then wsrep_log_info "Removing the sst_in_progress file" wsrep_cleanup_progress_file fi - if [[ -n $progress && -p $progress ]];then + if [[ -n $progress && -p $progress ]];then wsrep_log_info "Cleaning up fifo file $progress" rm $progress fi - if [[ -n ${STATDIR:-} ]];then + + if [[ -n ${STATDIR:-} ]];then [[ -d $STATDIR ]] && rm -rf $STATDIR fi - # Final cleanup + # Final cleanup pgid=$(ps -o pgid= $$ | grep -o '[0-9]*') # This means no setsid done in mysqld. # We don't want to kill mysqld here otherwise. if [[ $$ -eq $pgid ]];then - # This means a signal was delivered to the process. - # So, more cleanup. - if [[ $estatus -ge 128 ]];then + # So, more cleanup. + if [[ $estatus -ge 128 ]];then kill -KILL -$$ || true fi - fi exit $estatus @@ -490,52 +484,49 @@ cleanup_donor() { # Since this is invoked just after exit NNN local estatus=$? - if [[ $estatus -ne 0 ]];then + if [[ $estatus -ne 0 ]];then wsrep_log_error "Cleanup after exit with status:$estatus" fi - if [[ -n ${XTRABACKUP_PID:-} ]];then + if [[ -n ${XTRABACKUP_PID:-} ]];then if check_pid $XTRABACKUP_PID then wsrep_log_error "xtrabackup process is still running. Killing..." kill_xtrabackup fi - fi + rm -f ${DATA}/${IST_FILE} || true - if [[ -n $progress && -p $progress ]];then + if [[ -n $progress && -p $progress ]];then wsrep_log_info "Cleaning up fifo file $progress" rm -f $progress || true fi wsrep_log_info "Cleaning up temporary directories" - if [[ -n $xtmpdir ]];then + if [[ -n $xtmpdir ]];then [[ -d $xtmpdir ]] && rm -rf $xtmpdir || true fi - if [[ -n $itmpdir ]];then + if [[ -n $itmpdir ]];then [[ -d $itmpdir ]] && rm -rf $itmpdir || true fi - # Final cleanup + # Final cleanup pgid=$(ps -o pgid= $$ | grep -o '[0-9]*') # This means no setsid done in mysqld. # We don't want to kill mysqld here otherwise. if [[ $$ -eq $pgid ]];then - # This means a signal was delivered to the process. - # So, more cleanup. - if [[ $estatus -ge 128 ]];then + # So, more cleanup. + if [[ $estatus -ge 128 ]];then kill -KILL -$$ || true fi - fi exit $estatus - } kill_xtrabackup() @@ -565,7 +556,7 @@ wait_for_listen() local MODULE=$3 for i in {1..50} do - if [ "$OS" = "FreeBSD" ];then + if [ "$OS" = "FreeBSD" ];then sockstat -46lp $PORT | grep -qE "^[^ ]* *(socat|nc) *[^ ]* *[^ ]* *[^ ]* *[^ ]*:$PORT" && break else ss -p state listening "( sport = :$PORT )" | grep -qE 'socat|nc' && break @@ -578,20 +569,20 @@ wait_for_listen() check_extra() { local use_socket=1 - if [[ $uextra -eq 1 ]];then - if $MY_PRINT_DEFAULTS --mysqld | tr '_' '-' | grep -- "--thread-handling=" | grep -q 'pool-of-threads';then + if [[ $uextra -eq 1 ]];then + if $MY_PRINT_DEFAULTS --mysqld | tr '_' '-' | grep -- "--thread-handling=" | grep -q 'pool-of-threads';then local eport=$($MY_PRINT_DEFAULTS --mysqld | tr '_' '-' | grep -- "--extra-port=" | cut -d= -f2) - if [[ -n $eport ]];then + if [[ -n $eport ]];then # Xtrabackup works only locally. - # Hence, setting host to 127.0.0.1 unconditionally. + # Hence, setting host to 127.0.0.1 unconditionally. wsrep_log_info "SST through extra_port $eport" INNOEXTRA+=" --host=127.0.0.1 --port=$eport" use_socket=0 - else + else wsrep_log_error "Extra port $eport null, failing" exit 1 fi - else + else wsrep_log_info "Thread pool not set, ignore the option use_extra" fi fi @@ -603,7 +594,7 @@ check_extra() recv_joiner() { local dir=$1 - local msg=$2 + local msg=$2 local tmt=$3 local checkf=$4 local ltcmd @@ -617,27 +608,27 @@ recv_joiner() set +e if [[ $tmt -gt 0 ]] && command -v timeout >/dev/null;then - if timeout --help | grep -q -- '-k';then + if timeout --help | grep -q -- '-k';then ltcmd="timeout -k $(( tmt+10 )) $tmt $tcmd" - else + else ltcmd="timeout -s9 $tmt $tcmd" fi timeit "$msg" "$ltcmd | $strmcmd; RC=( "\${PIPESTATUS[@]}" )" - else + else timeit "$msg" "$tcmd | $strmcmd; RC=( "\${PIPESTATUS[@]}" )" fi set -e - popd 1>/dev/null + popd 1>/dev/null - if [[ ${RC[0]} -eq 124 ]];then + if [[ ${RC[0]} -eq 124 ]];then wsrep_log_error "Possible timeout in receiving first data from " - "donor in gtid stage: exit codes: ${RC[@]}" + "donor in gtid stage: exit codes: ${RC[@]}" exit 32 fi - for ecode in "${RC[@]}";do - if [[ $ecode -ne 0 ]];then + for ecode in "${RC[@]}";do + if [[ $ecode -ne 0 ]];then wsrep_log_error "Error while getting data from donor node: " \ "exit codes: ${RC[@]}" exit 32 @@ -647,33 +638,30 @@ recv_joiner() if [[ $checkf -eq 1 && ! -r "${MAGIC_FILE}" ]];then # this message should cause joiner to abort wsrep_log_error "xtrabackup process ended without creating '${MAGIC_FILE}'" - wsrep_log_info "Contents of datadir" + wsrep_log_info "Contents of datadir" wsrep_log_info "$(ls -l ${dir}/*)" exit 32 fi } - send_donor() { local dir=$1 - local msg=$2 + local msg=$2 pushd ${dir} 1>/dev/null set +e timeit "$msg" "$strmcmd | $tcmd; RC=( "\${PIPESTATUS[@]}" )" set -e - popd 1>/dev/null - + popd 1>/dev/null - for ecode in "${RC[@]}";do - if [[ $ecode -ne 0 ]];then + for ecode in "${RC[@]}";do + if [[ $ecode -ne 0 ]];then wsrep_log_error "Error while getting data from donor node: " \ "exit codes: ${RC[@]}" exit 32 fi done - } monitor_process() @@ -681,18 +669,14 @@ monitor_process() local sst_stream_pid=$1 while true ; do - if ! ps -p "${WSREP_SST_OPT_PARENT}" &>/dev/null; then - wsrep_log_error "Parent mysqld process (PID:${WSREP_SST_OPT_PARENT}) terminated unexpectedly." + wsrep_log_error "Parent mysqld process (PID:${WSREP_SST_OPT_PARENT}) terminated unexpectedly." exit 32 fi - if ! ps -p "${sst_stream_pid}" &>/dev/null; then break fi - sleep 0.1 - done } @@ -700,7 +684,7 @@ wsrep_check_programs "$INNOBACKUPEX_BIN" rm -f "${MAGIC_FILE}" -if [[ ! ${WSREP_SST_OPT_ROLE} == 'joiner' && ! ${WSREP_SST_OPT_ROLE} == 'donor' ]];then +if [[ ! ${WSREP_SST_OPT_ROLE} == 'joiner' && ! ${WSREP_SST_OPT_ROLE} == 'donor' ]];then wsrep_log_error "Invalid role ${WSREP_SST_OPT_ROLE}" exit 22 fi @@ -708,13 +692,13 @@ fi read_cnf setup_ports -if ${INNOBACKUPEX_BIN} /tmp --help 2>/dev/null | grep -q -- '--version-check'; then +if ${INNOBACKUPEX_BIN} /tmp --help 2>/dev/null | grep -q -- '--version-check'; then disver="--no-version-check" fi iopts+=" --databases-exclude=\"lost+found\"" -if [[ ${FORCE_FTWRL:-0} -eq 1 ]];then +if [[ ${FORCE_FTWRL:-0} -eq 1 ]];then wsrep_log_info "Forcing FTWRL due to environment variable FORCE_FTWRL equal to $FORCE_FTWRL" iopts+=" --no-backup-locks" fi @@ -746,24 +730,23 @@ else INNODB_DATA_HOME_DIR=$(cd $DATA; pwd -P) fi -if [[ $ssyslog -eq 1 ]];then +if [[ $ssyslog -eq 1 ]];then if ! command -v logger >/dev/null;then wsrep_log_error "logger not in path: $PATH. Ignoring" else - wsrep_log_info "Logging all stderr of SST/Innobackupex to syslog" exec 2> >(logger -p daemon.err -t ${ssystag}wsrep-sst-$WSREP_SST_OPT_ROLE) wsrep_log_error() { - logger -p daemon.err -t ${ssystag}wsrep-sst-$WSREP_SST_OPT_ROLE "$@" + logger -p daemon.err -t ${ssystag}wsrep-sst-$WSREP_SST_OPT_ROLE "$@" } wsrep_log_info() { - logger -p daemon.info -t ${ssystag}wsrep-sst-$WSREP_SST_OPT_ROLE "$@" + logger -p daemon.info -t ${ssystag}wsrep-sst-$WSREP_SST_OPT_ROLE "$@" } INNOAPPLY="${INNOBACKUPEX_BIN} --prepare $disver $iapts \$INNOEXTRA $rebuildcmd --target-dir=\${DATA} 2>&1 | logger -p daemon.err -t ${ssystag}innobackupex-apply" @@ -794,7 +777,6 @@ then else newfile=${INNOAPPLYLOG}.${ARCHIVETIMESTAMP} fi - wsrep_log_info "Moving ${INNOAPPLYLOG} to ${newfile}" mv "${INNOAPPLYLOG}" "${newfile}" gzip "${newfile}" @@ -827,12 +809,12 @@ then mv "${INNOBACKUPLOG}" "${newfile}" gzip "${newfile}" fi - fi - + INNOAPPLY="${INNOBACKUPEX_BIN} --prepare $disver $iapts \$INNOEXTRA $rebuildcmd --target-dir=\${DATA} &> ${INNOAPPLYLOG}" INNOMOVE="${INNOBACKUPEX_BIN} ${WSREP_SST_OPT_CONF} --move-back $disver $impts --force-non-empty-directories --target-dir=\${DATA} &> ${INNOMOVELOG}" INNOBACKUP="${INNOBACKUPEX_BIN} ${WSREP_SST_OPT_CONF} --backup $disver $iopts \$tmpopts \$INNOEXTRA --galera-info --stream=\$sfmt --target-dir=\$itmpdir 2> ${INNOBACKUPLOG}" + fi get_stream @@ -845,7 +827,7 @@ then if [ $WSREP_SST_OPT_BYPASS -eq 0 ] then usrst=0 - if [[ -z $sst_ver ]];then + if [[ -z $sst_ver ]];then wsrep_log_error "Upgrade joiner to 5.6.21 or higher for backup locks support" wsrep_log_error "The joiner is not supported for this version of donor" exit 93 @@ -878,7 +860,7 @@ then if [[ $encrypt -eq 1 ]];then if [[ -n $ekey ]];then INNOEXTRA+=" --encrypt=$ealgo --encrypt-key=$ekey" - else + else INNOEXTRA+=" --encrypt=$ealgo --encrypt-key-file=$ekeyfile" fi fi @@ -894,22 +876,22 @@ then ttcmd="$tcmd" if [[ $encrypt -eq 1 ]];then - if [[ -n $scomp ]];then + if [[ -n $scomp ]];then tcmd=" $ecmd | $scomp | $tcmd " - else + else tcmd=" $ecmd | $tcmd " fi - elif [[ -n $scomp ]];then + elif [[ -n $scomp ]];then tcmd=" $scomp | $tcmd " fi send_donor $DATA "${stagemsg}-gtid" tcmd="$ttcmd" - if [[ -n $progress ]];then + if [[ -n $progress ]];then get_footprint tcmd="$pcmd | $tcmd" - elif [[ -n $rlimit ]];then + elif [[ -n $rlimit ]];then adjust_progress tcmd="$pcmd | $tcmd" fi @@ -919,7 +901,7 @@ then wsrep_log_info "Streaming the backup to joiner at ${REMOTEIP} ${SST_PORT:-4444}" - if [[ -n $scomp ]];then + if [[ -n $scomp ]];then tcmd="$scomp | $tcmd" fi @@ -931,7 +913,7 @@ then wsrep_log_error "${INNOBACKUPEX_BIN} finished with error: ${RC[0]}. " \ "Check syslog or ${INNOBACKUPLOG} for details" exit 22 - elif [[ ${RC[$(( ${#RC[@]}-1 ))]} -eq 1 ]];then + elif [[ ${RC[$(( ${#RC[@]}-1 ))]} -eq 1 ]];then wsrep_log_error "$tcmd finished with error: ${RC[1]}" exit 22 fi @@ -939,7 +921,6 @@ then # innobackupex implicitly writes PID to fixed location in $xtmpdir XTRABACKUP_PID="$xtmpdir/xtrabackup_pid" - else # BYPASS FOR IST wsrep_log_info "Bypassing the SST for IST" @@ -951,12 +932,12 @@ then echo "1" > "${DATA}/${IST_FILE}" get_keys if [[ $encrypt -eq 1 ]];then - if [[ -n $scomp ]];then + if [[ -n $scomp ]];then tcmd=" $ecmd | $scomp | $tcmd " else tcmd=" $ecmd | $tcmd " fi - elif [[ -n $scomp ]];then + elif [[ -n $scomp ]];then tcmd=" $scomp | $tcmd " fi strmcmd+=" \${IST_FILE}" @@ -1003,7 +984,6 @@ then stagemsg="Joiner-Recv" - sencrypted=1 nthreads=1 @@ -1030,30 +1010,29 @@ then trap sig_joiner_cleanup HUP PIPE INT TERM trap cleanup_joiner EXIT - if [[ -n $progress ]];then + if [[ -n $progress ]];then adjust_progress tcmd+=" | $pcmd" fi get_keys if [[ $encrypt -eq 1 && $sencrypted -eq 1 ]];then - if [[ -n $sdecomp ]];then + if [[ -n $sdecomp ]];then strmcmd=" $sdecomp | $ecmd | $strmcmd" - else + else strmcmd=" $ecmd | $strmcmd" fi - elif [[ -n $sdecomp ]];then + elif [[ -n $sdecomp ]];then strmcmd=" $sdecomp | $strmcmd" fi STATDIR=$(mktemp -d) MAGIC_FILE="${STATDIR}/${INFO_FILE}" - recv_joiner $STATDIR "${stagemsg}-gtid" $stimeout 1 - + recv_joiner $STATDIR "${stagemsg}-gtid" $stimeout 1 if ! ps -p ${WSREP_SST_OPT_PARENT} &>/dev/null then - wsrep_log_error "Parent mysqld process (PID:${WSREP_SST_OPT_PARENT}) terminated unexpectedly." + wsrep_log_error "Parent mysqld process (PID:${WSREP_SST_OPT_PARENT}) terminated unexpectedly." exit 32 fi @@ -1070,11 +1049,11 @@ then wsrep_log_info "Proceeding with SST" wsrep_log_info "Cleaning the existing datadir and innodb-data/log directories" - if [ "${OS}" = "FreeBSD" ]; then + if [ "${OS}" = "FreeBSD" ]; then find -E $ib_home_dir $ib_log_dir $ib_undo_dir $DATA -mindepth 1 -prune -regex $cpat -o -exec rm -rfv {} 1>&2 \+ else find $ib_home_dir $ib_log_dir $ib_undo_dir $DATA -mindepth 1 -prune -regex $cpat -o -exec rm -rfv {} 1>&2 \+ - fi + fi tempdir=$LOG_BIN_ARG if [ -z "$tempdir" ]; then @@ -1094,30 +1073,27 @@ then fi fi - - TDATA=${DATA} DATA="${DATA}/.sst" - MAGIC_FILE="${DATA}/${INFO_FILE}" wsrep_log_info "Waiting for SST streaming to complete!" monitor_process $jpid get_proc - if [[ ! -s ${DATA}/xtrabackup_checkpoints ]];then + if [[ ! -s ${DATA}/xtrabackup_checkpoints ]];then wsrep_log_error "xtrabackup_checkpoints missing, failed innobackupex/SST on donor" exit 2 fi # Rebuild indexes for compact backups - if grep -q 'compact = 1' ${DATA}/xtrabackup_checkpoints;then + if grep -q 'compact = 1' ${DATA}/xtrabackup_checkpoints;then wsrep_log_info "Index compaction detected" rebuild=1 fi - if [[ $rebuild -eq 1 ]];then + if [[ $rebuild -eq 1 ]];then nthreads=$(parse_cnf xtrabackup rebuild-threads $nproc) wsrep_log_info "Rebuilding during prepare with $nthreads threads" rebuildcmd="--rebuild-indexes --rebuild-threads=$nthreads" @@ -1127,7 +1103,7 @@ then wsrep_log_info "Compressed qpress files found" - if ! command -v qpress >/dev/null;then + if ! command -v qpress >/dev/null;then wsrep_log_error "qpress not found in path: $PATH" exit 22 fi @@ -1135,28 +1111,27 @@ then if [[ -n $progress ]] && pv --help | grep -q 'line-mode';then count=$(find ${DATA} -type f -name '*.qp' | wc -l) count=$(( count*2 )) - if pv --help | grep -q FORMAT;then + if pv --help | grep -q FORMAT;then pvopts="-f -s $count -l -N Decompression -F '%N => Rate:%r Elapsed:%t %e Progress: [%b/$count]'" - else + else pvopts="-f -s $count -l -N Decompression" fi pcmd="pv $pvopts" adjust_progress dcmd="$pcmd | xargs -n 2 qpress -T${nproc}d" - else + else dcmd="xargs -n 2 qpress -T${nproc}d" fi - - # Decompress the qpress files + # Decompress the qpress files wsrep_log_info "Decompression with $nproc threads" timeit "Joiner-Decompression" "find ${DATA} -type f -name '*.qp' -printf '%p\n%h\n' | $dcmd" extcode=$? if [[ $extcode -eq 0 ]];then wsrep_log_info "Removing qpress files after decompression" - find ${DATA} -type f -name '*.qp' -delete - if [[ $? -ne 0 ]];then + find ${DATA} -type f -name '*.qp' -delete + if [[ $? -ne 0 ]];then wsrep_log_error "Something went wrong with deletion of qpress files. Investigate" fi else @@ -1165,13 +1140,12 @@ then fi fi - if [[ ! -z $WSREP_SST_OPT_BINLOG ]];then BINLOG_DIRNAME=$(dirname $WSREP_SST_OPT_BINLOG) BINLOG_FILENAME=$(basename $WSREP_SST_OPT_BINLOG) - # To avoid comparing data directory and BINLOG_DIRNAME + # To avoid comparing data directory and BINLOG_DIRNAME mv $DATA/${BINLOG_FILENAME}.* $BINLOG_DIRNAME/ 2>/dev/null || true pushd $BINLOG_DIRNAME &>/dev/null @@ -1187,7 +1161,7 @@ then if [ $? -ne 0 ]; then - wsrep_log_error "${INNOBACKUPEX_BIN} apply finished with errors. Check syslog or ${INNOAPPLYLOG} for details" + wsrep_log_error "${INNOBACKUPEX_BIN} apply finished with errors. Check syslog or ${INNOAPPLYLOG} for details" exit 22 fi @@ -1196,27 +1170,29 @@ then set -e wsrep_log_info "Moving the backup to ${TDATA}" timeit "Xtrabackup move stage" "$INNOMOVE" - if [[ $? -eq 0 ]];then + if [[ $? -eq 0 ]];then wsrep_log_info "Move successful, removing ${DATA}" rm -rf $DATA DATA=${TDATA} - else + else wsrep_log_error "Move failed, keeping ${DATA} for further diagnosis" wsrep_log_error "Check syslog or ${INNOMOVELOG} for details" exit 22 fi + else - else wsrep_log_info "${IST_FILE} received from donor: Running IST" + fi - if [[ ! -r ${MAGIC_FILE} ]];then + if [[ ! -r ${MAGIC_FILE} ]];then wsrep_log_error "SST magic file ${MAGIC_FILE} not found/readable" exit 2 fi wsrep_log_info "Galera co-ords from recovery: $(cat ${MAGIC_FILE})" cat "${MAGIC_FILE}" # Output : UUID:seqno wsrep_gtid_domain_id + wsrep_log_info "Total time on joiner: $totime seconds" fi diff --git a/scripts/wsrep_sst_mysqldump.sh b/scripts/wsrep_sst_mysqldump.sh index 664fd2c04f9..19fca2df024 100644 --- a/scripts/wsrep_sst_mysqldump.sh +++ b/scripts/wsrep_sst_mysqldump.sh @@ -100,12 +100,12 @@ SET_START_POSITION="SET GLOBAL wsrep_start_position='$WSREP_SST_OPT_GTID';" SET_WSREP_GTID_DOMAIN_ID="" if [ -n $WSREP_SST_OPT_GTID_DOMAIN_ID ] then - SET_WSREP_GTID_DOMAIN_ID=" - SET @val = (SELECT GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME = 'WSREP_GTID_STRICT_MODE' AND GLOBAL_VALUE > 0); - SET @stmt = IF (@val IS NOT NULL, 'SET GLOBAL WSREP_GTID_DOMAIN_ID=$WSREP_SST_OPT_GTID_DOMAIN_ID', 'SET @dummy = 0'); - PREPARE stmt FROM @stmt; - EXECUTE stmt; - DROP PREPARE stmt;" + SET_WSREP_GTID_DOMAIN_ID=" + SET @val = (SELECT GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME = 'WSREP_GTID_STRICT_MODE' AND GLOBAL_VALUE > 0); + SET @stmt = IF (@val IS NOT NULL, 'SET GLOBAL WSREP_GTID_DOMAIN_ID=$WSREP_SST_OPT_GTID_DOMAIN_ID', 'SET @dummy = 0'); + PREPARE stmt FROM @stmt; + EXECUTE stmt; + DROP PREPARE stmt;" fi MYSQL="$MYSQL_CLIENT $WSREP_SST_OPT_CONF "\ @@ -132,16 +132,16 @@ SQL_LOG_BIN_OFF="" # Safety check if [ "${SERVER_VERSION%%.*}" != '5' ] then - # If binary logging is enabled on the joiner node, we need to copy donor's - # gtid_binlog_state to joiner. In order to do that, a RESET MASTER must be - # executed to erase binary logs (if any). Binary logging should also be - # turned off for the session so that gtid state does not get altered while - # the dump gets replayed on joiner. - if [[ "$LOG_BIN" == 'ON' ]]; then - RESET_MASTER="RESET MASTER;" - SET_GTID_BINLOG_STATE="SET @@global.gtid_binlog_state='$GTID_BINLOG_STATE';" - SQL_LOG_BIN_OFF="SET @@session.sql_log_bin=OFF;" - fi + # If binary logging is enabled on the joiner node, we need to copy donor's + # gtid_binlog_state to joiner. In order to do that, a RESET MASTER must be + # executed to erase binary logs (if any). Binary logging should also be + # turned off for the session so that gtid state does not get altered while + # the dump gets replayed on joiner. + if [[ "$LOG_BIN" == 'ON' ]]; then + RESET_MASTER="RESET MASTER;" + SET_GTID_BINLOG_STATE="SET @@global.gtid_binlog_state='$GTID_BINLOG_STATE';" + SQL_LOG_BIN_OFF="SET @@session.sql_log_bin=OFF;" + fi fi # NOTE: we don't use --routines here because we're dumping mysql.proc table diff --git a/scripts/wsrep_sst_rsync.sh b/scripts/wsrep_sst_rsync.sh index 7e3f7b73301..ec64a6b5d8f 100644 --- a/scripts/wsrep_sst_rsync.sh +++ b/scripts/wsrep_sst_rsync.sh @@ -74,8 +74,8 @@ check_pid_and_port() ;; *) if ! which lsof > /dev/null; then - wsrep_log_error "lsof tool not found in PATH! Make sure you have it installed." - exit 2 # ENOENT + wsrep_log_error "lsof tool not found in PATH! Make sure you have it installed." + exit 2 # ENOENT fi local port_info="$(lsof -i :$rsync_port -Pn 2>/dev/null | \ @@ -107,15 +107,15 @@ is_local_ip() local get_addr_bin=`which ifconfig` if [ -z "$get_addr_bin" ] then - get_addr_bin=`which ip` - get_addr_bin="$get_addr_bin address show" - # Add an slash at the end, so we don't get false positive : 172.18.0.4 matches 172.18.0.41 - # ip output format is "X.X.X.X/mask" - address="${address}/" + get_addr_bin=`which ip` + get_addr_bin="$get_addr_bin address show" + # Add an slash at the end, so we don't get false positive : 172.18.0.4 matches 172.18.0.41 + # ip output format is "X.X.X.X/mask" + address="${address}/" else - # Add an space at the end, so we don't get false positive : 172.18.0.4 matches 172.18.0.41 - # ifconfig output format is "X.X.X.X " - address="$address " + # Add an space at the end, so we don't get false positive : 172.18.0.4 matches 172.18.0.41 + # ifconfig output format is "X.X.X.X " + address="$address " fi $get_addr_bin | grep -F "$address" > /dev/null @@ -373,11 +373,13 @@ EOF fi else # BYPASS + wsrep_log_info "Bypassing state dump." # Store donor's wsrep GTID (state ID) and wsrep_gtid_domain_id # (separated by a space). STATE="$WSREP_SST_OPT_GTID $WSREP_SST_OPT_GTID_DOMAIN_ID" + fi echo "continue" # now server can resume updating data @@ -461,22 +463,22 @@ EOF # If the IP is local listen only in it if is_local_ip "$RSYNC_ADDR" then - RSYNC_EXTRA_ARGS="--address $RSYNC_ADDR" - STUNNEL_ACCEPT="$RSYNC_ADDR:$RSYNC_PORT" + RSYNC_EXTRA_ARGS="--address $RSYNC_ADDR" + STUNNEL_ACCEPT="$RSYNC_ADDR:$RSYNC_PORT" else - # Not local, possibly a NAT, listen on all interfaces - RSYNC_EXTRA_ARGS="" - STUNNEL_ACCEPT="$RSYNC_PORT" - # Overwrite address with all - RSYNC_ADDR="*" + # Not local, possibly a NAT, listen on all interfaces + RSYNC_EXTRA_ARGS="" + STUNNEL_ACCEPT="$RSYNC_PORT" + # Overwrite address with all + RSYNC_ADDR="*" fi if [ -z "$STUNNEL" ] then - rsync --daemon --no-detach --port "$RSYNC_PORT" --config "$RSYNC_CONF" ${RSYNC_EXTRA_ARGS} & - RSYNC_REAL_PID=$! + rsync --daemon --no-detach --port "$RSYNC_PORT" --config "$RSYNC_CONF" ${RSYNC_EXTRA_ARGS} & + RSYNC_REAL_PID=$! else - cat << EOF > "$STUNNEL_CONF" + cat << EOF > "$STUNNEL_CONF" key = $SSTKEY cert = $SSTCERT foreground = yes @@ -488,9 +490,9 @@ accept = $STUNNEL_ACCEPT exec = $(which rsync) execargs = rsync --server --daemon --config=$RSYNC_CONF . EOF - stunnel "$STUNNEL_CONF" & - RSYNC_REAL_PID=$! - RSYNC_PID=$STUNNEL_PID + stunnel "$STUNNEL_CONF" & + RSYNC_REAL_PID=$! + RSYNC_PID=$STUNNEL_PID fi until check_pid_and_port "$RSYNC_PID" "$RSYNC_REAL_PID" "$RSYNC_ADDR" "$RSYNC_PORT" @@ -518,7 +520,6 @@ EOF if ! [ -z $WSREP_SST_OPT_BINLOG ] then - OLD_PWD="$(pwd)" cd $BINLOG_DIRNAME @@ -532,14 +533,15 @@ EOF do if ! [ -z $WSREP_SST_OPT_BINLOG_INDEX ] echo ${BINLOG_DIRNAME}/${ii} >> ${BINLOG_FILENAME}.index - then + then echo ${BINLOG_DIRNAME}/${ii} >> ${BINLOG_INDEX_DIRNAME}/${BINLOG_INDEX_FILENAME}.index fi done fi - cd "$OLD_PWD" + cd "$OLD_PWD" fi + if [ -r "$MAGIC_FILE" ] then # UUID:seqno & wsrep_gtid_domain_id is received here. @@ -548,6 +550,7 @@ EOF # this message should cause joiner to abort echo "rsync process ended without creating '$MAGIC_FILE'" fi + wsrep_cleanup_progress_file # cleanup_joiner else diff --git a/scripts/wsrep_sst_xtrabackup-v2.sh b/scripts/wsrep_sst_xtrabackup-v2.sh index 8c8af9a0219..7c3859237e0 100644 --- a/scripts/wsrep_sst_xtrabackup-v2.sh +++ b/scripts/wsrep_sst_xtrabackup-v2.sh @@ -15,12 +15,9 @@ # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston # MA 02110-1335 USA. -# Documentation: http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html +# Documentation: http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html # Make sure to read that before proceeding! - - - . $(dirname $0)/wsrep_sst_common ealgo="" @@ -73,7 +70,7 @@ ssl_cert="" ssl_ca="" ssl_key="" -if which pv &>/dev/null && pv --help | grep -q FORMAT;then +if which pv &>/dev/null && pv --help | grep -q FORMAT;then pvopts+=$pvformat fi pcmd="pv $pvopts" @@ -101,7 +98,7 @@ timeit(){ local cmd="$@" local x1 x2 took extcode - if [[ $ttime -eq 1 ]];then + if [[ $ttime -eq 1 ]];then x1=$(date +%s) wsrep_log_info "Evaluating $cmd" eval "$cmd" @@ -110,7 +107,7 @@ timeit(){ took=$(( x2-x1 )) wsrep_log_info "NOTE: $stage took $took seconds" totime=$(( totime+took )) - else + else wsrep_log_info "Evaluating $cmd" eval "$cmd" extcode=$? @@ -121,11 +118,11 @@ timeit(){ get_keys() { # $encrypt -eq 1 is for internal purposes only - if [[ $encrypt -ge 2 || $encrypt -eq -1 ]];then - return + if [[ $encrypt -ge 2 || $encrypt -eq -1 ]];then + return fi - if [[ $encrypt -eq 0 ]];then + if [[ $encrypt -eq 0 ]];then if $MY_PRINT_DEFAULTS xtrabackup | grep -q encrypt;then wsrep_log_error "Unexpected option combination. SST may fail. Refer to http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html " fi @@ -252,7 +249,7 @@ get_transfer() TSST_PORT=${WSREP_SST_OPT_PORT:-4444} if [[ $tfmt == 'nc' ]];then - if [[ ! -x `which nc` ]];then + if [[ ! -x `which nc` ]];then wsrep_log_error "nc(netcat) not found in path: $PATH" exit 2 fi @@ -292,7 +289,7 @@ get_transfer() else tfmt='socat' wsrep_log_info "Using socat as streamer" - if [[ ! -x `which socat` ]];then + if [[ ! -x `which socat` ]];then wsrep_log_error "socat not found in path: $PATH" exit 2 fi @@ -389,7 +386,6 @@ get_transfer() wsrep_log_info "Encrypting with CERT: $ssl_cert, KEY: $ssl_key, CA: $ssl_ca" tcmd="socat -u stdio openssl-connect:${WSREP_SST_OPT_HOST}:${TSST_PORT},cert=${ssl_cert},key=${ssl_key},cafile=${ssl_ca},verify=1${donor_extra}${sockopt}" fi - else if [[ $encrypt -eq 1 ]]; then wsrep_log_warning "**** WARNING **** encrypt=1 is deprecated and will be removed in a future release" @@ -408,7 +404,7 @@ get_footprint() { pushd $WSREP_SST_OPT_DATA 1>/dev/null payload=$(find . -regex '.*\.ibd$\|.*\.MYI$\|.*\.MYD$\|.*ibdata1$' -type f -print0 | du --files0-from=- --block-size=1 -c -s | awk 'END { print $1 }') - if $MY_PRINT_DEFAULTS xtrabackup | grep -q -- "--compress";then + if $MY_PRINT_DEFAULTS xtrabackup | grep -q -- "--compress";then # QuickLZ has around 50% compression ratio # When compression/compaction used, the progress is only an approximate. payload=$(( payload*1/2 )) @@ -420,8 +416,7 @@ get_footprint() adjust_progress() { - - if [[ ! -x `which pv` ]];then + if [[ ! -x `which pv` ]];then wsrep_log_error "pv not found in path: $PATH" wsrep_log_error "Disabling all progress/rate-limiting" pcmd="" @@ -430,16 +425,16 @@ adjust_progress() return fi - if [[ -n $progress && $progress != '1' ]];then - if [[ -e $progress ]];then + if [[ -n $progress && $progress != '1' ]];then + if [[ -e $progress ]];then pcmd+=" 2>>$progress" - else + else pcmd+=" 2>$progress" fi - elif [[ -z $progress && -n $rlimit ]];then + elif [[ -z $progress && -n $rlimit ]];then # When rlimit is non-zero pcmd="pv -q" - fi + fi if [[ -n $rlimit && "$WSREP_SST_OPT_ROLE" == "donor" ]];then wsrep_log_info "Rate-limiting SST to $rlimit" @@ -470,8 +465,7 @@ read_cnf() scomp=$(parse_cnf sst compressor "") sdecomp=$(parse_cnf sst decompressor "") - - # Refer to http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html + # Refer to http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html if [[ -z $ealgo ]];then ealgo=$(parse_cnf sst encrypt-algo "") ekey=$(parse_cnf sst encrypt-key "") @@ -502,7 +496,7 @@ read_cnf() ssystag=$(parse_cnf mysqld_safe syslog-tag "${SST_SYSLOG_TAG:-}") ssystag+="-" - if [[ $ssyslog -ne -1 ]];then + if [[ $ssyslog -ne -1 ]];then if $MY_PRINT_DEFAULTS mysqld_safe | grep -q -- "--syslog";then ssyslog=1 fi @@ -511,7 +505,7 @@ read_cnf() get_stream() { - if [[ $sfmt == 'xbstream' ]];then + if [[ $sfmt == 'xbstream' ]];then wsrep_log_info "Streaming with xbstream" if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then strmcmd="xbstream -x" @@ -526,7 +520,6 @@ get_stream() else strmcmd="tar cf - \${INFO_FILE} " fi - fi } @@ -548,33 +541,32 @@ cleanup_joiner() { # Since this is invoked just after exit NNN local estatus=$? - if [[ $estatus -ne 0 ]];then + if [[ $estatus -ne 0 ]];then wsrep_log_error "Cleanup after exit with status:$estatus" elif [ "${WSREP_SST_OPT_ROLE}" = "joiner" ];then wsrep_log_info "Removing the sst_in_progress file" wsrep_cleanup_progress_file fi - if [[ -n $progress && -p $progress ]];then + if [[ -n $progress && -p $progress ]];then wsrep_log_info "Cleaning up fifo file $progress" rm $progress fi - if [[ -n ${STATDIR:-} ]];then + + if [[ -n ${STATDIR:-} ]];then [[ -d $STATDIR ]] && rm -rf $STATDIR fi - # Final cleanup + # Final cleanup pgid=$(ps -o pgid= $$ | grep -o '[0-9]*') # This means no setsid done in mysqld. # We don't want to kill mysqld here otherwise. if [[ $$ -eq $pgid ]];then - # This means a signal was delivered to the process. - # So, more cleanup. - if [[ $estatus -ge 128 ]];then + # So, more cleanup. + if [[ $estatus -ge 128 ]];then kill -KILL -$$ || true fi - fi exit $estatus @@ -590,11 +582,11 @@ cleanup_donor() { # Since this is invoked just after exit NNN local estatus=$? - if [[ $estatus -ne 0 ]];then + if [[ $estatus -ne 0 ]];then wsrep_log_error "Cleanup after exit with status:$estatus" fi - if [[ -n ${XTRABACKUP_PID:-} ]];then + if [[ -n ${XTRABACKUP_PID:-} ]];then if check_pid $XTRABACKUP_PID then wsrep_log_error "xtrabackup process is still running. Killing... " @@ -602,24 +594,25 @@ cleanup_donor() fi fi + rm -f ${DATA}/${IST_FILE} || true - if [[ -n $progress && -p $progress ]];then + if [[ -n $progress && -p $progress ]];then wsrep_log_info "Cleaning up fifo file $progress" rm -f $progress || true fi wsrep_log_info "Cleaning up temporary directories" - if [[ -n $xtmpdir ]];then + if [[ -n $xtmpdir ]];then [[ -d $xtmpdir ]] && rm -rf $xtmpdir || true fi - if [[ -n $itmpdir ]];then + if [[ -n $itmpdir ]];then [[ -d $itmpdir ]] && rm -rf $itmpdir || true fi - # Final cleanup + # Final cleanup pgid=$(ps -o pgid= $$ | grep -o '[0-9]*') # This means no setsid done in mysqld. @@ -627,15 +620,14 @@ cleanup_donor() if [[ $$ -eq $pgid ]];then # This means a signal was delivered to the process. - # So, more cleanup. - if [[ $estatus -ge 128 ]];then + # So, more cleanup. + if [[ $estatus -ge 128 ]];then kill -KILL -$$ || true fi fi exit $estatus - } kill_xtrabackup() @@ -668,20 +660,20 @@ wait_for_listen() check_extra() { local use_socket=1 - if [[ $uextra -eq 1 ]];then + if [[ $uextra -eq 1 ]];then if [ $(parse_cnf --mysqld thread-handling) = 'pool-of-threads'];then local eport=$(parse_cnf --mysqld extra-port) - if [[ -n $eport ]];then + if [[ -n $eport ]];then # Xtrabackup works only locally. - # Hence, setting host to 127.0.0.1 unconditionally. + # Hence, setting host to 127.0.0.1 unconditionally. wsrep_log_info "SST through extra_port $eport" INNOEXTRA+=" --host=127.0.0.1 --port=$eport" use_socket=0 - else + else wsrep_log_error "Extra port $eport null, failing" exit 1 fi - else + else wsrep_log_info "Thread pool not set, ignore the option use_extra" fi fi @@ -693,7 +685,7 @@ check_extra() recv_joiner() { local dir=$1 - local msg=$2 + local msg=$2 local tmt=$3 local checkf=$4 local ltcmd @@ -706,27 +698,27 @@ recv_joiner() pushd ${dir} 1>/dev/null set +e - if [[ $tmt -gt 0 && -x `which timeout` ]];then - if timeout --help | grep -q -- '-k';then + if [[ $tmt -gt 0 && -x `which timeout` ]];then + if timeout --help | grep -q -- '-k';then ltcmd="timeout -k $(( tmt+10 )) $tmt $tcmd" - else + else ltcmd="timeout -s9 $tmt $tcmd" fi timeit "$msg" "$ltcmd | $strmcmd; RC=( "\${PIPESTATUS[@]}" )" - else + else timeit "$msg" "$tcmd | $strmcmd; RC=( "\${PIPESTATUS[@]}" )" fi set -e - popd 1>/dev/null + popd 1>/dev/null - if [[ ${RC[0]} -eq 124 ]];then + if [[ ${RC[0]} -eq 124 ]];then wsrep_log_error "Possible timeout in receving first data from donor in gtid stage" exit 32 fi - for ecode in "${RC[@]}";do - if [[ $ecode -ne 0 ]];then + for ecode in "${RC[@]}";do + if [[ $ecode -ne 0 ]];then wsrep_log_error "Error while getting data from donor node: " \ "exit codes: ${RC[@]}" exit 32 @@ -736,33 +728,30 @@ recv_joiner() if [[ $checkf -eq 1 && ! -r "${MAGIC_FILE}" ]];then # this message should cause joiner to abort wsrep_log_error "xtrabackup process ended without creating '${MAGIC_FILE}'" - wsrep_log_info "Contents of datadir" + wsrep_log_info "Contents of datadir" wsrep_log_info "$(ls -l ${dir}/*)" exit 32 fi } - send_donor() { local dir=$1 - local msg=$2 + local msg=$2 pushd ${dir} 1>/dev/null set +e timeit "$msg" "$strmcmd | $tcmd; RC=( "\${PIPESTATUS[@]}" )" set -e - popd 1>/dev/null - + popd 1>/dev/null - for ecode in "${RC[@]}";do - if [[ $ecode -ne 0 ]];then + for ecode in "${RC[@]}";do + if [[ $ecode -ne 0 ]];then wsrep_log_error "Error while getting data from donor node: " \ "exit codes: ${RC[@]}" exit 32 fi done - } # Returns the version string in a standardized format @@ -774,7 +763,7 @@ normalize_version() local minor=0 local patch=0 - # Only parses purely numeric version numbers, 1.2.3 + # Only parses purely numeric version numbers, 1.2.3 # Everything after the first three values are ignored if [[ $1 =~ ^([0-9]+)\.([0-9]+)\.?([0-9]*)([\.0-9])*$ ]]; then major=${BASH_REMATCH[1]} @@ -808,12 +797,12 @@ monitor_process() while true ; do if ! ps --pid "${WSREP_SST_OPT_PARENT}" &>/dev/null; then - wsrep_log_error "Parent mysqld process (PID:${WSREP_SST_OPT_PARENT}) terminated unexpectedly." + wsrep_log_error "Parent mysqld process (PID:${WSREP_SST_OPT_PARENT}) terminated unexpectedly." kill -- -"${WSREP_SST_OPT_PARENT}" exit 32 fi - if ! ps --pid "${sst_stream_pid}" &>/dev/null; then + if ! ps --pid "${sst_stream_pid}" &>/dev/null; then break fi @@ -822,8 +811,7 @@ monitor_process() done } - -if [[ ! -x `which $INNOBACKUPEX_BIN` ]];then +if [[ ! -x `which $INNOBACKUPEX_BIN` ]];then wsrep_log_error "innobackupex not in path: $PATH" exit 2 fi @@ -843,46 +831,43 @@ if ! check_for_version $XB_VERSION $XB_REQUIRED_VERSION; then exit 2 fi - rm -f "${MAGIC_FILE}" -if [[ ! ${WSREP_SST_OPT_ROLE} == 'joiner' && ! ${WSREP_SST_OPT_ROLE} == 'donor' ]];then +if [[ ! ${WSREP_SST_OPT_ROLE} == 'joiner' && ! ${WSREP_SST_OPT_ROLE} == 'donor' ]];then wsrep_log_error "Invalid role ${WSREP_SST_OPT_ROLE}" exit 22 fi read_cnf -if ${INNOBACKUPEX_BIN} /tmp --help 2>/dev/null | grep -q -- '--version-check'; then +if ${INNOBACKUPEX_BIN} /tmp --help 2>/dev/null | grep -q -- '--version-check'; then disver="--no-version-check" fi -if [[ ${FORCE_FTWRL:-0} -eq 1 ]];then +if [[ ${FORCE_FTWRL:-0} -eq 1 ]];then wsrep_log_info "Forcing FTWRL due to environment variable FORCE_FTWRL equal to $FORCE_FTWRL" iopts+=" --no-backup-locks " fi - INNOEXTRA="" -if [[ $ssyslog -eq 1 ]];then +if [[ $ssyslog -eq 1 ]];then - if [[ ! -x `which logger` ]];then + if [[ ! -x `which logger` ]];then wsrep_log_error "logger not in path: $PATH. Ignoring" else - wsrep_log_info "Logging all stderr of SST/Innobackupex to syslog" exec 2> >(logger -p daemon.err -t ${ssystag}wsrep-sst-$WSREP_SST_OPT_ROLE) wsrep_log_error() { - logger -p daemon.err -t ${ssystag}wsrep-sst-$WSREP_SST_OPT_ROLE "$@" + logger -p daemon.err -t ${ssystag}wsrep-sst-$WSREP_SST_OPT_ROLE "$@" } wsrep_log_info() { - logger -p daemon.info -t ${ssystag}wsrep-sst-$WSREP_SST_OPT_ROLE "$@" + logger -p daemon.info -t ${ssystag}wsrep-sst-$WSREP_SST_OPT_ROLE "$@" } INNOAPPLY="2>&1 | logger -p daemon.err -t ${ssystag}innobackupex-apply " @@ -890,7 +875,7 @@ if [[ $ssyslog -eq 1 ]];then INNOBACKUP="2> >(logger -p daemon.err -t ${ssystag}innobackupex-backup)" fi -else +else INNOAPPLY="&>\${DATA}/innobackup.prepare.log" INNOMOVE="&>\${DATA}/innobackup.move.log" INNOBACKUP="2>\${DATA}/innobackup.backup.log" @@ -976,12 +961,12 @@ then ttcmd="$tcmd" if [[ $encrypt -eq 1 ]];then - if [[ -n $scomp ]];then + if [[ -n $scomp ]];then tcmd=" \$ecmd | $scomp | $tcmd " - else + else tcmd=" \$ecmd | $tcmd " fi - elif [[ -n $scomp ]];then + elif [[ -n $scomp ]];then tcmd=" $scomp | $tcmd " fi @@ -989,10 +974,10 @@ then # Restore the transport commmand to its original state tcmd="$ttcmd" - if [[ -n $progress ]];then + if [[ -n $progress ]];then get_footprint tcmd="$pcmd | $tcmd" - elif [[ -n $rlimit ]];then + elif [[ -n $rlimit ]];then adjust_progress tcmd="$pcmd | $tcmd" fi @@ -1020,7 +1005,7 @@ then wsrep_log_error "${INNOBACKUPEX_BIN} finished with error: ${RC[0]}. " \ "Check ${DATA}/innobackup.backup.log" exit 22 - elif [[ ${RC[$(( ${#RC[@]}-1 ))]} -eq 1 ]];then + elif [[ ${RC[$(( ${#RC[@]}-1 ))]} -eq 1 ]];then wsrep_log_error "$tcmd finished with error: ${RC[1]}" exit 22 fi @@ -1028,7 +1013,6 @@ then # innobackupex implicitly writes PID to fixed location in $xtmpdir XTRABACKUP_PID="$xtmpdir/xtrabackup_pid" - else # BYPASS FOR IST wsrep_log_info "Bypassing the SST for IST" @@ -1040,12 +1024,12 @@ then echo "1" > "${DATA}/${IST_FILE}" get_keys if [[ $encrypt -eq 1 ]];then - if [[ -n $scomp ]];then + if [[ -n $scomp ]];then tcmd=" \$ecmd | $scomp | $tcmd " else tcmd=" \$ecmd | $tcmd " fi - elif [[ -n $scomp ]];then + elif [[ -n $scomp ]];then tcmd=" $scomp | $tcmd " fi strmcmd+=" \${IST_FILE}" @@ -1099,19 +1083,19 @@ then trap sig_joiner_cleanup HUP PIPE INT TERM trap cleanup_joiner EXIT - if [[ -n $progress ]];then + if [[ -n $progress ]];then adjust_progress tcmd+=" | $pcmd" fi get_keys if [[ $encrypt -eq 1 && $sencrypted -eq 1 ]];then - if [[ -n $sdecomp ]];then + if [[ -n $sdecomp ]];then strmcmd=" $sdecomp | \$ecmd | $strmcmd" - else + else strmcmd=" \$ecmd | $strmcmd" fi - elif [[ -n $sdecomp ]];then + elif [[ -n $sdecomp ]];then strmcmd=" $sdecomp | $strmcmd" fi @@ -1119,10 +1103,9 @@ then MAGIC_FILE="${STATDIR}/${INFO_FILE}" recv_joiner $STATDIR "${stagemsg}-gtid" $stimeout 1 - if ! ps -p ${WSREP_SST_OPT_PARENT} &>/dev/null then - wsrep_log_error "Parent mysqld process (PID:${WSREP_SST_OPT_PARENT}) terminated unexpectedly." + wsrep_log_error "Parent mysqld process (PID:${WSREP_SST_OPT_PARENT}) terminated unexpectedly." exit 32 fi @@ -1138,7 +1121,6 @@ then jpid=$! wsrep_log_info "Proceeding with SST" - wsrep_log_info "Cleaning the existing datadir and innodb-data/log directories" if [ "${OS}" = "FreeBSD" ]; then find -E $ib_home_dir $ib_log_dir $ib_undo_dir $DATA -mindepth 1 -prune -regex $cpat -o -exec rm -rfv {} 1>&2 \+ @@ -1164,30 +1146,27 @@ then fi fi - - TDATA=${DATA} DATA="${DATA}/.sst" - MAGIC_FILE="${DATA}/${INFO_FILE}" wsrep_log_info "Waiting for SST streaming to complete!" monitor_process $jpid get_proc - if [[ ! -s ${DATA}/xtrabackup_checkpoints ]];then + if [[ ! -s ${DATA}/xtrabackup_checkpoints ]];then wsrep_log_error "xtrabackup_checkpoints missing, failed innobackupex/SST on donor" exit 2 fi # Rebuild indexes for compact backups - if grep -q 'compact = 1' ${DATA}/xtrabackup_checkpoints;then + if grep -q 'compact = 1' ${DATA}/xtrabackup_checkpoints;then wsrep_log_info "Index compaction detected" rebuild=1 fi - if [[ $rebuild -eq 1 ]];then + if [[ $rebuild -eq 1 ]];then nthreads=$(parse_cnf xtrabackup rebuild-threads $nproc) wsrep_log_info "Rebuilding during prepare with $nthreads threads" rebuildcmd="--rebuild-indexes --rebuild-threads=$nthreads" @@ -1197,7 +1176,7 @@ then wsrep_log_info "Compressed qpress files found" - if [[ ! -x `which qpress` ]];then + if [[ ! -x `which qpress` ]];then wsrep_log_error "qpress not found in path: $PATH" exit 22 fi @@ -1205,28 +1184,27 @@ then if [[ -n $progress ]] && pv --help | grep -q 'line-mode';then count=$(find ${DATA} -type f -name '*.qp' | wc -l) count=$(( count*2 )) - if pv --help | grep -q FORMAT;then + if pv --help | grep -q FORMAT;then pvopts="-f -s $count -l -N Decompression -F '%N => Rate:%r Elapsed:%t %e Progress: [%b/$count]'" - else + else pvopts="-f -s $count -l -N Decompression" fi pcmd="pv $pvopts" adjust_progress dcmd="$pcmd | xargs -n 2 qpress -T${nproc}d" - else + else dcmd="xargs -n 2 qpress -T${nproc}d" fi - - # Decompress the qpress files + # Decompress the qpress files wsrep_log_info "Decompression with $nproc threads" timeit "Joiner-Decompression" "find ${DATA} -type f -name '*.qp' -printf '%p\n%h\n' | $dcmd" extcode=$? if [[ $extcode -eq 0 ]];then wsrep_log_info "Removing qpress files after decompression" - find ${DATA} -type f -name '*.qp' -delete - if [[ $? -ne 0 ]];then + find ${DATA} -type f -name '*.qp' -delete + if [[ $? -ne 0 ]];then wsrep_log_error "Something went wrong with deletion of qpress files. Investigate" fi else @@ -1235,13 +1213,12 @@ then fi fi - if [[ ! -z $WSREP_SST_OPT_BINLOG ]];then BINLOG_DIRNAME=$(dirname $WSREP_SST_OPT_BINLOG) BINLOG_FILENAME=$(basename $WSREP_SST_OPT_BINLOG) - # To avoid comparing data directory and BINLOG_DIRNAME + # To avoid comparing data directory and BINLOG_DIRNAME mv $DATA/${BINLOG_FILENAME}.* $BINLOG_DIRNAME/ 2>/dev/null || true pushd $BINLOG_DIRNAME &>/dev/null @@ -1257,7 +1234,7 @@ then if [ $? -ne 0 ]; then - wsrep_log_error "${INNOBACKUPEX_BIN} apply finished with errors. Check ${DATA}/innobackup.prepare.log" + wsrep_log_error "${INNOBACKUPEX_BIN} apply finished with errors. Check ${DATA}/innobackup.prepare.log" exit 22 fi @@ -1267,22 +1244,21 @@ then set -e wsrep_log_info "Moving the backup to ${TDATA}" timeit "Xtrabackup move stage" "$INNOMOVE" - if [[ $? -eq 0 ]];then + if [[ $? -eq 0 ]];then wsrep_log_info "Move successful, removing ${DATA}" rm -rf $DATA DATA=${TDATA} - else + else wsrep_log_error "Move failed, keeping ${DATA} for further diagnosis" wsrep_log_error "Check ${DATA}/innobackup.move.log for details" exit 22 fi - - else + else wsrep_log_info "${IST_FILE} received from donor: Running IST" fi - if [[ ! -r ${MAGIC_FILE} ]];then + if [[ ! -r ${MAGIC_FILE} ]];then wsrep_log_error "SST magic file ${MAGIC_FILE} not found/readable" exit 2 fi diff --git a/scripts/wsrep_sst_xtrabackup.sh b/scripts/wsrep_sst_xtrabackup.sh index c4feac2a135..d0083a8eea0 100644 --- a/scripts/wsrep_sst_xtrabackup.sh +++ b/scripts/wsrep_sst_xtrabackup.sh @@ -15,12 +15,9 @@ # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston # MA 02110-1335 USA. -# Optional dependencies and options documented here: http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html +# Optional dependencies and options documented here: http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html # Make sure to read that before proceeding! - - - . $(dirname $0)/wsrep_sst_common ealgo="" @@ -52,7 +49,7 @@ pvformat="-F '%N => Rate:%r Avg:%a Elapsed:%t %e Bytes: %b %p' " pvopts="-f -i 10 -N $WSREP_SST_OPT_ROLE " uextra=0 -if which pv &>/dev/null && pv --help | grep -q FORMAT;then +if which pv &>/dev/null && pv --help | grep -q FORMAT;then pvopts+=$pvformat fi pcmd="pv $pvopts" @@ -73,7 +70,7 @@ timeit(){ local cmd="$@" local x1 x2 took extcode - if [[ $ttime -eq 1 ]];then + if [[ $ttime -eq 1 ]];then x1=$(date +%s) wsrep_log_info "Evaluating $cmd" eval "$cmd" @@ -82,7 +79,7 @@ timeit(){ took=$(( x2-x1 )) wsrep_log_info "NOTE: $stage took $took seconds" totime=$(( totime+took )) - else + else wsrep_log_info "Evaluating $cmd" eval "$cmd" extcode=$? @@ -92,11 +89,11 @@ timeit(){ get_keys() { - if [[ $encrypt -eq 2 ]];then - return + if [[ $encrypt -eq 2 ]];then + return fi - if [[ $encrypt -eq 0 ]];then + if [[ $encrypt -eq 0 ]];then if $MY_PRINT_DEFAULTS xtrabackup | grep -q encrypt;then wsrep_log_error "Unexpected option combination. SST may fail. Refer to http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html " fi @@ -137,13 +134,13 @@ get_transfer() TSST_PORT=${WSREP_SST_OPT_PORT:-4444} if [[ $tfmt == 'nc' ]];then - if [[ ! -x `which nc` ]];then + if [[ ! -x `which nc` ]];then wsrep_log_error "nc(netcat) not found in path: $PATH" exit 2 fi wsrep_log_info "Using netcat as streamer" if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then - if nc -h 2>&1 | grep -q ncat;then + if nc -h 2>&1 | grep -q ncat;then # Ncat tcmd="nc -l ${TSST_PORT}" elif nc -h 2>&1 | grep -q -- '-d\>';then @@ -168,19 +165,19 @@ get_transfer() else tfmt='socat' wsrep_log_info "Using socat as streamer" - if [[ ! -x `which socat` ]];then + if [[ ! -x `which socat` ]];then wsrep_log_error "socat not found in path: $PATH" exit 2 fi - if [[ $encrypt -eq 2 ]] && ! socat -V | grep -q OPENSSL;then + if [[ $encrypt -eq 2 ]] && ! socat -V | grep -q OPENSSL;then wsrep_log_info "NOTE: socat is not openssl enabled, falling back to plain transfer" encrypt=0 fi - if [[ $encrypt -eq 2 ]];then + if [[ $encrypt -eq 2 ]];then wsrep_log_info "Using openssl based encryption with socat" - if [[ -z $tpem || -z $tcert ]];then + if [[ -z $tpem || -z $tcert ]];then wsrep_log_error "Both PEM and CRT files required" exit 22 fi @@ -191,7 +188,7 @@ get_transfer() wsrep_log_info "Encrypting with PEM $tpem, CA: $tcert" tcmd="socat -u stdio openssl-connect:${WSREP_SST_OPT_HOST}:${TSST_PORT},cert=$tpem,cafile=${tcert}${sockopt}" fi - else + else if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then tcmd="socat -u TCP-LISTEN:${TSST_PORT},reuseaddr${sockopt} stdio" else @@ -199,14 +196,13 @@ get_transfer() fi fi fi - } get_footprint() { pushd $WSREP_SST_OPT_DATA 1>/dev/null payload=$(find . -regex '.*\.ibd$\|.*\.MYI$\|.*\.MYD$\|.*ibdata1$' -type f -print0 | du --files0-from=- --block-size=1 -c -s | awk 'END { print $1 }') - if $MY_PRINT_DEFAULTS xtrabackup | grep -q -- "--compress";then + if $MY_PRINT_DEFAULTS xtrabackup | grep -q -- "--compress";then # QuickLZ has around 50% compression ratio # When compression/compaction used, the progress is only an approximate. payload=$(( payload*1/2 )) @@ -218,16 +214,16 @@ get_footprint() adjust_progress() { - if [[ -n $progress && $progress != '1' ]];then - if [[ -e $progress ]];then + if [[ -n $progress && $progress != '1' ]];then + if [[ -e $progress ]];then pcmd+=" 2>>$progress" - else + else pcmd+=" 2>$progress" fi - elif [[ -z $progress && -n $rlimit ]];then + elif [[ -z $progress && -n $rlimit ]];then # When rlimit is non-zero pcmd="pv -q" - fi + fi if [[ -n $rlimit && "$WSREP_SST_OPT_ROLE" == "donor" ]];then wsrep_log_info "Rate-limiting SST to $rlimit" @@ -251,7 +247,7 @@ read_cnf() ekey=$(parse_cnf xtrabackup encrypt-key "") ekeyfile=$(parse_cnf xtrabackup encrypt-key-file "") - # Refer to http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html + # Refer to http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html if [[ -z $ealgo ]];then ealgo=$(parse_cnf sst encrypt-algo "") ekey=$(parse_cnf sst encrypt-key "") @@ -263,7 +259,7 @@ read_cnf() get_stream() { - if [[ $sfmt == 'xbstream' ]];then + if [[ $sfmt == 'xbstream' ]];then wsrep_log_info "Streaming with xbstream" if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then strmcmd="xbstream -x" @@ -278,7 +274,6 @@ get_stream() else strmcmd="tar cf - \${INFO_FILE} \${IST_FILE}" fi - fi } @@ -300,14 +295,14 @@ cleanup_joiner() { # Since this is invoked just after exit NNN local estatus=$? - if [[ $estatus -ne 0 ]];then + if [[ $estatus -ne 0 ]];then wsrep_log_error "Cleanup after exit with status:$estatus" fi if [ "${WSREP_SST_OPT_ROLE}" = "joiner" ];then wsrep_log_info "Removing the sst_in_progress file" wsrep_cleanup_progress_file fi - if [[ -n $progress && -p $progress ]];then + if [[ -n $progress && -p $progress ]];then wsrep_log_info "Cleaning up fifo file $progress" rm $progress fi @@ -323,22 +318,22 @@ cleanup_donor() { # Since this is invoked just after exit NNN local estatus=$? - if [[ $estatus -ne 0 ]];then + if [[ $estatus -ne 0 ]];then wsrep_log_error "Cleanup after exit with status:$estatus" fi - if [[ -n $XTRABACKUP_PID ]];then + if [[ -n $XTRABACKUP_PID ]];then if check_pid $XTRABACKUP_PID then wsrep_log_error "xtrabackup process is still running. Killing... " kill_xtrabackup fi - - rm -f $XTRABACKUP_PID + rm -f $XTRABACKUP_PID fi + rm -f ${DATA}/${IST_FILE} - if [[ -n $progress && -p $progress ]];then + if [[ -n $progress && -p $progress ]];then wsrep_log_info "Cleaning up fifo file $progress" rm $progress fi @@ -363,9 +358,9 @@ wait_for_listen() ss -p state listening "( sport = :$PORT )" | grep -qE 'socat|nc' && break sleep 0.2 done - if [[ $incremental -eq 1 ]];then + if [[ $incremental -eq 1 ]];then echo "ready ${ADDR}/${MODULE}/$lsn" - else + else echo "ready ${ADDR}/${MODULE}" fi } @@ -373,20 +368,20 @@ wait_for_listen() check_extra() { local use_socket=1 - if [[ $uextra -eq 1 ]];then + if [[ $uextra -eq 1 ]];then if [ $(parse_cnf --mysqld thread-handling) = 'pool-of-threads'];then local eport=$(parse_cnf --mysqld extra-port) - if [[ -n $eport ]];then + if [[ -n $eport ]];then # Xtrabackup works only locally. - # Hence, setting host to 127.0.0.1 unconditionally. + # Hence, setting host to 127.0.0.1 unconditionally. wsrep_log_info "SST through extra_port $eport" INNOEXTRA+=" --host=127.0.0.1 --port=$eport" use_socket=0 - else + else wsrep_log_error "Extra port $eport null, failing" exit 1 fi - else + else wsrep_log_info "Thread pool not set, ignore the option use_extra" fi fi @@ -395,14 +390,14 @@ check_extra() fi } -if [[ ! -x `which innobackupex` ]];then +if [[ ! -x `which innobackupex` ]];then wsrep_log_error "innobackupex not in path: $PATH" exit 2 fi rm -f "${MAGIC_FILE}" -if [[ ! ${WSREP_SST_OPT_ROLE} == 'joiner' && ! ${WSREP_SST_OPT_ROLE} == 'donor' ]];then +if [[ ! ${WSREP_SST_OPT_ROLE} == 'joiner' && ! ${WSREP_SST_OPT_ROLE} == 'donor' ]];then wsrep_log_error "Invalid role ${WSREP_SST_OPT_ROLE}" exit 22 fi @@ -440,12 +435,12 @@ then if [[ $encrypt -eq 1 ]];then if [[ -n $ekey ]];then INNOEXTRA+=" --encrypt=$ealgo --encrypt-key=$ekey" - else + else INNOEXTRA+=" --encrypt=$ealgo --encrypt-key-file=$ekeyfile" fi fi - if [[ -n $lsn ]];then + if [[ -n $lsn ]];then INNOEXTRA+=" --incremental --incremental-lsn=$lsn" fi @@ -453,10 +448,10 @@ then wsrep_log_info "Streaming the backup to joiner at ${WSREP_SST_OPT_HOST} ${WSREP_SST_OPT_PORT}" - if [[ -n $progress ]];then + if [[ -n $progress ]];then get_footprint tcmd="$pcmd | $tcmd" - elif [[ -n $rlimit ]];then + elif [[ -n $rlimit ]];then adjust_progress tcmd="$pcmd | $tcmd" fi @@ -469,7 +464,7 @@ then wsrep_log_error "${INNOBACKUPEX_BIN} finished with error: ${RC[0]}. " \ "Check ${DATA}/innobackup.backup.log" exit 22 - elif [[ ${RC[$(( ${#RC[@]}-1 ))]} -eq 1 ]];then + elif [[ ${RC[$(( ${#RC[@]}-1 ))]} -eq 1 ]];then wsrep_log_error "$tcmd finished with error: ${RC[1]}" exit 22 fi @@ -496,13 +491,14 @@ then set -e popd 1>/dev/null - for ecode in "${RC[@]}";do - if [[ $ecode -ne 0 ]];then + for ecode in "${RC[@]}";do + if [[ $ecode -ne 0 ]];then wsrep_log_error "Error while streaming data to joiner node: " \ "exit codes: ${RC[@]}" exit 1 fi done + fi echo "done ${WSREP_SST_OPT_GTID}" @@ -513,11 +509,11 @@ then [[ -e $SST_PROGRESS_FILE ]] && wsrep_log_info "Stale sst_in_progress file: $SST_PROGRESS_FILE" touch $SST_PROGRESS_FILE - if [[ ! -e ${DATA}/ibdata1 ]];then + if [[ ! -e ${DATA}/ibdata1 ]];then incremental=0 fi - if [[ $incremental -eq 1 ]];then + if [[ $incremental -eq 1 ]];then wsrep_log_info "Incremental SST enabled" #lsn=$(/pxc/bin/mysqld $WSREP_SST_OPT_CONF --basedir=/pxc --wsrep-recover 2>&1 | grep -o 'log sequence number .*' | cut -d " " -f 4 | head -1) lsn=$(grep to_lsn xtrabackup_checkpoints | cut -d= -f2 | tr -d ' ') @@ -539,12 +535,12 @@ then trap sig_joiner_cleanup HUP PIPE INT TERM trap cleanup_joiner EXIT - if [[ -n $progress ]];then + if [[ -n $progress ]];then adjust_progress tcmd+=" | $pcmd" fi - if [[ $incremental -eq 1 ]];then + if [[ $incremental -eq 1 ]];then BDATA=$DATA DATA=$(mktemp -d) MAGIC_FILE="${DATA}/${INFO_FILE}" @@ -558,13 +554,13 @@ then pushd ${DATA} 1>/dev/null timeit "Joiner-Recv-Unencrypted" "$tcmd | $strmcmd; RC=( "\${PIPESTATUS[@]}" )" - popd 1>/dev/null + popd 1>/dev/null set -e - if [[ $sfmt == 'xbstream' ]];then + if [[ $sfmt == 'xbstream' ]];then # Special handling till lp:1193240 is fixed" - if [[ ${RC[$(( ${#RC[@]}-1 ))]} -eq 1 ]];then + if [[ ${RC[$(( ${#RC[@]}-1 ))]} -eq 1 ]];then wsrep_log_error "Xbstream failed" wsrep_log_error "Data directory ${DATA} may not be empty: lp:1193240" \ "Manual intervention required in that case" @@ -574,8 +570,8 @@ then wait %% # join for wait_for_listen thread - for ecode in "${RC[@]}";do - if [[ $ecode -ne 0 ]];then + for ecode in "${RC[@]}";do + if [[ $ecode -ne 0 ]];then wsrep_log_error "Error while getting data from donor node: " \ "exit codes: ${RC[@]}" exit 32 @@ -586,22 +582,23 @@ then then # this message should cause joiner to abort wsrep_log_error "xtrabackup process ended without creating '${MAGIC_FILE}'" - wsrep_log_info "Contents of datadir" + wsrep_log_info "Contents of datadir" wsrep_log_info "$(ls -l ${DATA}/**/*)" exit 32 fi if ! ps -p ${WSREP_SST_OPT_PARENT} &>/dev/null then - wsrep_log_error "Parent mysqld process (PID:${WSREP_SST_OPT_PARENT}) terminated unexpectedly." + wsrep_log_error "Parent mysqld process (PID:${WSREP_SST_OPT_PARENT}) terminated unexpectedly." exit 32 fi if [ ! -r "${DATA}/${IST_FILE}" ] then wsrep_log_info "Proceeding with SST" + wsrep_log_info "Removing existing ib_logfile files" - if [[ $incremental -ne 1 ]];then + if [[ $incremental -ne 1 ]];then rm -f ${DATA}/ib_logfile* else rm -f ${BDATA}/ib_logfile* @@ -610,12 +607,12 @@ then get_proc # Rebuild indexes for compact backups - if grep -q 'compact = 1' ${DATA}/xtrabackup_checkpoints;then + if grep -q 'compact = 1' ${DATA}/xtrabackup_checkpoints;then wsrep_log_info "Index compaction detected" rebuild=1 fi - if [[ $rebuild -eq 1 ]];then + if [[ $rebuild -eq 1 ]];then nthreads=$(parse_cnf xtrabackup rebuild-threads $nproc) wsrep_log_info "Rebuilding during prepare with $nthreads threads" rebuildcmd="--rebuild-indexes --rebuild-threads=$nthreads" @@ -625,7 +622,7 @@ then wsrep_log_info "Compressed qpress files found" - if [[ ! -x `which qpress` ]];then + if [[ ! -x `which qpress` ]];then wsrep_log_error "qpress not found in path: $PATH" exit 22 fi @@ -633,30 +630,30 @@ then if [[ -n $progress ]] && pv --help | grep -q 'line-mode';then count=$(find ${DATA} -type f -name '*.qp' | wc -l) count=$(( count*2 )) - if pv --help | grep -q FORMAT;then + if pv --help | grep -q FORMAT;then pvopts="-f -s $count -l -N Decompression -F '%N => Rate:%r Elapsed:%t %e Progress: [%b/$count]'" - else + else pvopts="-f -s $count -l -N Decompression" fi pcmd="pv $pvopts" adjust_progress dcmd="$pcmd | xargs -n 2 qpress -T${nproc}d" - else + else dcmd="xargs -n 2 qpress -T${nproc}d" fi wsrep_log_info "Removing existing ibdata1 file" rm -f ${DATA}/ibdata1 - # Decompress the qpress files + # Decompress the qpress files wsrep_log_info "Decompression with $nproc threads" timeit "Decompression" "find ${DATA} -type f -name '*.qp' -printf '%p\n%h\n' | $dcmd" extcode=$? if [[ $extcode -eq 0 ]];then wsrep_log_info "Removing qpress files after decompression" - find ${DATA} -type f -name '*.qp' -delete - if [[ $? -ne 0 ]];then + find ${DATA} -type f -name '*.qp' -delete + if [[ $? -ne 0 ]];then wsrep_log_error "Something went wrong with deletion of qpress files. Investigate" fi else @@ -665,7 +662,7 @@ then fi fi - if [[ $incremental -eq 1 ]];then + if [[ $incremental -eq 1 ]];then # Added --ibbackup=xtrabackup_55 because it fails otherwise citing connection issues. INNOAPPLY="${INNOBACKUPEX_BIN} ${WSREP_SST_OPT_CONF} \ --ibbackup=xtrabackup_55 --apply-log $rebuildcmd --redo-only $BDATA --incremental-dir=${DATA} &>>${BDATA}/innobackup.prepare.log" @@ -674,7 +671,7 @@ then wsrep_log_info "Preparing the backup at ${DATA}" timeit "Xtrabackup prepare stage" "$INNOAPPLY" - if [[ $incremental -eq 1 ]];then + if [[ $incremental -eq 1 ]];then wsrep_log_info "Cleaning up ${DATA} after incremental SST" [[ -d ${DATA} ]] && rm -rf ${DATA} DATA=$BDATA @@ -682,10 +679,10 @@ then if [ $? -ne 0 ]; then - wsrep_log_error "${INNOBACKUPEX_BIN} finished with errors. Check ${DATA}/innobackup.prepare.log" + wsrep_log_error "${INNOBACKUPEX_BIN} finished with errors. Check ${DATA}/innobackup.prepare.log" exit 22 fi - else + else wsrep_log_info "${IST_FILE} received from donor: Running IST" fi |