I just managed to corrupt contents of my Eclipse .metadata directory. Starting up with eclipse -clean did not work out. Deleting .metadata and then importing all projects, plugins and setting does not sound too interesting. I ended up moving .metadata/.plugins/org.eclipse.core.resources/ elsewhere and reimporting my projects only.
Are there any tools or best practices to recover workspace?
When workspace is damaged and Eclipse cannot start, even using the
-clean
option, removing single fileworkspace/.metadata/.plugins/org.eclipse.core.resources/.snap
may help (source: comments to article http://letsgetdugg.com/2009/04/19/recovering-a-corrupt-eclipse-workspace/).Update: when Eclipse 4.X cannot start after crash, try to start with
-clearPersistedState
option; if it didn't help then remove fileworkspace/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi
(sources: http://www.eclipse.org/forums/index.php/m/1269045/ http://www.eclipse.org/forums/index.php/t/522428/ https://bugs.eclipse.org/bugs/show_bug.cgi?id=404873). Note: you'll lose configuration of your perspective/views/tabs.Update: Subversive plugin may be responsible for unability to start Eclipse with corrupted metadata. If you have Subversive plugin installed, update it to latest build (at least 0.7.9.I20120210-1700) from update-site. Related bugs 372621 and 370374 were fixed by Subversive developers.
One more solution that I've discovered by accident, and may help someone:
In my case, it was a project that got corrupted, and not the entire workspace (attempting to import said project into a fresh workspace caused it to fail as well). So, I've started to search for the faulty project - instead, I got the result described above.
I know this sounds obvious, but if I'm writing code for a living I would be sure to do a full backup weekly, with corresponding incremental backups daily.
Simple and easy recovery.
For a simple way to backup your eclipse directory and assuming your using Linux, you could use rsync.
rsync -ar <eclipse-dir> <backup-eclipse-dir>
You can put this in cron and have it backup your files automatically. It will only copy over the changed files to your backup-eclipse-dir on subsequent runs.
You should be able to start your workspace after deleting the following file: .metadata.plugins\org.eclipse.e4.workbench\workbench.xmi as shown here :
In my case, it was not the workspace that was broken but Eclipse itself. Even though it seemed like workspace is broken (the same error dialog, etc.), all I had to do was reinstall Eclipse and point it to the old workspace. You can't really repair a broken workspace if it is the workspace that is broken but you can do so just for good measure, maybe it'll work.
If the workspace is not that big you could backup to say dropbox as a private locked folder.