#!/bin/bash # curl -X POST -H "Content-Type: application/json" -d '{"path":"/","tag":"test3","request_id":"1","version":0}' http://127.0.0.1:9000/hooks/queue-restic-snapshot pipe="/tmp/restic/snapshot_trigger_pipe" if [ ! -p "$pipe" ]; then mkdir -p "/tmp/restic" mkfifo "$pipe" chmod 777 -R "/tmp/restic" # TODO fix this, the webhook web server runs as a user that can access this otherwise fi # keep pipe open exec 3<"$pipe" while read -u 3 msg; do ghost_db_running=false nassella_lldap_db_running=false nassella_authelia_db_running=false nassella_db_running=false nextcloud_db_running=false nextcloud_redis_running=false IFS=$'\t' # set IFS to tab (IFS is the delimiter used to split strings when parsing in the shell) set -- $msg # this splits msg based on IFS (tab) tag=$1 request_id=$2 path=$3 # TODO not currently used # update status for webhooks printf "%s\n" "running" > "/tmp/restic/snapshot_status_$request_id" touch /app/maintenance/maintenance.on # shut down databases so we can get a clean snapshot if docker ps --filter "name=^app-ghost_db-1$" --filter "status=running" | grep -q app-ghost_db-1; then ghost_db_running=true docker stop app-ghost_db-1 fi if docker ps --filter "name=^app-nassella_lldap_db-1$" --filter "status=running" | grep -q app-nassella_lldap_db-1; then nassella_lldap_db_running=true docker stop app-nassella_lldap_db-1 fi if docker ps --filter "name=^app-nassella_authelia_db-1$" --filter "status=running" | grep -q app-nassella_authelia_db-1; then nassella_authelia_db_running=true docker stop app-nassella_authelia_db-1 fi if docker ps --filter "name=^app-nassella_db-1$" --filter "status=running" | grep -q app-nassella_db-1; then nassella_db_running=true docker stop app-nassella_db-1 fi if docker ps --filter "name=^app-nextcloud_db-1$" --filter "status=running" | grep -q app-nextcloud_db-1; then nextcloud_db_running=true docker stop app-nextcloud_db-1 fi if docker ps --filter "name=^app-nextcloud_redis-1$" --filter "status=running" | grep -q app-nextcloud_redis-1; then nextcloud_redis_running=true docker stop app-nextcloud_redis-1 fi # perform the snapshot docker run --rm --volume /nassella:/nassella --volume /restic-password:/restic-password -e AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} -e AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} -i restic/restic:0.18.0 backup --verbose --repo s3:${BACKBLAZE_BUCKET_URL} --password-file /restic-password --tag "$tag" "/nassella" # restart databases if [ $ghost_db_running = true ]; then docker start app-ghost_db-1 fi if [ $nassella_lldap_db_running = true ]; then docker start app-nassella_lldap_db-1 fi if [ $nassella_authelia_db_running = true ]; then docker start app-nassella_authelia_db-1 fi if [ $nassella_db_running = true ]; then docker start app-nassella_db-1 fi if [ $nextcloud_db_running = true ]; then docker start app-nextcloud_db-1 fi if [ $nextcloud_redis_running = true ]; then docker start app-nextcloud_redis-1 fi rm /app/maintenance/maintenance.on # update status for webhooks printf "%s\n" "complete" > "/tmp/restic/snapshot_status_$request_id" done