Skip to content

Commit

Permalink
Merge pull request #16 from silinternational/feature-data-img
Browse files Browse the repository at this point in the history
Feature data img
  • Loading branch information
Praveenraj-K authored Nov 22, 2024
2 parents 78b3459 + 0093717 commit 2c8ef7d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
39 changes: 34 additions & 5 deletions application/backup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
#!/usr/bin/env sh
#!/usr/bin/env bash

# Function to send error to Sentry
send_error_to_sentry() {
local error_message="$1"
local db_name="$2"
local status_code="$3"

if [ -n "${SENTRY_DSN}" ]; then
wget -q --header="Content-Type: application/json" \
--post-data="{
\"message\": \"${error_message}\",
\"level\": \"error\",
\"extra\": {
\"database\": \"${db_name}\",
\"status_code\": \"${status_code}\",
\"hostname\": \"$(hostname)\"
}
}" \
-O - "${SENTRY_DSN}"
fi
}

MYNAME="postgresql-backup-restore"
STATUS=0
Expand All @@ -12,7 +33,9 @@ $(PGPASSWORD=${DB_USERPASSWORD} pg_dump --host=${DB_HOST} --username=${DB_USER}
end=$(date +%s)

if [ $STATUS -ne 0 ]; then
echo "${MYNAME}: FATAL: Backup of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
error_message="${MYNAME}: FATAL: Backup of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
echo "${error_message}"
send_error_to_sentry "${error_message}" "${STATUS}" "${DB_NAME}"
exit $STATUS
else
echo "${MYNAME}: Backup of ${DB_NAME} completed in $(expr ${end} - ${start}) seconds, ($(stat -c %s /tmp/${DB_NAME}.sql) bytes)."
Expand All @@ -23,7 +46,9 @@ gzip -f /tmp/${DB_NAME}.sql || STATUS=$?
end=$(date +%s)

if [ $STATUS -ne 0 ]; then
echo "${MYNAME}: FATAL: Compressing backup of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
error_message="${MYNAME}: FATAL: Compressing backup of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
echo "${error_message}"
send_error_to_sentry "${error_message}" "${STATUS}" "${DB_NAME}"
exit $STATUS
else
echo "${MYNAME}: Compressing backup of ${DB_NAME} completed in $(expr ${end} - ${start}) seconds."
Expand All @@ -34,7 +59,9 @@ s3cmd put /tmp/${DB_NAME}.sql.gz ${S3_BUCKET} || STATUS=$?
end=$(date +%s)

if [ $STATUS -ne 0 ]; then
echo "${MYNAME}: FATAL: Copy backup to ${S3_BUCKET} of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
error_message="${MYNAME}: FATAL: Copy backup to ${S3_BUCKET} of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
echo "${error_message}"
send_error_to_sentry "${error_message}" "${STATUS}" "${DB_NAME}"
exit $STATUS
else
echo "${MYNAME}: Copy backup to ${S3_BUCKET} of ${DB_NAME} completed in $(expr ${end} - ${start}) seconds."
Expand All @@ -51,7 +78,9 @@ if [ "${B2_BUCKET}" != "" ]; then
STATUS=$?
end=$(date +%s)
if [ $STATUS -ne 0 ]; then
echo "${MYNAME}: FATAL: Copy backup to Backblaze B2 bucket ${B2_BUCKET} of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
error_message="${MYNAME}: FATAL: Copy backup to Backblaze B2 bucket ${B2_BUCKET} of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
echo "${error_message}"
send_error_to_sentry "${error_message}" "${STATUS}"
exit $STATUS
else
echo "${MYNAME}: Copy backup to Backblaze B2 bucket ${B2_BUCKET} of ${DB_NAME} completed in $(expr ${end} - ${start}) seconds."
Expand Down
17 changes: 6 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
services:
data:
image: silintl/data-volume:latest
volumes:
- ./application:/data

# See https://hub.docker.com/_/postgres/ for details of the postgres image.
# POSTGRES_PASSWORD - superuser password for PostgreSQL
# POSTGRES_USER - superuser (default is 'postgres')
# POSTGRES_DB - name of default database (default is value of POSTGRES_USER)
db:
image: postgres:14.11-alpine3.19
volumes_from:
- data
volumes:
- ./application:/data
ports:
- "5432"
environment:
Expand All @@ -25,8 +20,8 @@ services:
# DB_NAME - name of database to back up/restore
restore:
build: ./
volumes_from:
- data
volumes:
- ./application:/data
env_file:
- ./local.env
environment:
Expand All @@ -41,8 +36,8 @@ services:

backup:
build: ./
volumes_from:
- data
volumes:
- ./application:/data
env_file:
- ./local.env
environment:
Expand Down

0 comments on commit 2c8ef7d

Please sign in to comment.