feat: add database backup verification

This commit is contained in:
2024-01-11 19:38:13 +01:00
parent bcfc69e7f9
commit 2a8ad3a6e2
6 changed files with 22 additions and 12 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

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

View File

@@ -6,6 +6,6 @@ if [ $# -eq 0 ]
tag=$1 tag=$1
fi fi
docker build -f src/docker/Dockerfile -t jkaninda/mysql-bkup:$tag . docker build -f src/Dockerfile -t jkaninda/mysql-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/mysql-bkup
go 1.20

View File

@@ -13,7 +13,7 @@ ARG DEBIAN_FRONTEND=noninteractive
ENV VERSION="v0.3" ENV VERSION="v0.3"
RUN apt-get update -qq RUN apt-get update -qq
RUN apt-get install build-essential libcurl4-openssl-dev libxml2-dev mime-support -y #RUN apt-get install build-essential libcurl4-openssl-dev libxml2-dev mime-support -y
RUN apt install s3fs mysql-client supervisor cron -y RUN apt install s3fs mysql-client supervisor cron -y
# Clear cache # Clear cache
@@ -34,4 +34,3 @@ RUN ln -s /usr/local/bin/mysql_bkup.sh /usr/local/bin/bkup
RUN mkdir /backup RUN mkdir /backup
WORKDIR /backup WORKDIR /backup
#VOLUME /backup

View File

@@ -18,7 +18,7 @@ export S3_PATH=/mysql-bkup
export TIMEOUT=60 export TIMEOUT=60
export EXECUTION_MODE="default" export EXECUTION_MODE="default"
export SCHEDULE_PERIOD="0 1 * * *" export SCHEDULE_PERIOD="0 1 * * *"
export FILE_COMPRESION=true export DISABLE_COMPRESION=false
usage_info() usage_info()
{ {
echo "Usage: \\" echo "Usage: \\"
@@ -131,6 +131,11 @@ flags()
[ $# = 0 ] && error "No timeout specified" [ $# = 0 ] && error "No timeout specified"
export TIMEOUT="$1" export TIMEOUT="$1"
shift;; shift;;
(--disable-compression)
shift
[ $# = 0 ] && error "No disable-compression specified"
export DISABLE_COMPRESION="$1"
shift;;
(-h|--help) (-h|--help)
help;; help;;
(-V|--version) (-V|--version)
@@ -149,12 +154,15 @@ backup()
else else
## Test database connection ## Test database connection
test_database_connection test_database_connection
##mysql -h ${DB_HOST} -P ${DB_PORT} -u ${DB_USERNAME} --password=${DB_PASSWORD} ${DB_NAME} -e"quit"
## Backup database ## Backup database
mysqldump -h ${DB_HOST} -P ${DB_PORT} -u ${DB_USERNAME} --password=${DB_PASSWORD} ${DB_NAME} | gzip > ${STORAGE_PATH}/${DB_NAME}_${TIME}.sql.gz export BK_FILE_NAME="${DB_NAME}_${TIME}.sql.gz"
echo "$TIME: ${DB_NAME}_${TIME}.sql.gz" | tee -a "${STORAGE_PATH}/history.txt" mysqldump -h ${DB_HOST} -P ${DB_PORT} -u ${DB_USERNAME} --password=${DB_PASSWORD} ${DB_NAME} | gzip > ${STORAGE_PATH}/$BK_FILE_NAME
info "Database has been saved" 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 fi
exit 0 exit 0
} }