Skip to content

Commit

Permalink
feat: add backup files - tmp - wip
Browse files Browse the repository at this point in the history
issue #1268
  • Loading branch information
Ricardo Campos committed Aug 12, 2024
1 parent 493f4a8 commit 6c7ab20
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
14 changes: 14 additions & 0 deletions backup/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM postgis/postgis:15-master

# Enable pgcrypto extension on startup
RUN sed -i '/EXISTS postgis_tiger_geocoder;*/a CREATE EXTENSION IF NOT EXISTS pgcrypto;' \
/docker-entrypoint-initdb.d/10_postgis.sh

WORKDIR /app
COPY pg-simple-backup.sh .

RUN mkdir /mnt/bkp

# User, port and Healthcheck
#USER postgres
ENTRYPOINT [ "/app/pg-simple-backup.sh", "$${POSTGRES_USER}", "$${POSTGRES_DB}", "15432" ]
6 changes: 6 additions & 0 deletions backup/help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
docker build -t backup .

docker run -it \
--network=host \
-v .:/mnt/bkp \
backup
31 changes: 31 additions & 0 deletions backup/pg-simple-backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# -*- coding: utf-8 -*-

##
# DB access
##
DB_USER="nr-spar"
DB_NAME="nr-spar"
DB_PORT="15432"
echo "User=$DB_USER"
echo "DB=$DB_NAME"
echo "Port=$DB_PORT"

##
# File name
##
FILENAME_PREFIX="spar_pg_bkp"

# %F -> 2024-08-12
# %T -> 16:44:58
# Here for more: https://www.man7.org/linux/man-pages/man1/date.1.html
FILENAME_SUFIX=$(date +"%F_%T")
FILENAME=$FILENAME_PREFIX"_"$FILENAME_SUFIX
echo "Filename=$FILENAME"

# -F specifies that the output should be in tar format
PG_DUMP="pg_dump"
COMM="$PG_DUMP -U \"$DB_USER\" -W -F t \"$DB_NAME\" > /mnt/bkp/$FILENAME.tar"
echo "Command=$COMM"

pg_dump -h localhost -p $DB_PORT -U "$DB_USER" -W -F t "$DB_NAME" > /mnt/bkp/$FILENAME.tar

0 comments on commit 6c7ab20

Please sign in to comment.