Finish Borg script #2

Merged
lhahn merged 4 commits from borg into main 2024-07-25 21:55:47 +02:00
3 changed files with 31 additions and 1 deletions
Showing only changes of commit 7ca52f7374 - Show all commits

View File

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

View File

@ -1 +0,0 @@
#!/bin/bash