feat: add database backup verification

This commit is contained in:
2024-01-11 19:46:29 +01:00
parent 3d885bfb44
commit 5f048cdf83
5 changed files with 15 additions and 9 deletions

View File

@@ -32,7 +32,7 @@ jobs:
uses: docker/build-push-action@v3
with:
push: true
file: "./src/docker/Dockerfile"
file: "./src/Dockerfile"
platforms: linux/amd64,linux/arm64
tags: |
"${{env.BUILDKIT_IMAGE}}:v0.2"

View File

@@ -6,6 +6,6 @@ if [ $# -eq 0 ]
tag=$1
fi
docker build -f src/docker/Dockerfile -t jkaninda/pg-bkup:$tag .
docker build -f src/Dockerfile -t jkaninda/pg-bkup:$tag .
docker compose up -d
#docker compose up -d

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module github.com/jkaninda/pg-bkup
go 1.20

View File

@@ -13,7 +13,6 @@ ARG DEBIAN_FRONTEND=noninteractive
ENV VERSION="0.2"
RUN apt-get update -qq
RUN apt-get install build-essential libcurl4-openssl-dev libxml2-dev mime-support -y
RUN apt install s3fs postgresql-client postgresql-client-common libpq-dev supervisor cron -y
# Clear cache

View File

@@ -155,11 +155,15 @@ else
export PGPASSWORD=${DB_PASSWORD}
## Test database connection
export BK_FILE_NAME="${DB_NAME}_${TIME}.sql.gz"
## Backup database
pg_dump -h ${DB_HOST} -p ${DB_PORT} -U ${DB_USERNAME} -d ${DB_NAME} | gzip > ${STORAGE_PATH}/${DB_NAME}_${TIME}.sql.gz
echo "$TIME: ${DB_NAME}_${TIME}.sql.gz" | tee -a "${STORAGE_PATH}/history.txt"
info "Database has been saved"
pg_dump -h ${DB_HOST} -p ${DB_PORT} -U ${DB_USERNAME} -d ${DB_NAME} | gzip > ${STORAGE_PATH}/$BK_FILE_NAME
if [[ $? -eq 0 ]];then
echo $BK_FILE_NAME | tee -a "${STORAGE_PATH}/history.txt"
info "Database has been backed up"
else
fatal "An error occurred during the backup"
fi
fi
exit 0
}
@@ -266,7 +270,7 @@ scheduled_mode()
}
flags "$@"
# ?
if [ $EXECUTION_MODE == 'default' ]
then
if [ $OPERATION != 'backup' ]