docker instead of nerdctl and minor changes

This commit is contained in:
julien
2025-10-07 13:20:09 +02:00
parent 338655642a
commit 0b5644d59e
5 changed files with 14 additions and 17 deletions

43
scripts/vol-backup Executable file
View File

@@ -0,0 +1,43 @@
#!/bin/bash
#
# Run this script as root inside a service directory.
#
if [ -d "volumes" ]; then
# Dump mysql
if [ -d "volumes/mysql" ]; then
CONTAINER_NAME=$(echo ${PWD##*/} | sed -e 's/\.//g')_mariadb
DB_USER=$(docker exec $CONTAINER_NAME bash -c 'echo "$MYSQL_USER"')
DB_PASSWORD=$(docker exec $CONTAINER_NAME bash -c 'echo "$MYSQL_PASSWORD"')
DB_NAME=$(docker exec $CONTAINER_NAME bash -c 'echo "$MYSQL_DATABASE"')
DUMP_NAME=datadump.sql
docker exec -e MYSQL_PWD=$DB_PASSWORD $CONTAINER_NAME mariadb-dump -u $DB_USER $DB_NAME > volumes/$DUMP_NAME
fi
# Dump postgres
if [ -d "volumes/postgres" ]; then
CONTAINER_NAME=$(echo ${PWD##*/} | sed -e 's/\.//g')_postgres
DB_USER=$(docker exec $CONTAINER_NAME bash -c 'echo "$POSTGRES_USER"')
DB_PASSWORD=$(docker exec $CONTAINER_NAME bash -c 'echo "$POSTGRES_PASSWORD"')
DB_NAME=$(docker exec $CONTAINER_NAME bash -c 'echo "$POSTGRES_DATABASE"')
DUMP_NAME=datadump.sql
docker exec -e PGPASSWORD=$DB_PASSWORD $CONTAINER_NAME pg_dump -U $DB_USER $DB_NAME > volumes/$DUMP_NAME
fi
# Compress all volumes excerpt mysql and postgres
BACKUP=${PWD##*/}.tar.zst
tar --exclude='mysql' --exclude='postgres' --zstd -cf /tmp/$BACKUP -C volumes .
# Put it into the storage box (pubkey needed)
STORAGE_BOX=u442569@u442569.your-storagebox.de
TODAY=$(date +%F)
ssh -p23 $STORAGE_BOX "mkdir -p $TODAY"
scp -P 23 /tmp/$BACKUP $STORAGE_BOX:/home/$TODAY
# Clean
if [ -f "volumes/$DUMP_NAME" ]; then
rm volumes/$DUMP_NAME
fi
rm /tmp/$BACKUP
fi

6
scripts/vol-backup-all Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
for d in /srv/*/; do
cd $d
vol-backup
done

26
scripts/vol-restore Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/bash
#
# Run this script as root inside a service directory.
# 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
fi
mkdir volumes
tar --zstd --same-owner -xvf $BACKUP -C volumes
# Start the service and populate db from sql file if needed
if [ -f "compose.db-restore.yml" ]
then
docker compose -f compose.yml -f compose.db-restore.yml up -d
else
docker compose up -d
fi
# Clean backup files
rm $BACKUP
rm volumes/*.sql