Skip to content

Commit 2bfee44

Browse files
heyjorgedevclaude
andcommitted
Prune old DB backups, keep the 5 most recent
backup_db copies the SQLite file once per upgrade; without pruning the data dir grows one snapshot per release. Keep the 5 newest and remove the rest after each successful snapshot. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 84b8aa3 commit 2bfee44

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

install.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,20 @@ backup_db() {
198198
log "snapshotting database to ${backup}"
199199
cp -p "$db" "$backup"
200200
chown "${SERVICE_USER}:${SERVICE_USER}" "$backup"
201+
prune_backups "$db" 5
202+
}
203+
204+
# prune_backups keeps the N most recent deploykit.db.bak-* files and removes
205+
# the rest. Snapshots are tiny (megabytes) but accumulate one per upgrade.
206+
prune_backups() {
207+
local db="$1"
208+
local keep="$2"
209+
local old
210+
# shellcheck disable=SC2012 # backup names don't contain newlines.
211+
ls -1t "${db}.bak-"* 2>/dev/null | tail -n +"$((keep + 1))" | while IFS= read -r old; do
212+
log "pruning old backup ${old}"
213+
rm -f -- "$old"
214+
done
201215
}
202216

203217
# ensure_cosign installs the cosign binary into LIB_DIR if it isn't already

0 commit comments

Comments
 (0)