Variables, Dockerfile, better syntax, etc.

This commit is contained in:
3wc
2021-11-06 19:45:39 +02:00
parent 49ed657084
commit 8317f50a8a
5 changed files with 80 additions and 24 deletions

View File

@ -1,15 +1,20 @@
#!/bin/bash
# FIXME: just for testing
backup_path=backups
server_name="${SERVER_NAME:?SERVER_NAME not set}"
# FIXME: just for testing
export DOCKER_CONTEXT=demo.coopcloud.tech
restic_password_file="${RESTIC_PASSWORD_FILE:?RESTIC_PASSWORD_FILE not set}"
mapfile -t services < <(docker service ls --format '{{ .Name }}')
restic_sftp_host="${RESTIC_SFTP_HOST:?RESTIC_SFTP_HOST not set}"
# FIXME: just for testing
services=( "ghost_demo_app" "ghost_demo_db" )
restic_repo="sftp:$restic_sftp_host:/$server_name"
backup_path="${BACKUP_DEST:?BACKUP_DEST not set}"
if [ -n "$SERVICES_OVERRIDE" ]; then
services=($SERVICES_OVERRIDE)
else
mapfile -t services < <(docker service ls --format '{{ .Name }}')
fi
for service in "${services[@]}"; do
echo "service: $service"
@ -32,7 +37,7 @@ for service in "${services[@]}"; do
if [ "$pre" != "null" ]; then
# run the precommand
# shellcheck disable=SC2086
docker exec "$container" $pre
docker exec "$container" sh -c "$pre"
fi
# run the backup
@ -41,10 +46,12 @@ for service in "${services[@]}"; do
if [ "$post" != "null" ]; then
# run the postcommand
# shellcheck disable=SC2086
docker exec "$container" $post
docker exec "$container" sh -c "$post"
fi
fi
restic -p restic-password \
backup --quiet -r sftp:u272979@u272979.your-storagebox.de:/demo.coopcloud.tech \
--tag coop-cloud "$backup_path"
done
restic -p "$restic_password_file" \
backup --quiet -r "$restic_repo" \
-o sftp.command="ssh $restic_sftp_host -s sftp" \
--tag coop-cloud "$backup_path"