diff --git a/offgrid_pile.sh b/offgrid_pile.sh index 32950cf..51cbac5 100755 --- a/offgrid_pile.sh +++ b/offgrid_pile.sh @@ -1,6 +1,11 @@ #!/bin/bash set -e +function finish() { + echo "$(date) Cleaning up..." + kill "${SERVER_PID}" 2>/dev/null + rm -r "${TMP_DIR}" +} echo "$(date) Syncing database..." rsync -v sdbs:/var/www/sdbs-pile/db.sqlite3 . echo "$(date) Syncing /docs..." @@ -11,6 +16,8 @@ OUT_DIR="${TMP_DIR}/sdbs_pile" mkdir -p "${OUT_DIR}" echo "$(date) Will backup into ${OUT_DIR}" +trap finish EXIT + echo "$(date) Starting local pile server" source .venv/bin/activate STATIC=1 python manage.py runserver 4123 & @@ -29,10 +36,3 @@ kill "${SERVER_PID}" echo "$(date) Compressing archive..." 7z a sdbs_pile__$(date "+%Y-%m-%d__%H%M%S").7z "${OUT_DIR}" - -function finish() { - echo "$(date) Cleaning up..." - kill "${SERVER_PID}" 2>/dev/null - rm -r "${TMP_DIR}" -} -trap finish EXIT