Browse Source

Add archivebot-compress-db

master
JustAnotherArchivist 4 months ago
parent
commit
c16bd0a477
1 changed files with 32 additions and 0 deletions
  1. +32
    -0
      archivebot-compress-db

+ 32
- 0
archivebot-compress-db View File

@@ -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

Loading…
Cancel
Save