Skip to content

Commit

Permalink
Merge pull request #7 from shikharish/dob-backup
Browse files Browse the repository at this point in the history
Backup
  • Loading branch information
proffapt authored Aug 13, 2024
2 parents b298a39 + f40482d commit daf13fe
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 56 deletions.
2 changes: 0 additions & 2 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ DATABASE_PORT=5432
DATABASE_NAME=databaseofbabel
DATABASE_USERNAME=metakgp_user
DATABASE_PASSWORD=somerandomstringfordevelopment
# Path to secret file containing database access information(username, password, etc.)
DBPASSFILE=
# Dropbox api variables(used for storing backups)
DROPBOX_APP_KEY=
DROPBOX_APP_SECRET=
Expand Down
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
FROM postgres:16

RUN apt-get update && apt-get install -y curl python3 python3-pip gzip

WORKDIR /backup

COPY ./backup .

RUN pip3 install -qr requirements.txt --break-system-packages
28 changes: 0 additions & 28 deletions backup/Dockerfile

This file was deleted.

1 change: 0 additions & 1 deletion backup/crontab

This file was deleted.

12 changes: 6 additions & 6 deletions backup/run_backup.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env bash

echo -e "\n-- Database of Babel Backup and Rotation START --\n"
echo -e "\n-- Backup and Rotation started at `date +"%Y/%m/%d %H:%M:%S"` --\n"

timestamp=$(date +%Y_%m_%d_%H_%M_%S)
backup_to_dropbox="python3 /root/backup/backup_to_dropbox.py"
rotate_backup="python3 /root/backup/rotate_backups.py"
backups_dir="/root/backup/backups"
backup_to_dropbox="python3 /backup/backup_to_dropbox.py"
rotate_backup="python3 /backup/rotate_backups.py"
backups_dir="/backup/backups"
dump_file="dob_dump_$timestamp.sql"
backup_file="$dump_file.gz"

mkdir -p "${backups_dir}"
cd "$backups_dir"

if ! pg_dumpall -U $POSTGRES_USER --no-password >$dump_file; then
if ! PGPASSWORD=$POSTGRES_PASSWORD pg_dumpall -U $POSTGRES_USER >$dump_file; then
echo "pgdump failure!"
exit 1
fi
Expand Down Expand Up @@ -50,4 +50,4 @@ if ! $backup_to_dropbox $backup_file; then
exit 1
fi

echo -e "\n-- Database of Babel Backup and Rotation END --\n"
echo -e "\n-- Backup and Rotation finished at `date +"%Y/%m/%d %H:%M:%S"` --\n"
29 changes: 10 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,23 @@ services:
- POSTGRES_DB=${DATABASE_NAME}
- PGPORT=${DATABASE_PORT}
- PGHOST=${DATABASE_HOST}
volumes:
- db-volume:/var/lib/postgresql/data
restart: always

backup:
build:
context: ./
dockerfile: ./backup/Dockerfile
args:
- DBPASSFILE=${DBPASSFILE}
restart: always
networks:
metaploy-private-network:
depends_on:
- database
environment:
- PGHOST=database
- POSTGRES_USER=${DATABASE_USERNAME}
- PGPASSFILE=/root/.pgpass
- DROPBOX_APP_KEY=${DROPBOX_APP_KEY}
- DROPBOX_APP_SECRET=${DROPBOX_APP_SECRET}
- DROPBOX_ACCESS_TOKEN=${DROPBOX_ACCESS_TOKEN}
- DROPBOX_REFRESH_TOKEN=${DROPBOX_REFRESH_TOKEN}
- SLACK_INCIDENTS_WH_URL=${SLACK_INCIDENTS_WH_URL}
volumes:
- db-volume:/var/lib/postgresql/data
healthcheck:
test:
[
"CMD-SHELL",
"/backup/run_backup.sh >> /var/log/pg_dump.log 2>&1 || exit 1",
]
interval: 24h
timeout: 2m
retries: 5
restart: always

networks:
metaploy-private-network:
Expand Down

0 comments on commit daf13fe

Please sign in to comment.