This answer is a checklist of some issues which would need testing, having not seen them mentioned elsewhere. Now I can happily discount mentions of "backing up" /etc, which do not also detail how to restore it. I have not tested to see whether this checklist is complete.
The following steps also ignore the frequent version-sensitive & other changes I see in etckeeper during package upgrades, as not specifically mentioned in the question. At least there are probably simpler systems where that is not a problem, like routers running OpenWrt.
- Assumption: this backup specifically includes
/etc
.
- Assumption: you also know how you're going to handle any references to filesystems, e.g. which might have been re-created with a different UUID, in
/etc/fstab
.
- Assumption: the target system does not include any extra users, when compared to the backup. E.g. it is a fresh install of the operating system, your initial user is created with the same name (and UID), and no additional services have been added to the OS during an upgrade. This is likely true within a Debian stable release, but certainly not reliable for a rolling-release distribution.
- Assumption: the install process is fully deterministic w.r.t. assigned UIDs (package install order), and this is not affected by any new updates in the repositories. I believe the usual package managers are deterministic. Again, Debian stable is probably reliable, a rolling-release isn't, and between them lies an area of uncertainty. You could also arrange to run the exact same version of the installer, without access to update repositories (both during the restore and when you installed the original system).
- You should have already installed the restore tool(s) for your backup :).
- The steps below also assume Linux' traditional shadow password files. BSD systems use different filenames. Some special-purpose Linux systems have introduced a significantly different style.
- Make sure you can boot into some "rescue mode", without using any password defined in
/etc
, and you don't need anything more complex in order to access the backup. We're playing with fire here. I don't know how disk encryption will handle this, although using the same password as the backup might help. Note the steps below will not work if run from a separate "rescue system".
mv /etc/ /etc.installer # can be removed later
mkdir /etc && chmod 755 /etc
ID_FILES=passwd group shadow
for i in $ID_FILES; do cp /etc.installer/${i} /etc; done
- Now for each file
i
in $ID_FILES
, you can restore /etc/${i}
from your backup to the target system.
- Now you can restore all the files, including their ownership information.
- Now you can re-apply SELinux labels or equivalent, if necessary.
If the backup is an etckeeper repo (and no additional files), then step 12 is to copy/clone it to /etc
and then run etckeeper init
. You could probably skip steps 10-12.
OpenWrt
System config backup/restore is supported on OpenWrt routers, with a specific feature in the web interface.
On my OpenWrt 15.05.1 system, I see the only users owning files in /etc
(or anywhere else) are root
and nobody
. It should be safe to assume that a fresh install of OpenWrt already includes these users.
I do not know if OpenWrt setups which have added extra users, would be handled correctly by this tool.
/etc
on OpenWrt. The answer I came up with being it might be ok in OpenWrt. But if I tried to do the same thing on a general-purpose Linux, there would be this annoying pitfall to work around. I think it gets a bit weird because I already had a separate concern (second paragraph of my answer). – sourcejedi Apr 18 '17 at 17:26/etc
and it works fine because