2

My Pi crashed and lost data recently but I had an old backup of /etc and /home.

When I reflashed the SD card I used a new OS, my question is can I just replace this /etc with the old one? I’m happy to replace /home but I’m not sure about what effects, if any, replacing an older /etc would have on a newer OS.

Any thoughts on the validity of restoring the /etc and any steps around it would be much appreciated. I’d also greatly appreciate any suggestions for how to do this better in future. Thank you, in advance.

2 Answers 2

1

/etc contains files involved in package management, so replacing these files with older versions may break respective software packages. Imagine you had /etc/foo/config which contained a setting bar=0 at the time you made your backup. Then a newer version of foo is released where bar was renamed to baz. When you install this package, /etc/foo/config is also updated to replace bar with baz. If you now restore the old backup, foo will complain about an unknown configuration parameter bar.

This gets much worse when security is at stake. For example, restoring your backup may revert hardened security settings back to insecure ones. Imagine you had a setting crypto_algoritms=A1,A2,A3, then a problem is discovered with A1, and it is removed from the settings. Restoring your backup will make your system vulnerable to a problem which is already fixed for everyone else, so this vulnerability may stick to your system for a long time.

If you want to make such backups in a useful way, you have several options:

  • keep a full image backup. Requires a lot of space.

  • use diff and patch to backup the changes you have done to /etc. You may occasionally run into problems, but at least patch will promptly warn you every time there is a problem. Requires very little space

  • write a script which makes the required changes, and keep backups of the said script. Requires very little space, and can also handle arbitrary commands like installation of missing packages.

3

I doubt that this question can be definitively answered. Here is my opinion.

The /etc directory is used for configuration data. The files and their contents are likely to change on a release by release basis.

Copying an old /etc is likely to cause errors later on. If you are lucky you may spot the error and be able to trace it to a /etc file configuration problem. If you are unlucky you may not even notice the error.

The same can be said for configuration data held in /home configuration files. At least they will only cause local problems.

Personally I regularly backup the changes I make to /etc. There don't tend to be many for me. I check the file changes individually at a new release or if I am re-installing.

3
  • Thanks, I will try to rebuild rather than restore so. Can I ask what sort of config problems you referred to?
    – BitFlow
    Jul 25, 2018 at 14:15
  • 1
    I remember having problems with mysql and the Apache server moving the location and format of some configuration files within /etc. I also remember various programs altering the way there ~/.local/share files were arranged.
    – joan
    Jul 25, 2018 at 14:26
  • thanks for your thoughts, I’ll go the long way round instead!
    – BitFlow
    Jul 25, 2018 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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