Mar 3, 2011

Recovering Lost Data In Safari

While trying to recover lost data typed into a web page on Safari, I stumbled across this forum and one response was worth remembering for later:
"If you wish to open cache.db you'd use the sqlite3 command.
It comes with your mac and it's easy to use if you know SQL.
Open Terminal an type in:
"cd ~/Library/Caches/;sqlite3 cache.db".
it'll open up the database and you can type ".tables" to show
the table names  then ".output FILENAME" 
then "select * from TABLENAME;" and it'll output to the
desired file you could do "foo.txt" as the file name. I have
3 tables, cfurl_cache_blob_data, cfurl_cache_schema_version,
cfurl_cache_response, in it so i did the steps three times
starting with the .output command for three separate files..."
This is a handy way to search through your old safari data by dumping everything in a file and then grepping the contents. The exact commands I used to accomplish this were:
cd ~/Library/Caches/
sqlite3 cache.db
.output temp.txt
select * from cfurl_cache_blob_data;
It's kind of surprising to see what's actually in your cache! I had no idea that the pages I surf were being stored to this extent. Turned out to be very handy.

But scary.

Other useful commands:

.schema cfurl_cache_blob_data


  1. Hey.. I'm trying to do something similar to what you posted on StackOverflow. So did you find any way you can see the shell command that Flash Builder 4 runs given the run configuration?

  2. Are you referring to this post?

    In flex, it turns out that flex builder just basically opens a browser pointed the webpage for your RIA. For example, the command used by Flex on my system is:

    /usr/bin/open -a /Applications/ http://localhost:8401/client/main.html?debug=true

    If you need to do other flex tasks, such as compiling or generating HTML wrappers, one approach would be to try using Flex Ant to get the job done.

  3. Kevin, any chance you could help me out? I've lost some critical info inputed into a Safari window. I tried your suggestion but I'm not familiar with Terminal and I can't seem to get anywhere with it.

  4. Hmm. I considered explaining the terminal commands above but, on second thought, if you're not familiar with it, then that's not going to be the best approach.

    Instead, I'd recommend getting a visual tool for looking at the database file. There are several SQLite editors that will make things easier. Here are several recommendations.

    In the past, I've used Lita (click the 'Install' badge below the download link).

    Open the app and choose "Open a database." When the file selection window opens, press command-shift-G and enter the following:


    That will let you browse the database. Once you get it open, you could choose "Export DB," at the top, to dump everything into a text file. From there, you can open that file with TextEdit and search through it.

    A much quicker way to do the same thing is to enter exactly the following into terminal (cut / paste from the first # up top to the last # at the bottom):

    cd ~/Library/Caches/
    sqlite3 cache.db
    .output safari-data.txt
    SELECT * FROM cfurl_cache_blob_data;
    SELECT * FROM cfurl_cache_response;
    SELECT * FROM cfurl_cache_receiver_data;
    SELECT * FROM cfurl_cache_schema_version;
    open safari-data.txt
    say done loading safari data, good luck!

    I hope you're able to find what you're looking for in that data!

  5. Thanks for your suggestions. Using Lita I was able to open the cache.db file but I couldn't make any sense of the contents (it seemed to be simply a bunch of url's and random blobs of html). In the safari-data.txt file, there seemed to be only html code as well. The code in both places did reference the url where I typed the lost text but I couldn't find the actual text.

    I was hoping to recover the text entered in the form but I may simply have to try to create it all again. But from now on, I'll either use Lazarus (safari add-on that remembers text in forms) or simply enter text offline primarily and cut/paste later.

    Thanks again.

  6. Hello! Did you manage to find a "readable" version of the html salad?

    I have been able to see the webpage and the html code in the safari-data.txt via the terminal commands, but I'm lost on how to read this.

    Thank you for your help in advance!