Skip to content

Commit 2c8ef7d

Browse files
authored
Merge pull request #16 from silinternational/feature-data-img
Feature data img
2 parents 78b3459 + 0093717 commit 2c8ef7d

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

application/backup.sh

+34-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
#!/usr/bin/env sh
1+
#!/usr/bin/env bash
2+
3+
# Function to send error to Sentry
4+
send_error_to_sentry() {
5+
local error_message="$1"
6+
local db_name="$2"
7+
local status_code="$3"
8+
9+
if [ -n "${SENTRY_DSN}" ]; then
10+
wget -q --header="Content-Type: application/json" \
11+
--post-data="{
12+
\"message\": \"${error_message}\",
13+
\"level\": \"error\",
14+
\"extra\": {
15+
\"database\": \"${db_name}\",
16+
\"status_code\": \"${status_code}\",
17+
\"hostname\": \"$(hostname)\"
18+
}
19+
}" \
20+
-O - "${SENTRY_DSN}"
21+
fi
22+
}
223

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

1435
if [ $STATUS -ne 0 ]; then
15-
echo "${MYNAME}: FATAL: Backup of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
36+
error_message="${MYNAME}: FATAL: Backup of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
37+
echo "${error_message}"
38+
send_error_to_sentry "${error_message}" "${STATUS}" "${DB_NAME}"
1639
exit $STATUS
1740
else
1841
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=$?
2346
end=$(date +%s)
2447

2548
if [ $STATUS -ne 0 ]; then
26-
echo "${MYNAME}: FATAL: Compressing backup of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
49+
error_message="${MYNAME}: FATAL: Compressing backup of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
50+
echo "${error_message}"
51+
send_error_to_sentry "${error_message}" "${STATUS}" "${DB_NAME}"
2752
exit $STATUS
2853
else
2954
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=$?
3459
end=$(date +%s)
3560

3661
if [ $STATUS -ne 0 ]; then
37-
echo "${MYNAME}: FATAL: Copy backup to ${S3_BUCKET} of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
62+
error_message="${MYNAME}: FATAL: Copy backup to ${S3_BUCKET} of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
63+
echo "${error_message}"
64+
send_error_to_sentry "${error_message}" "${STATUS}" "${DB_NAME}"
3865
exit $STATUS
3966
else
4067
echo "${MYNAME}: Copy backup to ${S3_BUCKET} of ${DB_NAME} completed in $(expr ${end} - ${start}) seconds."
@@ -51,7 +78,9 @@ if [ "${B2_BUCKET}" != "" ]; then
5178
STATUS=$?
5279
end=$(date +%s)
5380
if [ $STATUS -ne 0 ]; then
54-
echo "${MYNAME}: FATAL: Copy backup to Backblaze B2 bucket ${B2_BUCKET} of ${DB_NAME} returned non-zero status ($STATUS) in $(expr ${end} - ${start}) seconds."
81+
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."
82+
echo "${error_message}"
83+
send_error_to_sentry "${error_message}" "${STATUS}"
5584
exit $STATUS
5685
else
5786
echo "${MYNAME}: Copy backup to Backblaze B2 bucket ${B2_BUCKET} of ${DB_NAME} completed in $(expr ${end} - ${start}) seconds."

docker-compose.yml

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
services:
2-
data:
3-
image: silintl/data-volume:latest
4-
volumes:
5-
- ./application:/data
6-
72
# See https://hub.docker.com/_/postgres/ for details of the postgres image.
83
# POSTGRES_PASSWORD - superuser password for PostgreSQL
94
# POSTGRES_USER - superuser (default is 'postgres')
105
# POSTGRES_DB - name of default database (default is value of POSTGRES_USER)
116
db:
127
image: postgres:14.11-alpine3.19
13-
volumes_from:
14-
- data
8+
volumes:
9+
- ./application:/data
1510
ports:
1611
- "5432"
1712
environment:
@@ -25,8 +20,8 @@ services:
2520
# DB_NAME - name of database to back up/restore
2621
restore:
2722
build: ./
28-
volumes_from:
29-
- data
23+
volumes:
24+
- ./application:/data
3025
env_file:
3126
- ./local.env
3227
environment:
@@ -41,8 +36,8 @@ services:
4136

4237
backup:
4338
build: ./
44-
volumes_from:
45-
- data
39+
volumes:
40+
- ./application:/data
4641
env_file:
4742
- ./local.env
4843
environment:

0 commit comments

Comments
 (0)