From 338655642ac78f28b882d298177a12dfec3d495f Mon Sep 17 00:00:00 2001 From: julien Date: Thu, 6 Mar 2025 11:54:20 +0100 Subject: [PATCH] added db dump restoration --- bin/vol-backup.sh | 4 ++-- bin/vol-restore.sh | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bin/vol-backup.sh b/bin/vol-backup.sh index 9c48f68..65b0608 100755 --- a/bin/vol-backup.sh +++ b/bin/vol-backup.sh @@ -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 diff --git a/bin/vol-restore.sh b/bin/vol-restore.sh index 43cb280..ab965b0 100755 --- a/bin/vol-restore.sh +++ b/bin/vol-restore.sh @@ -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 \ No newline at end of file +# 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