Initial version of filthy backup script

This commit is contained in:
3wc 2021-10-25 13:35:40 +02:00
commit 13eb58716b
1 changed files with 50 additions and 0 deletions

50
backup.sh Executable file
View File

@ -0,0 +1,50 @@
#!/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