Add a weekly dump of the Garmin database

garmin-dump.timer runs garmin-dump weekly, keeping the two newest ISO weeks in
~/.local/share/negsplit/dumps, which simple_backup then copies; the login comes
from ~/.config/negsplit/dump.cnf (not tracked).
This commit is contained in:
Daniele Fucini
2026-10-31 11:30:03 +01:00
parent cc8eaebd5f
commit 831238e040
4 changed files with 45 additions and 1 deletions
+24
View File
@@ -0,0 +1,24 @@
#!/bin/bash
# Dump the Garmin database to a per-ISO-week file, keeping the two newest weeks.
set -euo pipefail
cnf=${XDG_CONFIG_HOME:-$HOME/.config}/negsplit/dump.cnf
dir=${XDG_DATA_HOME:-$HOME/.local/share}/negsplit/dumps
out=$dir/Garmin-$(date +%G-W%V).sql.gz
keep=2
umask 077
mkdir -p "$dir"
# Write to a temporary file so a failed dump never replaces a good one
tmp=$(mktemp "$dir/.dump.XXXXXX")
trap 'rm -f "$tmp"' EXIT
mariadb-dump --defaults-extra-file="$cnf" --single-transaction --databases Garmin | gzip > "$tmp"
mv "$tmp" "$out"
# Names sort by week, so all but the last $keep are the old ones
dumps=("$dir"/Garmin-*.sql.gz)
if (( ${#dumps[@]} > keep )); then
rm -f -- "${dumps[@]:0:${#dumps[@]}-keep}"
fi