Skip to content

Commit

Permalink
Added Automation script for windows installation (#188)
Browse files Browse the repository at this point in the history
* Added Automation script for windows installation

* Added Automation script for windows installation

* Added Automation script for windows installation

* Commented output file
  • Loading branch information
sushantpatil1214 authored Mar 4, 2024
1 parent afd9e6c commit c8d500c
Show file tree
Hide file tree
Showing 20 changed files with 1,102 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -e
set -u

echo
echo "Down stack"
source ./helper/scripts/d-stack-08-rm.sh
source ./helper/scripts/d-stack-09-wait-removed.sh

echo
echo "Up app containers"
source ./helper/scripts/d-stack-01-create-dirs.sh
sleep 2
source ./helper/scripts/d-stack-02-deploy-0.sh
sleep 2
source ./helper/scripts/d-stack-03-up-hub-containers.sh

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export DATA_DGRAPH_ALPHA_01_DIR=${PROJECT_DATA_DIR}/dgraph/alpha-01
export DATA_DGRAPH_ALPHA_02_DIR=${PROJECT_DATA_DIR}/dgraph/alpha-02
export DATA_DGRAPH_ALPHA_03_DIR=${PROJECT_DATA_DIR}/dgraph/alpha-03
export DATA_POSTGRESQL_DIR=${PROJECT_DATA_DIR}/postgres
export DATA_POSTGRESQL_DB_DIR=${PROJECT_DATA_DIR}/postgres_db
export POSTGRES_BACKUP_DIRECTORY=${PROJECT_DATA_DIR}/backups/postgres
export DGRAPH_BACKUP_DIRECTORY=${PROJECT_DATA_DIR}/backups/dgraph

export SCALE_KEYCLOAK_TEST_SERVER=${SCALE_KEYCLOAK_TEST_SERVER}
export SCALE_NGINX=${SCALE_NGINX}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export DATA_KAFKA_01_DIR=${PROJECT_DATA_DIR}/kafka-01
export DATA_DGRAPH_ZERO_01_DIR=${PROJECT_DATA_DIR}/dgraph/zero-01
export DATA_DGRAPH_ALPHA_01_DIR=${PROJECT_DATA_DIR}/dgraph/alpha-01
export DATA_POSTGRESQL_DIR=${PROJECT_DATA_DIR}/postgres
export DATA_POSTGRESQL_DB_DIR=${PROJECT_DATA_DIR}/postgres_db
export POSTGRES_BACKUP_DIRECTORY=${PROJECT_DATA_DIR}/backups/postgres
export DGRAPH_BACKUP_DIRECTORY=${PROJECT_DATA_DIR}/backups/dgraph

export SCALE_KEYCLOAK_TEST_SERVER=${SCALE_KEYCLOAK_TEST_SERVER}
export SCALE_NGINX=${SCALE_NGINX}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e
set -u

pushd .
SCRIPT_DIR=$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)
cd ${SCRIPT_DIR}/../..

java_args="${@:1}"
source ./conf.env
docker exec $(docker ps -q -f name=bootstrapper) /bootstrapper.sh $java_args

popd
16 changes: 16 additions & 0 deletions devops/windows/base-docker-wsl/helper/bootstrapper/bootstrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

pushd "$(dirname "$0")"
# Creating conf.env file
pushd ./docker/conf/env || exit
source ./create-env-linux-high-1.sh
popd || exit

source ./source/conf.env

java_args="${@:1}"

pushd ../../JeMPI_Apps/JeMPI_Bootstrapper
mvn compile exec:java -Dexec.mainClass="org.jembi.jempi.bootstrapper.BootstrapperCLI" -Dexec.args="$java_args"
popd
popd
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ pushd .
mkdir -p ${DATA_POSTGRESQL_DIR}
cp conf/postgres/*.* ${DATA_POSTGRESQL_DIR}/.

mkdir -p ${DATA_POSTGRESQL_DB_DIR}
sudo chown -R 1001:1001 ${DATA_POSTGRESQL_DB_DIR}
sudo chmod -R 770 ${DATA_POSTGRESQL_DB_DIR}


echo

popd
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,4 @@ pushd .
docker service scale ${STACK_NAME}_ratel=${SCALE_RATEL}


pushd helper/topics
source ./topics-create.sh
source ./topics-list.sh
popd
pushd helper/postgres
source ./create-schema.sh
popd
popd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -e
set -u

echo
echo "Down stack"
source ./helper/scripts/d-stack-08-rm.sh
source ./helper/scripts/d-stack-09-wait-removed.sh

echo
echo "Up app containers"
source ./helper/scripts/d-stack-01-create-dirs.sh
sleep 2
source ./helper/scripts/d-stack-02-deploy-0.sh
sleep 2
source ./helper/scripts/d-stack-03-up-hub-containers.sh

80 changes: 80 additions & 0 deletions devops/windows/deployment/backup_restore/dgraph-backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash
echo "$PWD"
source ../../base-docker-wsl/conf.env
# Load Environment Variables for DGraph Alpha and Zero Nodes
DGRAPH_ALPHA_HOSTS="${DGRAPH_HOSTS:-localhost}"
DGRAPH_ALPHA_PORTS="${DGRAPH_PORTS:-8080}"
DGRAPH_ZERO_HOSTS="${DGRAPH_ZERO_HOSTS:-localhost}"
DGRAPH_ZERO_PORTS="${DGRAPH_ZERO_PORTS:-5080}"

# Load Environment Variables for Data Directories
DATA_DGRAPH_ZERO_01_DIR="${DATA_DGRAPH_ZERO_01_DIR}"
DATA_DGRAPH_ALPHA_01_DIR="${DATA_DGRAPH_ALPHA_01_DIR}"
DATA_DGRAPH_ALPHA_02_DIR="${DATA_DGRAPH_ALPHA_02_DIR:-}" # Optional
DATA_DGRAPH_ALPHA_03_DIR="${DATA_DGRAPH_ALPHA_03_DIR:-}" # Optional
BACKUP_PATH="${DGRAPH_BACKUP_DIRECTORY}/$(date +%Y%m%d_%H%M%S)"
REMOTE_SERVER="${DGRAPH_BACKUP_REMOTE_SERVER}"
REMOTE_PATH="${DGRAPH_BACKUP_REMOTE_PATH}"

# Create Backup Directory if it doesn't exist
[ ! -d "$BACKUP_PATH" ] && mkdir -p "$BACKUP_PATH"

LOG_FILE="${BACKUP_PATH}/dgraph_backup_$(date +%Y%m%d_%H%M%S).log"

# Function to Backup DGraph Alpha and Zero Nodes
backup_dgraph_node() {
local host=$1
local port=$2

echo "$(date) - Starting backup for DGraph node at ${host}:${port}" >> "${LOG_FILE}"
# Replace with actual backup command for the node. Example:
# curl "http://${host}:${port}/admin/backup"
echo "$(date) - Backup completed for DGraph node at ${host}:${port}" >> "${LOG_FILE}"
}

# Function to Backup DGraph Directory
backup_dgraph_dir() {
local dir=$1
local dir_name=$(basename "$dir")
echo "Starting Dgraph database Backup..."
echo "$(date) - Starting backup for DGraph directory at $dir" >> "${LOG_FILE}"
tar -czvf "${BACKUP_PATH}/${dir_name}_$(date +%Y%m%d_%H%M%S).tar.gz" -C "$dir" .
echo "$(date) - Backup completed for DGraph directory at $dir" >> "${LOG_FILE}"
echo "Database Dgraph Backup completed."
}


# Backup DGraph Nodes (Alphas and Zeros)
IFS=',' read -r -a alpha_hosts <<< "$DGRAPH_ALPHA_HOSTS"
IFS=',' read -r -a alpha_ports <<< "$DGRAPH_ALPHA_PORTS"
IFS=',' read -r -a zero_hosts <<< "$DGRAPH_ZERO_HOSTS"
IFS=',' read -r -a zero_ports <<< "$DGRAPH_ZERO_PORTS"

for i in "${!alpha_hosts[@]}"; do
backup_dgraph_node "${alpha_hosts[i]}" "${alpha_ports[i]}"
done

for i in "${!zero_hosts[@]}"; do
backup_dgraph_node "${zero_hosts[i]}" "${zero_ports[i]}"
done

# Backup DGraph Directories
[ -d "$DATA_DGRAPH_ZERO_01_DIR" ] && backup_dgraph_dir "$DATA_DGRAPH_ZERO_01_DIR"
[ -d "$DATA_DGRAPH_ALPHA_01_DIR" ] && backup_dgraph_dir "$DATA_DGRAPH_ALPHA_01_DIR"
[ -d "$DATA_DGRAPH_ALPHA_02_DIR" ] && backup_dgraph_dir "$DATA_DGRAPH_ALPHA_02_DIR"
[ -d "$DATA_DGRAPH_ALPHA_03_DIR" ] && backup_dgraph_dir "$DATA_DGRAPH_ALPHA_03_DIR"

# Function to Copy Backup to Remote Server
copy_to_remote() {
if [ -n "${REMOTE_SERVER}" ] && [ -n "${REMOTE_PATH}" ]; then
echo "$(date) - Starting remote transfer" >> "${LOG_FILE}"
scp "${BACKUP_PATH}/*_$(date +%Y%m%d).tar.gz" ${REMOTE_SERVER}:${REMOTE_PATH}
echo "$(date) - Remote transfer completed" >> "${LOG_FILE}"
else
echo "$(date) - Remote server details not set. Skipping remote transfer." >> "${LOG_FILE}"
fi
}

# Main Execution
copy_to_remote
chmod -R 777 "$BACKUP_PATH"
87 changes: 87 additions & 0 deletions devops/windows/deployment/backup_restore/dgraph-restore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash
source ../conf.env
#Backup Folder Name
while true; do
# Ask the user to enter a folder name
echo "Backup folder Path:- ${DGRAPH_BACKUP_DIRECTORY}"
pushd ${DGRAPH_BACKUP_DIRECTORY}
echo
echo "Recent 5 Backups list"
ls -lt --time=creation --sort=time | grep '^d' | tail -n 5
echo
popd
read -p "Please enter your Dgraph Backup Folder Name: " BACKUP_FOLDER_NAME

# Check if the folder exists
if [ -d "${DGRAPH_BACKUP_DIRECTORY}/$BACKUP_FOLDER_NAME" ]; then
echo "Folder '$BACKUP_FOLDER_NAME' exists!"
break # Exit the loop if the folder exists
else
echo "Folder '$BACKUP_FOLDER_NAME' does not exist, at ${DGRAPH_BACKUP_DIRECTORY}. "
echo "Please try again"
fi
done

pushd ../deployment/reboot
source d-stack-3-reboot.sh
popd
echo "Please wait for sometime..."
sleep 60
# BACKUP_FOLDER_NAME="20240202_123952"
# Load Environment Variables for DGraph Alpha and Zero Nodes
DGRAPH_ALPHA_HOSTS="${DGRAPH_HOSTS:-localhost}"
DGRAPH_ALPHA_PORTS="${DGRAPH_PORTS:-8080}"
DGRAPH_ZERO_HOSTS="${DGRAPH_ZERO_HOSTS:-localhost}"
DGRAPH_ZERO_PORTS="${DGRAPH_ZERO_PORTS:-5080}"

# Load Environment Variables for Data Directories
DATA_DGRAPH_ZERO_01_DIR="${DATA_DGRAPH_ZERO_01_DIR}"
DATA_DGRAPH_ALPHA_01_DIR="${DATA_DGRAPH_ALPHA_01_DIR}"
DATA_DGRAPH_ALPHA_02_DIR="${DATA_DGRAPH_ALPHA_02_DIR:-}" # Optional
DATA_DGRAPH_ALPHA_03_DIR="${DATA_DGRAPH_ALPHA_03_DIR:-}" # Optional
BACKUP_PATH="${DGRAPH_BACKUP_DIRECTORY}/$BACKUP_FOLDER_NAME"

REMOTE_SERVER="${DGRAPH_BACKUP_REMOTE_SERVER:-""}"
REMOTE_PATH="${DGRAPH_BACKUP_REMOTE_PATH:-""}"
# Function to Restore DGraph Directory
restore_dgraph_dir() {
local dir=$1
local backup_file=$2
echo $dir
if [ "$(ls -A $dir)" ]; then
echo "Directory $dir is not empty. Clearing existing files."
sudo rm -rf $dir/*
fi

echo$(date) - Starting restore for DGraph directory at $dir from $backup_file
sudo tar -xzvf ${backup_file} -C $dir --strip-components=1
echo$(date) - Restore completed for DGraph directory at $dir
}
# Restore Zero Nodes
for backup_file in ${BACKUP_PATH}/zero*.tar.gz; do
echo $backup_file
# Assuming the first directory is for zero nodes
restore_dgraph_dir $DATA_DGRAPH_ZERO_01_DIR $backup_file
done
# Restore Alpha Nodes
for backup_file in ${BACKUP_PATH}/alpha*.tar.gz; do
# Assuming the first directory is for alpha nodes
restore_dgraph_dir $DATA_DGRAPH_ALPHA_01_DIR $backup_file
done

copy_from_remote() {
if [ -n "${REMOTE_SERVER}" ] && [ -n "${REMOTE_PATH}" ]; then
echo "$(date) - Starting remote copy"
scp ${REMOTE_SERVER}:${REMOTE_PATH}/*_$(date +%Y%m%d).tar.gz "${BACKUP_PATH}/"
echo "$(date) - Remote copy completed"
else
echo "$(date) - Remote server details not set. Skipping remote copy."
fi
}
# Main Execution
copy_from_remote
echo "Rebooting JeMPI"
pushd ../deployment/reboot
echo $PWD
source d-stack-3-reboot.sh
popd
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
source ../conf.env
# Load Backup Directory from Environment Variable
POSTGRES_BACKUP_PATH="${POSTGRES_BACKUP_DIRECTORY}"
OLD_LOGS_DIR="${BACKUP_PATH}/old_logs"

# Create Logrotate Configuration File
cat << EOF > /etc/logrotate.d/postgres-backup
$POSTGRES_BACKUP_PATH/backup_*.log {
rotate 30
daily
missingok
notifempty
compress
delaycompress
create 640 root adm
dateext
dateformat -%Y%m%d
olddir $OLD_LOGS_DIR
}
EOF

echo "Logrotate configuration for PostgreSQL backup updated."

DGRAPH_BACKUP_PATH="${DGRAPH_BACKUP_DIRECTORY}"
OLD_LOGS_DIR="${BACKUP_PATH}/old_logs"

# Create Logrotate Configuration File
cat << EOF > /etc/logrotate.d/dgraph-backup
$DGRAPH_BACKUP_PATH/backup_*.log {
rotate 30
daily
missingok
notifempty
compress
delaycompress
create 640 root adm
dateext
dateformat -%Y%m%d
olddir $OLD_LOGS_DIR
}
EOF

echo "Logrotate configuration for DGraph backup updated."
55 changes: 55 additions & 0 deletions devops/windows/deployment/backup_restore/postgres-backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
source ../../base-docker-wsl/conf.env
# Load Database Credentials from Environment Variables

DB_NAME="${POSTGRESQL_DATABASE}"
DB_USER="${POSTGRESQL_USERNAME}"
DB_PASSWORD="${POSTGRESQL_PASSWORD}"
DB_HOST="${POSTGRES_HOST:-localhost}"
BACKUP_PATH="${POSTGRES_BACKUP_DIRECTORY}/$(date +%Y%m%d_%H%M%S)"
OLD_LOGS_DIR="${BACKUP_PATH}/old_logs" # Directory to store old logs

databases=("$POSTGRESQL_DATABASE" "$POSTGRESQL_USERS_DB" "$POSTGRESQL_NOTIFICATIONS_DB" "$POSTGRESQL_AUDIT_DB" "$POSTGRESQL_KC_TEST_DB")

# Check and Create Backup Directory and Old Logs Directory
[ ! -d "$BACKUP_PATH" ] && mkdir -p "$BACKUP_PATH"
[ ! -d "$OLD_LOGS_DIR" ] && mkdir -p "$OLD_LOGS_DIR"

LOG_FILE="${BACKUP_PATH}/$(date +%Y%m%d_%H%M%S).log"

# Check for Remote Server Details
REMOTE_SERVER="${POSTGRES_BACKUP_REMOTE_SERVER}"
REMOTE_PATH="${POSTGRES_BACKUP_REMOTE_PATH}"
PGPORT="${PGPORT:-5432}"

# Function to Perform Backup
backup_database() {
echo "Starting Postgres database Backup..."
# Loop through each database and dump it
for db in "${databases[@]}"; do
echo "db.. $db "
backup_file="${BACKUP_PATH}/${db}--$(date +%Y%m%d_%H%M%S).sql"

echo "$(date) - Starting backup for database: ${db}" >> "${LOG_FILE}"
PGPASSWORD=$DB_PASSWORD pg_dump -h $DB_HOST -U $DB_USER -d $db -F c -f "${BACKUP_PATH}/${db}--$(date +%Y%m%d_%H%M%S).sql"
echo "$(date) - Backup completed for database: ${db}" >> "${LOG_FILE}"
done
echo "Database Postgres Backup completed."
}

echo Function to Copy Backup to Remote Server
copy_to_remote() {
if [ -n "${REMOTE_SERVER}" ] && [ -n "${REMOTE_PATH}" ]; then
for db in "${databases[@]}"; do
echo "$(date) - Starting remote transfer" >> "${LOG_FILE}"
scp "${BACKUP_PATH}/${db}_$(date +%Y%m%d_%H%M%S).sql" ${REMOTE_SERVER}:${REMOTE_PATH}
echo "$(date) - Remote transfer completed" >> "${LOG_FILE}"
done
else
echo "$(date) - Remote server details not set. Skipping remote transfer." >> "${LOG_FILE}"
fi
}

# # Main Execution
backup_database
copy_to_remote
Loading

0 comments on commit c8d500c

Please sign in to comment.