Add error handling and improve backup scripts for consistency
All checks were successful
Build a dev image / build (push) Successful in 6s
Release of a new version / build (release) Successful in 7s

This commit is contained in:
Adam Štrauch 2025-10-18 23:15:26 +02:00
parent 5bfbda5e5e
commit 2ab7be67fa
Signed by: cx
GPG key ID: 7262DAFE292BCE20
4 changed files with 12 additions and 4 deletions

View file

@ -5,6 +5,6 @@ RUN apk add --no-cache restic docker-cli docker-cli-compose curl zstd bash
COPY backup.sh /backup.sh
COPY backup_local.sh /backup_local.sh
COPY backup_restic.sh /backup_restic.sh
RUN chmod +x /backup.sh
RUN chmod +x /backup.sh /backup_local.sh /backup_restic.sh
ENTRYPOINT [ "/backup.sh" ]

View file

@ -1,5 +1,7 @@
#!/bin/bash
set -e
if [ "$1" = "local" ]; then
source /backup_local.sh
elif [ "$1" = "restic" ]; then

View file

@ -1,5 +1,7 @@
#!/bin/bash
set -e
# Environment variables
#
# CONTAINER - name of the container where the database is running
@ -31,8 +33,9 @@ fi
echo "Starting backup for container: $CONTAINER"
if [ `docker exec -i $CONTAINER test -e /usr/bin/mariadb-dump && echo "yes" || echo "no"` = "yes" ]; then
DBTYPE="mariadb"
FILENAME=`date +"%Y%m%d_%H%M%S"`_$DBTYPE_$CONTAINER_$DB_NAME.sql.zst.tmp
FILENAME=`date +"%Y%m%d_%H%M%S"`_$DBTYPE_$CONTAINER_$DB_NAME.sql.zst
docker exec -i $CONTAINER mariadb-dump \
--all-databases \
--user=root \
--password=$MARIADB_ROOT_PASSWORD \
--add-drop-trigger \
@ -43,8 +46,8 @@ if [ `docker exec -i $CONTAINER test -e /usr/bin/mariadb-dump && echo "yes" || e
--events \
--routines \
--single-transaction \
--triggers | zstd -1 > $TARGET_DIR/
mv $TARGET_DIR/$DBTYPE_$CONTAINER_$DB_NAME.sql.zst.tmp $TARGET_DIR/$DBTYPE_$CONTAINER_$DB_NAME.sql.zst
--triggers | zstd -1 > $TARGET_DIR/$FILENAME.tmp
mv $TARGET_DIR/$FILENAME.tmp $TARGET_DIR/$FILENAME
elif [ `docker exec -i $CONTAINER test -e /usr/bin/pg_dump && echo "yes" || echo "no"` = "yes" ]; then
DBTYPE="pgsql"
FILENAME=`date +"%Y%m%d_%H%M%S"`_$DBTYPE_$CONTAINER_$DB_NAME.sql.zst

View file

@ -1,5 +1,7 @@
#!/bin/bash
set -e
# Environment variables
#
# CONTAINER - name of the container where the database is running
@ -32,6 +34,7 @@ echo "Starting backup for container: $CONTAINER"
if [ `docker exec -i $CONTAINER test -e /usr/bin/mariadb-dump && echo "yes" || echo "no"` = "yes" ]; then
DBTYPE="mariadb"
docker exec -i $CONTAINER mariadb-dump \
--all-databases \
--user=root \
--password=$MARIADB_ROOT_PASSWORD \
--add-drop-trigger \