summaryrefslogtreecommitdiff
path: root/scripts/wsrep_sst_xtrabackup.sh
diff options
context:
space:
mode:
authorJulius Goryavsky <julius.goryavsky@mariadb.com>2021-04-15 13:53:28 +0200
committerJulius Goryavsky <julius.goryavsky@mariadb.com>2021-05-03 18:08:13 +0200
commite0324bf300a57e84e5fdeca995c91b9efa3dc62c (patch)
treeb9dc6091e71e281e99ee610fab7ace98975bb4c6 /scripts/wsrep_sst_xtrabackup.sh
parent562c88257f574d297ca0d9c284ed80390a3c927b (diff)
downloadmariadb-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.
Diffstat (limited to 'scripts/wsrep_sst_xtrabackup.sh')
-rw-r--r--scripts/wsrep_sst_xtrabackup.sh147
1 files changed, 72 insertions, 75 deletions
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