Something went wrong. Try again.
A script to set to a cron tab to clear the sequencer.sqlite db
Something went wrong. Try again.
754 B · 24 lines · Created 6mo ago
Shell
12345678910111213141516171819202122232425#!/usr/bin/env bash# Trims the sequencer.sqlite db on a PDS# usage {db path} {hours back to trim}# /pds/sequencer.sqlite 48set -euo pipefail# Uncomment to log the out put somewhere#exec &>> /pds/capture-log.txtDB_PATH="${1:-sequencer.sqlite}"HOURS_AGO="${2:-48}"
# Calculate the cutoff timestamp in ISO8601 formatTRUNCATE_FROM=$(date -u -d "${HOURS_AGO} hours ago" +"%Y-%m-%dT%H:%M:%S.000Z" 2>/dev/null \ || date -u -v-${HOURS_AGO}H +"%Y-%m-%dT%H:%M:%S.000Z") # macOS fallback
echo "Deleting rows from repo_seq where sequencedAt < ${TRUNCATE_FROM}"
sqlite3 \ -cmd ".timeout 10000" \ "${DB_PATH}" \ "PRAGMA journal_mode=WAL; PRAGMA busy_timeout=10000; DELETE FROM repo_seq WHERE sequencedAt < '${TRUNCATE_FROM}';"
echo "Done."