Backup script resolves symlinks, aborts without DB
Invoking via ./backup.sh symlink made dirname escape the repo and sqlite created an empty DB in the parent dir. Now uses readlink -f with a location check plus a guard that refuses to run without ./whaleprep.db.
This commit is contained in:
parent
288ccef090
commit
ba10e70830
1 changed files with 10 additions and 1 deletions
|
|
@ -3,7 +3,16 @@
|
|||
# Usage: ./deploy/termux-backup.sh (run from repo root; safe while live)
|
||||
# Termux has no cron, so run this from Termux:Tasker, a daily alarm via
|
||||
# Termux:API, or manually. One line, one snapshot.
|
||||
cd "$(dirname "$0")/.."
|
||||
# Resolve symlinks first: this script may be invoked as ./backup.sh (a
|
||||
# symlink at repo root), in which case plain dirname would escape the repo
|
||||
# and sqlite would create an empty DB in the wrong place.
|
||||
HERE="$(dirname "$(readlink -f "$0")")"
|
||||
if [ "$(basename "$HERE")" = "deploy" ]; then
|
||||
cd "$HERE/.."
|
||||
else
|
||||
cd "$HERE"
|
||||
fi
|
||||
[ -f ./whaleprep.db ] || { echo "no ./whaleprep.db here ($(pwd)) — aborting"; exit 1; }
|
||||
OUT="./backups/whaleprep-$(date +%F).db"
|
||||
mkdir -p ./backups
|
||||
# VACUUM INTO refuses to overwrite, so remove today's snapshot first —
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue