8

Only sometimes, I forget to make a backup of a given linux file such as /etc/rc.local, /etc/rsyslog.conf, /etc/dhcpcd.conf, etc, and later wish I did. Distribution agnostic, is there a good approach to later getting a copy of an unf'd up copy?

9

While the topic of configuration files backup/versioning might seem simple on the surface, it is one of the hot topics of system/infrastructure administration.

Distribution agnostic, to keep automatic backups of /etc as a simple solution you can install etckeeper.

By default it commits /etc to a repository/version control system installed on the same system.

The commits/backups are by default daily and/or each time there are package updates.

The etckeeper package is pretty much present in all Linux distributions.

see: https://help.ubuntu.com/lts/serverguide/etckeeper.html

or https://wiki.archlinux.org/index.php/Etckeeper

It could be argued it is a good standard of the industry to have this package installed.

If you have not etckeeper installed, and need a particular etc file, there are several ways; you might copy it from a similar system of yours, you can ask your package manager to download the installation file or download it by hand, and extract the etc file from there; one of the easiest ways is using mc (midnight commander) to navigate inside packages as if they were directories.

You can also use the distribution repositories to get packages, in the case of debian is http://packages.debian.org

Ultimately if the etc/configurations are mangled beyond recognition you always have the option to reinstall the particular package. move the etc files to a backup name/directory, and for instance in Debian:

apt-get install --reinstall package_name

You can also configure and install the source repos for your particular distribution/version, install the source package, and get the etc files from there.

https://wiki.debian.org/apt-src (again a Debian example)

In some packages, you might also have samples of the configurations files at /usr/share/doc/package_name, which might be fit or not for use.

As a last resort, you may also find etc files in the repositories/github addresses if the corresponding open source projects, just bear in mind that often distributions change default settings and things around.

Obviously, none of these alternatives exempt you from having a sound backup policy in place, and retrieve your lost /etc files from there.

Times also move fast, and if following a devops philosophy, you might also choose to discard certains systems altogether and redeploy them in case some files get corrupted; you might also use CI and reploy the files for instance, from jenkins.

  • Thanks Rui. Not bad formatted considering it was on your phone! I will look into etckeeper. If you didn't have it installed and wanted a copy of the original, any recommended steps? – user1032531 Apr 28 '17 at 3:49
  • Travelling today, wont be able to edit this on a notebook so soon, if some feels like editing it, be my guest – Rui F Ribeiro Apr 28 '17 at 5:17
  • If it came from a package, extract it from the package .deb (or RPM, etc). If not, that's tougher. – tripleee Apr 28 '17 at 12:16
  • 2
    apt-get install --reinstall generally speaking won’t restore the default files in /etc. Extracting configuration from packages is generally straightforward, but there are a few gotchas: some packages build the configuration from other sources during installation (or are capable of merging settings from debconf or ucf). Installing etckeeper before anything else is definitely the easiest option ;-). – Stephen Kitt Apr 28 '17 at 13:57
  • @StephenKitt I said moving the etc files out of way before doing reinstall – Rui F Ribeiro Apr 28 '17 at 16:16
1

If your distribution has a live ISO, or you don't mind doing a virtual install to a Virtual Machine (VirtualBox, VMWare, etc) then you could see it's default files without digging through package files manually.

And installing / re-installing / re-configuring any packages in the VM wouldn't change your "real" system files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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