Wednesday 18 November 2015

restoring the configurations of a GNU/Linux system with git

As a Slackware user, I tend to customise my configurations file a lot, ie the files in /etc. I try to avoid using programs that write into /etc, this helps to have a certain consistency among my configured files. This also has the advantage to understand and optimise for performance and speed while leveraging the work load to a minimal effect.
In view of this methodology, I proposed to myself to setup up a git repository hosted under /etc and I performed this action on all three of my computers which are all now running Slackware x86_64.

Code:
cd /etc
git init
So for every change in /etc, I performed an analysis and registered the change in git.

Code:
cd /etc
git status
git add "The necessary files"
git commit -m "The change that happened"
This step has to be taken whenever an upgrade or a patch has to be installed.

I always keep /etc updated under git. But on a reboot, new network connection using Networkmanager and automatic update of time using ntpd , this is what comes out of a git status:

Code:
 git status
# On branch master
# Changes not staged for commit:
#   (use "git add ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#
#       modified:   adjtime
#       modified:   ld.so.cache
#       modified:   mtab
#       modified:   random-seed
#       modified:   resolv.conf
#
no changes added to commit (use "git add" and/or "git commit -a")
It has been more than two years that I track my changes when Slackware 14.1 was released and I wanted to quantify the changes happened during an OS upgrade, There was not changes since at that time and on that particular SlackBox I was using Slackware -current, so no great changes was registered. But in the coming months Slackware 14.2 shall be released and it shall be a good moment to act on the quantisation process of tracking configuration changes.

Nonetheless, the git repo has saved me time to reconfigure the system when I was testing the Nvidia driver directly rather that using Bumblebee. By removing and reinstalling all packages, I lad lost all my custom configurations done upon the /etc files and directories.
The solution obviously was to use git checkout to restore all files to the last commit.

Code:
cd /etc
git status
git checkout
git status
Obviously, I cheated here. I also launched gitk and did a "git reset master branch to here". This was equivalent to a git reset --hard "commit id". This was much easier and quicker than to find the last commit, then hard reset to that particular commit.

To my surprise there were a high number of new files in /etc when performing git status. Fortunately, they consisted only of *.orig and *.new and some backup files, ie *~. So the files were then removed using find.

Code:
find . -iname "*.orig" -exec rm {} \;
git status
find . -iname "*.new" -exec rm {} \;
git status
find . -iname "*~" -exec rm {} \;
git status

No comments:

Post a Comment

Thanks for your comment

highlights

Automatise additional Installation of software in Slackware

Slackware being an Advanced Operating System, is the oldest living Free/Libre Open Source Software Distribution in the world. Major task...