Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undelete accidentally deleted records in Sqlite3

Tags:

sqlite

As title, possible? I have by accident deleted another record due to my ugly html interface in FireFox. The bad thing is this record delete is a root folder which the program automatically cascade delete everything :(

like image 864
William Yeung Avatar asked Jan 18 '09 10:01

William Yeung


4 Answers

Take a look at undark. I already used it. It it can export the rows (deleted or not) from a SQLite db file if the records were not overwritten. Last version here.

The SQLite-Deleted-Records-Parser does not give the same type of output, but can be useful.

And there are also some products like the SQLite Forensic Explorer, SQLite Repair, Sqlite Database Recovery and SQLiteDoctor.

If you are a developer you can avoid having the same problem again using litereplica. It adds single-master replication to SQLite.

But remember to enable the point-in-time recovery because as the transactions are replicated to the replicas an accidental command like DROP TABLE or DELETE FROM will also be replicated. With PITR you will be able to go to a previous point-in-time.

Or use the Backup API regularly. Although it transfers the entire db on each backup.

And remember: if you copy an SQLite file or use a regular backup approach while a transaction is active the copy can be corrupted.

like image 146
Bernardo Ramos Avatar answered Oct 13 '22 01:10

Bernardo Ramos


Sorry -- nope. Backups are the only option I know of.

In the future, consider never issuing DELETE queries, especially from user-accessible forms (let only the DB admin do it, if anyone) -- just include a field in your tables that marks a record as inactive and then factor that in to your queries in the WHERE clause.

like image 36
Wil Doane Avatar answered Oct 12 '22 23:10

Wil Doane


Unfortunately I don't know of a way, either. However, until you do a VACUUM on the SQLite database file the deleted data is generally not technically removed. Perhaps you might be able to still recover some of the data using some sort of hex editor on the file.

like image 28
Paul Lefebvre Avatar answered Oct 13 '22 00:10

Paul Lefebvre


It might be possible to go in and see the data via a hex-editor. The only info I could find said that metadata was gone so the records weren't going to come back, but the data itself might still be there. It has a lot to do with how important the data is, I suspect it's not important enough for you to dig out a hex editor.

like image 41
jcollum Avatar answered Oct 13 '22 01:10

jcollum