The little things give you away... A collection of various small helper stuff
Du kan inte välja fler än 25 ämnen
Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
|
- #!/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
|