Skip to content

Instantly share code, notes, and snippets.

@chamlis
Created February 9, 2026 21:15
Show Gist options
  • Select an option

  • Save chamlis/137865c91cfa1877bc492ef30b393fad to your computer and use it in GitHub Desktop.

Select an option

Save chamlis/137865c91cfa1877bc492ef30b393fad to your computer and use it in GitHub Desktop.
#!/bin/sh
set -eu
if [ "$#" -ne 2 ]; then
echo "Usage: $0 input.db output.sql" >&2
exit 1
fi
if ! [ -f "$1" ]; then
echo "Input must be a file" >&2
exit 1
fi
WORKDIR=$(mktemp -d)
trap 'rm -rf "$WORKDIR"' EXIT
TMP_DB="$WORKDIR/tmp.db"
sqlite3 -readonly "$1" ".backup '$TMP_DB'"
sqlite3 -readonly "$TMP_DB" ".dump --preserve-rowids" > "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment