Created
September 6, 2013 08:14
-
-
Save sarim/6460936 to your computer and use it in GitHub Desktop.
Sqlite db repair script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
throwing really a lot of errors (multiline command isn't normal, /tmp can be full, sed should not have two expressions..), using this: