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