I accidentlly deleted /var folder form my ubuntu istalltion. Can it be restored somehow, without loosing the installation? Please suggest what options I do have?

link|improve this question

67% accept rate
Isn't that exactly what backups are for? – David Schwartz Nov 9 '11 at 9:33
feedback

1 Answer

/var contains some important folders which hold the state for programs (in /var/lib). Your program state (dpkg) has gone too, so you will end up with a reinstallation of programs anyway.

Since /var/log has gone too, you cannot analyse /var/log/apt/history.log either so you have to rely on your memory to know which programs you've installed. After restoring the dpkg and packages database (probably by sudo install -D -m755 /var/lib/dpkg && sudo apt-get update), you can use dpkg -S /path/to/file to get the package for a given path.

That said, a reinstallation would be the easiest way. Make a backup of /home (and possibly /etc if you changed system-wide settings or users/groups) and do a reinstall. If your /home was on a separate partition, it's even easier: mark that partition as /home in the installer, but do not tick "format".

link|improve this answer
1  
I don't understand: if he lost /var, how can he look at /var/log/apt/history.log? – Lohoris Nov 9 '11 at 9:20
1  
@Lohoris: well, that's technically possible since /var/log could be a separate mount point. Updated answer with for a more likely situation. – Lekensteyn Nov 9 '11 at 9:37
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.