How to recover previously saved text file after an overwrite and a reboot?

I was programming in python and I had two text editors open to the same file, and right before I shut down my computer I saved in the wrong one and overwrote the version I wanted to keep. How can I restore the old version? I'm using Mac OS X Snow Leopard


Solution 1:

There is little hope unless one or both of the editors squirrel away copies of the file for you or embed the undo buffer in the document.

It really depends on the editors and the settings.

One last ditch effort is to use the mdfind command. If that file had a memorable string or misspelling you could see in an instant if any files on the disk contain that string. If you search for a common string, you'll have a lot of false positives, but it's worth a shot.

In this case, even software that recovers deleted files won't be of use when another editor truncates the file. It was shredded and not simply deleted


On a personal note, We all learn this lesson about data loss in a personal way, usually many times over.

It's not overkill to have both version control and an automated backup system.

Time Machine is marvelous in that it makes hourly snapshots so you lose at most an hours work. Files that have been around for [a day|a week] are saved for [a month|until the drive fills]. It really works well in practice, and if you have local backups, you might even have snapshots more often than one an hour to recover a file. Sorry to hear you lost work, it's never a good feeling.

Solution 2:

You could try this: http://www.cgsecurity.org/wiki/TestDisk which is free undelete software, although it operates at the command line level. If you are happy with Python I will assume you are familiar enough with the terminal.app.

Other than that, Hope your backup caught the previous file, if you don't have a backup start making one, and/or consider switching to a text editor that provides for revisions/versions/backups etc. Prevention is better than cure, and being proactive with backups is better than being reactive with undeletes. Mistakes happen, I hop you can get your file back one way or another, and think about altering your workflow to try to prevent it happening again.

Solution 3:

You don't mention which editors you were using. My primary editor is BBEdit which has a preference to make backups of every file you save. On my system the files are saved to:

Documents/BBEdit Backups/[Date Folder]/[copies of your files]

This is set via the settings:

BBEdit > Preferences > Text files 

On a side note, I am so paranoid about backup that most of my projects are covered the following:

  • weekly SuperDupper full system bootable backup
  • SVN or Git for the project
  • BBEdit's backup for all text files I touch
  • Home directory Daily offsite incremental backups to Amazon S3 via Arq
  • Home directory every 20 minute backups via Crashplan to system in my office and Crashplan's remote servers