Monday, February 26, 2007

Recover a File with vi After System Crash

A few years ago, I was creating a maintenance script file for a database and experienced a system crash. As I recollect, the file had several hundred lines that were unsaved/modified, and the last thing I wanted to do was recover from an older copy. What did I do? Fortunately, I was able to use the "-r" option to recover the file.

# vi -r filename

2 comments:

Anonymous said...

For Solaris, if you find you have multiple instances of the same file/filename (it seems the latest copy is selected) and you want to obtain an earlier copy, you can move all the /usr/preserve/$LOGNAME/Ex* to somewhere safe (create another directory like /var/tmp/safespot/) and selectively move them back until you have the one you want.

'vi -r' will list them - as available.

You may need to make provision for a any in /var/tmp too (all the 'saved' files will begin with 'Ex'.

Move the files back to the way they were if necessary (or risk forgetting about what you've done :o)).

esofthub said...

Anon,

That is an excellent tip.