51 lines
1.4 KiB
Bash
51 lines
1.4 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
# FIXME: just for testing
|
||
|
backup_path=backups
|
||
|
|
||
|
# FIXME: just for testing
|
||
|
export DOCKER_CONTEXT=demo.coopcloud.tech
|
||
|
|
||
|
mapfile -t services < <(docker service ls --format '{{ .Name }}')
|
||
|
|
||
|
# FIXME: just for testing
|
||
|
services=( "ghost_demo_app" "ghost_demo_db" )
|
||
|
|
||
|
for service in "${services[@]}"; do
|
||
|
echo "service: $service"
|
||
|
details=$(docker service inspect "$service" --format "{{ json .Spec.Labels }}")
|
||
|
if echo "$details" | jq -r '.["backupbot.backup"]' | grep -q 'true'; then
|
||
|
pre=$(echo "$details" | jq -r '.["backupbot.backup.pre-hook"]')
|
||
|
post=$(echo "$details" | jq -r '.["backupbot.backup.post-hook"]')
|
||
|
path=$(echo "$details" | jq -r '.["backupbot.backup.path"]')
|
||
|
|
||
|
if [ "$path" = "null" ]; then
|
||
|
echo "ERROR: missing 'path' for $service"
|
||
|
continue # or maybe exit?
|
||
|
fi
|
||
|
|
||
|
container=$(docker container ls -f "name=$service" --format '{{ .ID }}')
|
||
|
|
||
|
echo "backing up $service"
|
||
|
test -d "$backup_path/$service" || mkdir "$backup_path/$service"
|
||
|
|
||
|
if [ "$pre" != "null" ]; then
|
||
|
# run the precommand
|
||
|
# shellcheck disable=SC2086
|
||
|
docker exec "$container" $pre
|
||
|
fi
|
||
|
|
||
|
# run the backup
|
||
|
docker cp "$container:$path" "$backup_path/$service"
|
||
|
|
||
|
if [ "$post" != "null" ]; then
|
||
|
# run the postcommand
|
||
|
# shellcheck disable=SC2086
|
||
|
docker exec "$container" $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
|