The little things give you away... A collection of various small helper stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

33 lines
783 B

  1. #!/bin/bash
  2. # Compresses the database in the current directory using the filename of the .json file for naming.
  3. if [[ ! -f wpull.db ]]; then
  4. printf 'Error: wpull.db does not exist.\n' >&2
  5. exit 1
  6. fi
  7. if lsof wpull.db >/dev/null; then
  8. printf 'Error: wpull.db is opened by another process.\n' >&2
  9. exit 1
  10. fi
  11. jsonfiles=(*.json)
  12. if [[ ${#jsonfiles[@]} -eq 0 ]]; then
  13. printf 'Error: no .json file\n' >&2
  14. exit 1
  15. elif [[ ${#jsonfiles[@]} -gt 1 ]]; then
  16. printf 'Error: two or more .json files\n' >&2
  17. exit 1
  18. fi
  19. outname="${jsonfiles[0]%.json}-wpull.db.zst"
  20. if [[ -e "${outname}" ]]; then
  21. printf 'Error: %q already exists\n' "${outname}" >&2
  22. exit 1
  23. fi
  24. printf 'WAL checkpoint...\n'
  25. sqlite3 wpull.db 'PRAGMA wal_checkpoint'
  26. printf 'Compressing...\n'
  27. zstd -10 -o "${outname}" wpull.db