From fc21306f6ed6e960a58c0ceab62bec37a235df43 Mon Sep 17 00:00:00 2001 From: Praveen Date: Thu, 14 Nov 2024 18:28:45 +0530 Subject: [PATCH 1/2] Adding Sentry --- application/backup.sh | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/application/backup.sh b/application/backup.sh index a3b497a..956b54c 100755 --- a/application/backup.sh +++ b/application/backup.sh @@ -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 @@ -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)." @@ -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." @@ -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." @@ -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." From 009371797cb89f3813bb6b586ee1c52a060ef224 Mon Sep 17 00:00:00 2001 From: Praveen Date: Thu, 21 Nov 2024 19:49:06 +0530 Subject: [PATCH 2/2] Removed the data-image --- docker-compose.yml | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 075b007..2d53f72 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: @@ -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: @@ -41,8 +36,8 @@ services: backup: build: ./ - volumes_from: - - data + volumes: + - ./application:/data env_file: - ./local.env environment: