#!/bin/bash BORGUSER="{{ backup_owner }}"; RUNFOLDER="{{ backup_run_folder }}"; TARGETFOLDER="{{ backup_storage }}"; REPOLOCATION="{{ backup_location }}"; ARCHIVENAME="authentik-$(date '+%s')"; cd $RUNFOLDER; POSTGRES_DOCKER_ID=$(docker ps --format '{{.ID}} {{.Names}}' | grep postgres | cut -f 1 -d ' '); mkdir $TARGETFOLDER/$ARCHIVENAME; docker exec -i $POSTGRES_DOCKER_ID /usr/local/bin/pg_dump --username {{ authentik_db.user }} {{ authentik_db.name }} > $TARGETFOLDER/authentik-postgres-backup.sql sudo -H -u $BORGUSER bash -c ' TARGETFOLDER='$TARGETFOLDER'; REPOLOCATION='$REPOLOCATION'; ARCHIVENAME='$ARCHIVENAME'; export BORG_PASSPHRASE=$(cat {{ backup_home }}/.borg.key); borg create -C lzma $REPOLOCATION::$ARCHIVENAME $TARGETFOLDER/$ARCHIVENAME'; rm -rf $TARGETFOLDER/$ARCHIVENAME; ### RESTORE!!! ### SHUTDOWN_CONTAINER_IDS=$(docker ps --format '{{.ID}} {{.Names}}' | cut -f 1 -d ' ' | grep -v $POSTGRES_DOCKER_ID | tr '\n' ' '); docker stop $SHUTDOWN_CONTAINER_IDS docker exec -i $POSTGRES_DOCKER_ID /usr/local/bin/dropdb --username {{ authentik_db.user }} '{{ authentik_db.name }}' docker exec -i $POSTGRES_DOCKER_ID /usr/local/bin/createdb --username {{ authentik_db.user }} '{{ authentik_db.name }}' docker exec -i $POSTGRES_DOCKER_ID /usr/local/bin/psql --username {{ authentik_db.user }} -d {{ authentik_db.name }} < $TARGETFOLDER/authentik-postgres-backup.sql docker-compose down docker-compose up -d help (){ echo "Here Help"; } ( flock -n 9 || { echo "PERFORMANCE TEST ABORTED! ALREADY RUNNING!"; exit 1; } if [[ $(id -u) != 0 ]]; then echo "Performance test aborted; please become root in order to run a performance test."; exit 1; fi if [ $# = 0 ]; then help exit 0; fi case $tooling in "atlassian") echo "blah"; ;; *) # I know this looks stupid, only one case, but in future we want to use TaaS/TReX aswell... # So let's make it future safe! echo -e "Invalid tooling '$tooling'.Please check help for correct list." exit 1 ;; esac echo "" ) 9>/var/run/lock/devstack-loadtest.lock;