Skip to content

Instantly share code, notes, and snippets.

@sarim
Created September 6, 2013 08:14
Show Gist options
  • Save sarim/6460936 to your computer and use it in GitHub Desktop.
Save sarim/6460936 to your computer and use it in GitHub Desktop.

Revisions

  1. sarim created this gist Sep 6, 2013.
    16 changes: 16 additions & 0 deletions repairsqlite.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #!/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