2

In order to save space, I don't backup /usr (except /usr/local), /bin, /sbin and /lib. Instead I do a rpm -qa --qf '%{NAME}\n' to get a list of packages I need to install to restore the content of these directories.

When doing a bare-metal recovery, after installing a minimal CentOS system, I install the packages in the list with yum.

Next step is to restore /etc, but here there is a problem: The packages I have just installed may be a newer version than those who were present on my old system when I created the backup. Thus, copying over my old /etc could break things, if configuration formats meanwhile has changed, or make my installation less secure, if important configuration directives has been added in the meantime. Checking every single configuration file is an option, but I would rather avoid it. Could it be done in a more automated fashion?

Troels Folke
  • 353
  • 2
  • 5

2 Answers2

3

Run rpm -Vac. You will get a list of every configuration file installed by RPM which has been altered.

Also, if you restore the contents of /etc before installing the packages, then yum will notice, and place any configuration files that are different with a .rpmnew extension. You can then go and look at those files individually.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
  • That sounds reasonable, but what do I do with the configuration files that has been installed as part of the minimal installation, like /etc/sysctl.conf? – Troels Folke Sep 01 '13 at 17:49
  • 1
    You've either altered them or you haven't. Either way your own copy of the files is what you want to use, right? – Michael Hampton Sep 01 '13 at 18:11
  • Yes, but I want all changes made by RPM-maintainers to the files incorporated. And while that will happen for the files that are owned by packages I install after having restored /etc from my backup copy, it will not happen to files owned by packages installed before my /etc restoration. That includes all packages that are part of the centos minimal installation, and thus files such as /etc/sysctl.conf – Troels Folke Sep 01 '13 at 18:37
  • You can run `rpm -Vac` to see which of them aren't the same, and then `yum reinstall` the affected packages, and they'll have the originals dropped in with a `.rpmnew` extension. Eventually you could probably write a script to automate this, to some extent at least, but that's something I would get paid for... :) – Michael Hampton Sep 01 '13 at 18:40
  • I just tested by overwriting /etc/named.conf with a completely different file on a test system, and then doing yum reinstall bind. No .rpmnew file is created. – Troels Folke Sep 01 '13 at 18:48
  • Hmmm, it certainly should have. Quite strange. – Michael Hampton Sep 01 '13 at 18:49
  • Hmm, well to force dropping of .rpmnew files, one could do a `rpm -e --nodeps --justdb ` and then a `yum install `. It is a bit ugly, but it works. – Troels Folke Sep 01 '13 at 19:28
0

You might take a look at etckeeper.

etckeeper is a collection of tools to let /etc be stored in a git, mercurial, bazaar or darcs repository. It hooks into [apt, yum] to automatically commit changes made to /etc during package upgrades. It tracks file metadata that git does not normally support, but that is important for /etc, such as the permissions of /etc/shadow.

Wes Turner
  • 109
  • 3