Skip to content

Commit

Permalink
changed to GET request to Kuma EP
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinholz committed Oct 7, 2024
1 parent ddd8f51 commit 03375b5
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 22 deletions.
16 changes: 12 additions & 4 deletions backup/notify_uptime_kuma.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#!/bin/bash

KUMA_STATUS_ENDPOINT=${KUMA_STATUS_ENDPOINT}
# Set KUMA_STATUS_ENDPOINT variable from environment or default to empty string
KUMA_STATUS_ENDPOINT=${KUMA_STATUS_ENDPOINT:-}

if [ -z "$KUMA_STATUS_ENDPOINT" ]; then
echo "KUMA_STATUS_ENDPOINT is not set. Skipping."
echo "Error: KUMA_STATUS_ENDPOINT is not set. Skipping."
else
curl -X POST \\
$KUMA_STATUS_ENDPOINT
# Use curl to make a GET request to the status endpoint
response=$(curl -s -X GET "$KUMA_STATUS_ENDPOINT")

# Check if the request was successful
if [ $? -eq 0 ]; then
echo "Status endpoint responded successfully: $response"
else
echo "Error: Failed to push status from $KUMA_STATUS_ENDPOINT. Status code: $?"
fi
fi
Empty file modified backup/rotate_backup.sh
100644 → 100755
Empty file.
Empty file modified mongodb/install-packages.sh
100644 → 100755
Empty file.
6 changes: 4 additions & 2 deletions mongodb/mongodb-backup.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ if [ ! -s "$FILE" ] || [ $(stat -c%s "$FILE") -lt $MIN_SIZE ]; then
exit 1
fi

/notify_uptime_kuma.sh || log "Failed to send notification"

# Send a notification using the notify_uptime_kuma.sh script
if ! ./notify_uptime_kuma.sh; then
log "Failed to send notification"
fi
log "Backup completed successfully"
Empty file modified mysql/install-packages.sh
100644 → 100755
Empty file.
6 changes: 4 additions & 2 deletions mysql/mysql-backup.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ if [ ! -s "$FILE" ] || [ $(stat -c%s "$FILE") -lt $MIN_SIZE ]; then
exit 1
fi

/notify_uptime_kuma.sh || log "Failed to send notification"

# Send a notification using the notify_uptime_kuma.sh script
if ! ./notify_uptime_kuma.sh; then
log "Failed to send notification"
fi
log "Backup completed successfully"
Empty file modified postgresql/install-packages.sh
100644 → 100755
Empty file.
48 changes: 40 additions & 8 deletions postgresql/postgresql-backup.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,22 +1,51 @@
#!/bin/sh

# Define a logging function
log() {
echo "[$(date +"%Y-%m-%d %H:%M:%S")] - $1"
}

# Set up an error trap to exit the script on any error
trap 'log "Error occurred, exiting script"; exit 1' ERR

touch ~/.pgpass
log "Creating ~/.pgpass file"
echo ${POSTGRES_HOST}:${POSTGRES_PORT}:${POSTGRES_DB}:${POSTGRES_USER}:${POSTGRES_PASSWORD} > ~/.pgpass
chmod 600 ~/.pgpass
# Create the ~/.pgpass file if it doesn't exist
if [ ! -f "~/.pgpass" ]; then
touch ~/.pgpass
log "Created ~/.pgpass file"
fi

# Set the PostgreSQL connection details as environment variables
POSTGRES_HOST=${POSTGRES_HOST:-}
POSTGRES_PORT=${POSTGRES_PORT:-5432} # default to 5432 if not set
POSTGRES_DB=${POSTGRES_DB:-}
POSTGRES_USER=${POSTGRES_USER:-}
POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-}

# Check that all required environment variables are set
if [ -z "$POSTGRES_HOST" ] || [ -z "$POSTGRES_DB" ] || [ -z "$POSTGRES_USER" ] || [ -z "$POSTGRES_PASSWORD" ]; then
log "Error: Missing PostgreSQL connection details, exiting script"
exit 1
fi

# Set the PGPASSFILE environment variable to point to the ~/.pgpass file
export PGPASSFILE='/root/.pgpass'

# Write the PostgreSQL connection details to the ~/.pgpass file
echo "${POSTGRES_HOST}:${POSTGRES_PORT}:${POSTGRES_DB}:${POSTGRES_USER}:${POSTGRES_PASSWORD}" > ~/.pgpass

# Set permissions on the ~/.pgpass file
chmod 600 ~/.pgpass

# Create a timestamp for the backup file name
NOW=$(date '+%y-%m-%d-%H%M')
FILE=/etc/backup/${POSTGRES_DB}-${NOW}.dump.gz
log "Create Backup $FILE"

pg_dump -h ${POSTGRES_HOST} -U ${POSTGRES_USER} ${POSTGRES_DB} -Z 9 > $FILE
# Define the backup file path and name
FILE="/etc/backup/${POSTGRES_DB}-${NOW}.dump.gz"

log "Creating Backup $FILE"

# Perform the PostgreSQL database dump
pg_dump -h "${POSTGRES_HOST}" -U "${POSTGRES_USER}" "${POSTGRES_DB}" -Z 9 > "$FILE"

# Check if the backup file is not empty and has a reasonable size
MIN_SIZE=$((1024 * 10)) # 10KB minimum size
Expand All @@ -25,6 +54,9 @@ if [ ! -s "$FILE" ] || [ $(stat -c%s "$FILE") -lt $MIN_SIZE ]; then
exit 1
fi

/notify_uptime_kuma.sh || log "Failed to send notification"
# Send a notification using the notify_uptime_kuma.sh script
if ! ./notify_uptime_kuma.sh; then
log "Failed to send notification"
fi

log "Backup completed successfully"
Empty file modified postgresql/postgresql-cron
100644 → 100755
Empty file.
Empty file modified prepare-cron.sh
100644 → 100755
Empty file.
6 changes: 5 additions & 1 deletion s3/s3_backup.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,8 @@ find "$S3_CONFIGS_PATH" -type f -name "*.cfg" | while read -r env_data; do
rm -f "$tmp_conf"
done

/notify_uptime_kuma.sh || log "Failed to send notification"

# Send a notification using the s3_notify_uptime_kuma.sh script
if ! ./s3_notify_uptime_kuma.sh; then
log "Failed to send notification"
fi
Empty file modified s3/s3_backup_rotation.sh
100644 → 100755
Empty file.
19 changes: 14 additions & 5 deletions s3/s3_notify_uptime_kuma.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
#!/bin/bash

S3_KUMA_STATUS_ENDPOINT=${S3_KUMA_STATUS_ENDPOINT}
# Set S3_KUMA_STATUS_ENDPOINT variable from environment or default to empty string
S3_KUMA_STATUS_ENDPOINT=${S3_KUMA_STATUS_ENDPOINT:-}

if [ -z "$KUMA_STATUS_ENDPOINT" ]; then
echo "S3_KUMA_STATUS_ENDPOINT is not set. Skipping."
if [ -z "$S3_KUMA_STATUS_ENDPOINT" ]; then
echo "Error: S3_KUMA_STATUS_ENDPOINT is not set. Skipping."
else
curl -X POST \\
$S3_KUMA_STATUS_ENDPOINT
# Use curl to make a POST request to the status endpoint
response=$(curl -s -X POST \\
"$S3_KUMA_STATUS_ENDPOINT")

# Check if the request was successful
if [ $? -eq 0 ]; then
echo "Status endpoint responded successfully: $response"
else
echo "Error: Failed to send status update to $S3_KUMA_STATUS_ENDPOINT. Status code: $?"
fi
fi

0 comments on commit 03375b5

Please sign in to comment.