Skip to content

Instantly share code, notes, and snippets.

@click0
Forked from sarim/repairsqlite.sh
Created August 2, 2020 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save click0/b2de322211e9b5d44d39437a4006ee49 to your computer and use it in GitHub Desktop.
Save click0/b2de322211e9b5d44d39437a4006ee49 to your computer and use it in GitHub Desktop.
Sqlite db repair script
#!/bin/bash
DBSTATUS=$(sqlite3 "$1" "PRAGMA integrity_check")
if [ "$DBSTATUS" == "ok" ] ; then
echo DB ALREADY OK
else
echo FIXING CORRUPT DB
TMPDB=$(mktemp -t sarim)
echo ".mode insert
.dump" | sqlite3 "$1" > $TMPDB
rm "$1"
sed -i "" "s/ROLLBACK; -- due to errors/COMMIT;/" $TMPDB
sqlite3 "$1" < $TMPDB
rm $TMPDB
echo DB FIXED
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment