From c16bd0a47760d66e3443784e5ba566d52d101d70 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Thu, 7 Dec 2023 16:26:30 +0000 Subject: [PATCH] Add archivebot-compress-db --- archivebot-compress-db | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 archivebot-compress-db diff --git a/archivebot-compress-db b/archivebot-compress-db new file mode 100755 index 0000000..d4b96c1 --- /dev/null +++ b/archivebot-compress-db @@ -0,0 +1,32 @@ +#!/bin/bash +# Compresses the database in the current directory using the filename of the .json file for naming. +if [[ ! -f wpull.db ]]; then + printf 'Error: wpull.db does not exist.\n' >&2 + exit 1 +fi + +if lsof wpull.db >/dev/null; then + printf 'Error: wpull.db is opened by another process.\n' >&2 + exit 1 +fi + +jsonfiles=(*.json) +if [[ ${#jsonfiles[@]} -eq 0 ]]; then + printf 'Error: no .json file\n' >&2 + exit 1 +elif [[ ${#jsonfiles[@]} -gt 1 ]]; then + printf 'Error: two or more .json files\n' >&2 + exit 1 +fi + +outname="${jsonfiles[0]%.json}-wpull.db.zst" +if [[ -e "${outname}" ]]; then + printf 'Error: %q already exists\n' "${outname}" >&2 + exit 1 +fi + +printf 'WAL checkpoint...\n' +sqlite3 wpull.db 'PRAGMA wal_checkpoint' + +printf 'Compressing...\n' +zstd -10 -o "${outname}" wpull.db