How can i recover deleted data from sqlite? [duplicate]

血红的双手。 提交于 2019-12-11 02:47:21

问题


I want recover deleted record and dropped data from SQLite db file,

I check my db file with text editor and i saw dropped data is still there..

I'm using SQLite3.dll (in c#) but i can`t find something property for open db with dropped data or ...

Is there any library for helping me? or something simple code for recovering data from sqlite db file?

Edit 1:

i try to find a data recovery library or program for sqlite.. after many searchs i found http://www.devart.com/dotconnect/sqlite/docs/Devart.Data.SQLite~Devart.Data.SQLite.SQLiteDump.html

SQLiteConnection.Open(); 
SQLiteDump sqSqlDump = new SQLiteDump(); 
sqSqlDump.Connection = SQLiteConnection1; 
sqSqlDump.IncludeDrop = true;                          //<<-- check here
sqSqlDump.Backup(); 
StreamWriter stream = new StreamWriter("d:\\dump.dmp"); 
stream.WriteLine(sqSqlDump.DumpText); 
stream.Close(); 

that i can use IncludeDrop property for backing data to me but this library is not free and i cant use it.. i like to find free library or program...


回答1:


SQLite deletes data perminently when you delete records. It would be up to you to implement a model where by data was only marked as deleted or maybe a system where you store all versions of the data. You do this by adding fields to mark those attributes. Then when you do selects you change them to account for the new fields functionality.

Like:

select * from mytable where mytable.deleted<>true and etc=etc

SQLite stores all it's data in a single file. If you have a file system backup service in place you could get at old versions of the database.

When SQLite deletes records there maybe ghost data left in the file. This data is just rubbish and won't allow you to reliably get back to a previous point before deletion.

The SQLite db file is binary, be careful editing it with a text editor if you save it will be corrupted!




回答2:


It is possible, at least partially, by hiring a (very expensive) data recovery firm which would recover the data by analysing the binary file. You will probably not be able to do it yourself because, as others have said, "SQLite deletes data permanently when you delete records" and that is true, because the data deletion operation in SQLite involves overwriting the metadata in the file describing where the data is and how it is related to other data.

Parts of the data might still physically be in the file but:

  • The pointers to this data (sqlite uses btrees) are gone and the file regions are marked as "free space" in the metedata
  • In the process of using the database, some of that space may have been overwritten and now contains garbage.

If you have have nothing to do for the next couple of months, you may start by analysing the SQLite file structure and applying that knowledge to try guessing where the data might have ended up in the file before it was deleted (meaning, its metadata was overwritten) and so perform the recovery. You need to start here: http://www.sqlite.org/fileformat.html .




回答3:


I don't think that is possible, see Documentation. I don't know what data you are seeing in your text editor.



来源:https://stackoverflow.com/questions/21628240/how-can-i-recover-deleted-data-from-sqlite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!