Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions scripts/backup-stream-file-exists.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

if [ -f /scripts/backup_data_stream_pod_ip.txt ]; then
echo -n "Yes"
echo -n "Yes"
else
echo -n "No"
fi
echo -n "No"
fi
20 changes: 10 additions & 10 deletions scripts/backup-stream.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env bash

ip=$(cat "/scripts/backup_data_stream_pod_ip.txt")
echo "Start master data transferring..ip $ip"
export MYSQL_PWD="$MYSQL_ROOT_PASSWORD"
mariabackup --backup --stream=mbstream --user=root | socat -u STDIN TCP:$ip:3307
if [ $? -eq 0 ]; then
echo "Backup data for pod $ip transferred successfully."
else
echo "Backup data transfer for pod $ip failed."
fi
rm /scripts/backup_data_stream_pod_ip.txt
ip=$(cat "/scripts/backup_data_stream_pod_ip.txt")
echo "Start master data transferring..ip $ip"
export MYSQL_PWD="$MYSQL_ROOT_PASSWORD"
mariabackup --backup --stream=mbstream --user=root | socat -u STDIN TCP:$ip:3307
if [ $? -eq 0 ]; then
echo "Backup data for pod $ip transferred successfully."
else
echo "Backup data transfer for pod $ip failed."
fi
rm /scripts/backup_data_stream_pod_ip.txt
38 changes: 19 additions & 19 deletions scripts/copy-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ TOTAL_DIR_TO_COPY="$TOTAL_DIR_TO_COPY"
DATA_DIR="$DATA_DIR"

if [ -z "$ROOT_DIR" ] || [ -z "$TOTAL_DIR_TO_COPY" ]; then
echo "ROOT_DIR and TOTAL_DIR_TO_COPY must be set."
exit 1
echo "ROOT_DIR and TOTAL_DIR_TO_COPY must be set."
exit 1
fi
Size1=$(du -s "$ROOT_DIR" | cut -f1)
echo "DATA DIRECTORY SIZE: ", $Size1
for (( i = 1; i <= $TOTAL_DIR_TO_COPY; i++ ));do
if [[ -d "$ROOT_DIR$i" ]];then
Size2=$(du -s "$ROOT_DIR$i" | cut -f1)
echo $Size1, " ", $Size2
if [[ "$Size1" == "$Size2" ]];then
continue
for ((i = 1; i <= $TOTAL_DIR_TO_COPY; i++)); do
if [[ -d "$ROOT_DIR$i" ]]; then
Size2=$(du -s "$ROOT_DIR$i" | cut -f1)
echo $Size1, " ", $Size2
if [[ "$Size1" == "$Size2" ]]; then
continue
fi
fi
# not deleting any data
# because the sole purpose of this script is to copy the data
# rm -rf "$ROOT_DIR$i"/*
rm "$ROOT_DIR/mysql.sock"
cp -rvL "$ROOT_DIR/"* "$ROOT_DIR$i"/
if [[ $? -ne 0 ]]; then
echo "Error occurred while copying to $ROOT_DIR$i"
exit 1
fi
fi
# not deleting any data
# because the sole purpose of this script is to copy the data
# rm -rf "$ROOT_DIR$i"/*
rm "$ROOT_DIR/mysql.sock"
cp -rvL "$ROOT_DIR/"* "$ROOT_DIR$i"/
if [[ $? -ne 0 ]]; then
echo "Error occurred while copying to $ROOT_DIR$i"
exit 1
fi
done

exit 0
exit 0
20 changes: 10 additions & 10 deletions scripts/ensure-restore.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#!/usr/bin/env bash

if [[ "$PITR_RESTORE" == "true" ]]; then
if [[ "$HOSTNAME" != *"-0" ]]; then
if [[ -f /var/lib/mysql/gvwstate.dat ]]; then
rm /var/lib/mysql/gvwstate.dat
if [[ "$HOSTNAME" != *"-0" ]]; then
if [[ -f /var/lib/mysql/gvwstate.dat ]]; then
rm /var/lib/mysql/gvwstate.dat
fi
fi
fi
fi

RECOVERY_DONE_FILE="/tmp/recovery.done"
if [[ "$PITR_RESTORE" == "true" ]]; then
while true; do
sleep 2
echo "Point In Time Recovery In Progress. Waiting for $RECOVERY_DONE_FILE file"
if [[ -e "$RECOVERY_DONE_FILE" ]]; then
echo "$RECOVERY_DONE_FILE found."
break
fi
sleep 2
echo "Point In Time Recovery In Progress. Waiting for $RECOVERY_DONE_FILE file"
if [[ -e "$RECOVERY_DONE_FILE" ]]; then
echo "$RECOVERY_DONE_FILE found."
break
fi
done
fi
24 changes: 12 additions & 12 deletions scripts/on-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ hosts=$(cat "/scripts/peer-list")
log "INFO" "hosts are {$hosts}"

if [[ $DISTRIBUTED == "true" ]]; then
while [ ! -f "/etc/podip/podip" ];do
sleep 1
echo "nsmIP not available!!!"
done

while [ ! -s /etc/podip/podip ]; do
sleep 1
echo "nsm ip not available"
done

export POD_IP=$(cat /etc/podip/podip)
log "INFO" "pod ip is-> $POD_IP"
while [ ! -f "/etc/podip/podip" ]; do
sleep 1
echo "nsmIP not available!!!"
done

while [ ! -s /etc/podip/podip ]; do
sleep 1
echo "nsm ip not available"
done

export POD_IP=$(cat /etc/podip/podip)
log "INFO" "pod ip is-> $POD_IP"
fi

# write on galera configuration file
Expand Down
1 change: 0 additions & 1 deletion scripts/std-replication-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ while [ true ]; do
./scripts/std-replication-on-start.sh $@
sleep 1
done

100 changes: 49 additions & 51 deletions scripts/std-replication-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ function wait_for_mysqld_running() {

joining_for_first_time=1

function alter_user(){
local mysql="$mysql_header --host=$localhost"
local ssl_require=""
local user="$1"
if [[ "${REQUIRE_SSL:-}" == "TRUE" ]]; then
function alter_user() {
local mysql="$mysql_header --host=$localhost"
local ssl_require=""
local user="$1"
if [[ "${REQUIRE_SSL:-}" == "TRUE" ]]; then
ssl_require="REQUIRE SSL"
else
else
ssl_require="REQUIRE NONE"
fi
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;ALTER USER '$user'@'%' $ssl_require;"
fi
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;ALTER USER '$user'@'%' $ssl_require;"
}

function create_replication_user() {
Expand Down Expand Up @@ -137,7 +137,6 @@ function create_maxscale_user() {
# fi
#}


function create_monitor_user() {
log "INFO" "Checking whether monitor user exist or not......"
local mysql="$mysql_header --host=$localhost"
Expand All @@ -151,12 +150,12 @@ function create_monitor_user() {
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;CREATE USER 'monitor_user'@'%' IDENTIFIED BY '$MYSQL_ROOT_PASSWORD';"
#mariadb 10.6+ change SUPER-> READ_ONLY ADMIN, REPLICATION CLIENT> SLAVE MONITOR
if [[ "$(echo -e "1:10.7\n$MARIADB_VERSION" | sort -V | tail -n1)" == "$MARIADB_VERSION" ]]; then
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT READ_ONLY ADMIN, RELOAD on *.* to 'monitor_user'@'%';"
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT SLAVE MONITOR ON *.* TO 'monitor_user'@'%';"
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT BINLOG ADMIN, REPLICATION MASTER ADMIN, REPLICATION SLAVE ADMIN ON *.* TO 'monitor_user'@'%';"
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT READ_ONLY ADMIN, RELOAD on *.* to 'monitor_user'@'%';"
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT SLAVE MONITOR ON *.* TO 'monitor_user'@'%';"
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT BINLOG ADMIN, REPLICATION MASTER ADMIN, REPLICATION SLAVE ADMIN ON *.* TO 'monitor_user'@'%';"
else
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT SUPER, RELOAD on *.* to 'monitor_user'@'%';"
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT REPLICATION CLIENT on *.* to 'monitor_user'@'%';"
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT SUPER, RELOAD on *.* to 'monitor_user'@'%';"
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT REPLICATION CLIENT on *.* to 'monitor_user'@'%';"
fi

retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;FLUSH PRIVILEGES;"
Expand Down Expand Up @@ -199,7 +198,7 @@ function join_to_master_by_slave_pos() {
retry 20 ${mysql} -N -e "STOP SLAVE;"
retry 20 ${mysql} -N -e "RESET SLAVE ALL;"
if [ $joining_for_first_time -eq 1 ]; then
retry 20 ${mysql} -N -e "SET GLOBAL gtid_slave_pos = '$gtid';"
retry 20 ${mysql} -N -e "SET GLOBAL gtid_slave_pos = '$gtid';"
fi
if [[ "${REQUIRE_SSL:-}" == "TRUE" ]]; then
ssl_options=", MASTER_SSL=1, MASTER_SSL_CA='/etc/mysql/certs/server/ca.crt'"
Expand Down Expand Up @@ -231,30 +230,30 @@ function start_mysqld_in_background() {

backup_restored=0
if [ -f "/scripts/receive_backup.txt" ]; then
echo "Waiting for the master to start streaming backup data..."
echo "$POD_IP">/scripts/backup_receive_started.txt
while true; do
socat -u TCP-LISTEN:3307 STDOUT | mbstream -x -C /var/lib/mysql
if [ $? -eq 0 ]; then
log "INFO" "Data restore successful."
break
else
log "INFO" "Data restore failed."
rm -rf /var/lib/mysql
fi
done
mariabackup --prepare --target-dir=/var/lib/mysql
rm /scripts/backup_receive_started.txt
backup_restored=1
rm /scripts/receive_backup.txt
echo "Waiting for the master to start streaming backup data..."
echo "$POD_IP" >/scripts/backup_receive_started.txt
while true; do
socat -u TCP-LISTEN:3307 STDOUT | mbstream -x -C /var/lib/mysql
if [ $? -eq 0 ]; then
log "INFO" "Data restore successful."
break
else
log "INFO" "Data restore failed."
rm -rf /var/lib/mysql
fi
done
mariabackup --prepare --target-dir=/var/lib/mysql
rm /scripts/backup_receive_started.txt
backup_restored=1
rm /scripts/receive_backup.txt
fi

start_mysqld_in_background

if [[ "${REQUIRE_SSL:-}" == "TRUE" ]]; then
export mysql_header="mariadb -u ${USER} --port=3306 --ssl-ca=/etc/mysql/certs/server/ca.crt --ssl-cert=/etc/mysql/certs/server/tls.crt --ssl-key=/etc/mysql/certs/server/tls.key"
export mysql_header="mariadb -u ${USER} --port=3306 --ssl-ca=/etc/mysql/certs/server/ca.crt --ssl-cert=/etc/mysql/certs/server/tls.crt --ssl-key=/etc/mysql/certs/server/tls.key"
else
export mysql_header="mariadb -u ${USER} --port=3306"
export mysql_header="mariadb -u ${USER} --port=3306"
fi

export MYSQL_PWD=${PASSWORD}
Expand Down Expand Up @@ -299,27 +298,26 @@ while true; do
fi

if [[ $desired_func == "join_to_master" ]]; then
# wait for the script copied by coordinator
while [ ! -f "/scripts/master.txt" ]; do
log "WARNING" "master detector file isn't present yet!"
sleep 1
done
master=$(cat /scripts/master.txt)
rm -rf /scripts/master.txt
if [[ $backup_restored -eq 0 ]]; then
join_to_master_by_current_pos
else
while [ ! -f "/scripts/gtid.txt" ]; do
log "WARNING" "gtid detector file isn't present yet!"
# wait for the script copied by coordinator
while [ ! -f "/scripts/master.txt" ]; do
log "WARNING" "master detector file isn't present yet!"
sleep 1
done
gtid=$(cat /scripts/gtid.txt)
echo "master replica's current gtid position is $gtid"
rm -rf /scripts/gtid.txt
join_to_master_by_slave_pos
fi
master=$(cat /scripts/master.txt)
rm -rf /scripts/master.txt
if [[ $backup_restored -eq 0 ]]; then
join_to_master_by_current_pos
else
while [ ! -f "/scripts/gtid.txt" ]; do
log "WARNING" "gtid detector file isn't present yet!"
sleep 1
done
gtid=$(cat /scripts/gtid.txt)
echo "master replica's current gtid position is $gtid"
rm -rf /scripts/gtid.txt
join_to_master_by_slave_pos
fi
fi
log "INFO" "waiting for mysql process id = $pid"
wait $pid
done