added db dump restoration

This commit is contained in:
julien 2025-03-06 11:54:20 +01:00
parent a8802db99b
commit 338655642a
2 changed files with 14 additions and 5 deletions

View File

@ -11,7 +11,7 @@ if [ -d "volumes" ]; then
DB_USER=$(nerdctl exec $CONTAINER_NAME bash -c 'echo "$MYSQL_USER"')
DB_PASSWORD=$(nerdctl exec $CONTAINER_NAME bash -c 'echo "$MYSQL_PASSWORD"')
DB_NAME=$(nerdctl exec $CONTAINER_NAME bash -c 'echo "$MYSQL_DATABASE"')
DUMP_NAME=$CONTAINER_NAME.sql
DUMP_NAME=datadump.sql
nerdctl exec -e MYSQL_PWD=$DB_PASSWORD $CONTAINER_NAME mariadb-dump -u $DB_USER $DB_NAME > volumes/$DUMP_NAME
fi
@ -21,7 +21,7 @@ if [ -d "volumes" ]; then
DB_USER=$(nerdctl exec $CONTAINER_NAME bash -c 'echo "$POSTGRES_USER"')
DB_PASSWORD=$(nerdctl exec $CONTAINER_NAME bash -c 'echo "$POSTGRES_PASSWORD"')
DB_NAME=$(nerdctl exec $CONTAINER_NAME bash -c 'echo "$POSTGRES_DATABASE"')
DUMP_NAME=$CONTAINER_NAME.sql
DUMP_NAME=datadump.sql
nerdctl exec -e PGPASSWORD=$DB_PASSWORD $CONTAINER_NAME pg_dump -U $DB_USER $DB_NAME > volumes/$DUMP_NAME
fi

View File

@ -5,6 +5,7 @@
# The backup have to be in the same directory.
#
# Extract the archive into volumes directory
BACKUP=${PWD##*/}.tar.zst
if [ -d "volumes" ]; then
rm -r volumes
@ -12,6 +13,14 @@ fi
mkdir volumes
tar --zstd --same-owner -xvf $BACKUP -C volumes
# Todo :
# Import .sql if there
# rm volumes/*.sql
# Start the service and populate db from sql file if needed
if [ -f "compose.db-restore.yml" ]
then
nerdctl compose -f compose.yml -f compose.db-restore.yml up -d
else
nerdctl compose up -d
fi
# Clean backup files
rm $BACKUP
rm volumes/*.sql