From 4b6bb2e49a974e298e1b05549d1dec73de9e2237 Mon Sep 17 00:00:00 2001 From: SK Ali Arman Date: Thu, 5 Dec 2024 16:25:12 +0600 Subject: [PATCH] Add PITR Replication Strategy Support & Fix Same Memeber_ID (#43) Signed-off-by: SK Ali Arman --- init-script/run.sh | 1 + scripts/copy-data.sh | 32 ++++++++++++++++++++++++++++++++ scripts/directory-exist.sh | 0 scripts/run.sh | 15 +++++++++++++++ scripts/standalone-run.sh | 19 +++++++++++++++++++ 5 files changed, 67 insertions(+) create mode 100755 scripts/copy-data.sh mode change 100644 => 100755 scripts/directory-exist.sh create mode 100755 scripts/standalone-run.sh diff --git a/init-script/run.sh b/init-script/run.sh index 43b1dbf..f2a8174 100755 --- a/init-script/run.sh +++ b/init-script/run.sh @@ -2,4 +2,5 @@ rm -rf /var/lib/mysql/lost+found rm -rf /run-scripts/* +rm /var/lib/mysql/auto.cnf cp /tmp/scripts/* /scripts diff --git a/scripts/copy-data.sh b/scripts/copy-data.sh new file mode 100755 index 0000000..c121f98 --- /dev/null +++ b/scripts/copy-data.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +ROOT_DIR="$ROOT_DIR" +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 +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 + 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 \ No newline at end of file diff --git a/scripts/directory-exist.sh b/scripts/directory-exist.sh old mode 100644 new mode 100755 diff --git a/scripts/run.sh b/scripts/run.sh index bbaebb8..2e1130b 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -16,6 +16,21 @@ # PRIMARY_TYPE = defines single/multi primary env | sort | grep "POD\|HOST\|NAME" +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 + done +fi + +if [[ -e "$RECOVERY_DONE_FILE" ]]; then + rm $RECOVERY_DONE_FILE +fi args=$@ script_name=${0##*/} diff --git a/scripts/standalone-run.sh b/scripts/standalone-run.sh new file mode 100755 index 0000000..94afbd3 --- /dev/null +++ b/scripts/standalone-run.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +if [[ -z "$TOPOLOGY" ]]; then + 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 + done + fi + + if [[ -e "$RECOVERY_DONE_FILE" ]]; then + rm $RECOVERY_DONE_FILE + fi +fi \ No newline at end of file