how to apply an older patch in local GIT repository?

How can I use Git as a distributed, private repository for server configuration files?

  • I am a new user of Git. I am thinking of controlling changes for configuration files in my Linux boxes, mostly CentOS. Putting all important configuration files for a box under one repository/project. Since all those configuration files are obviously scattered under different directories, how can I do that? Should I put root directory as the directory where I init Git? Should Git be the elegant solution, or is there a better solution? My idea is to push and pull configuration files from a server with ease and no need to manually backup or copy-and-paste to other location for backup. Don't even need to remember config file's location. Pull-edit-commit-push-done. Here I am looking for suggestion on the high-level and in detailed how-to's...

  • Answer:

    What is your prime motivation for this? Is it to backup the files in case of a system failure or just keeping the old versions in case you need to revert one of them? If the first, this really isn't the correct way simply because it's highly likely you will forget something important so just reinstalling & fetching those files won't be enough. You still need to find your backup files. If you have plenty of files scattered around, something like http://www.yolinux.com/TUTORIALS/LinuxTutorialRCSintro.htmlmight work better. Another possibility is http://www.nongnu.org/rdiff-backup/. If you insist on using Git I would create a simple script that copies files that you want to control to a directory with correct path structure and then pushing that to a remote server. This way reverting is simple. If you just want to backup one or two directories (such as /etc) then Git would work better. The Git method, since you wanted hands-on examples, would look something like Create the "central" repository. Clone that repository to your local box. Write a script that cp's all the files with their path to that repository, cd to repo's directory, git commit && git push. And that's it. The problem is collecting all the necessary files in step 3. Of course this is just pushing, for pulling you need to do a simple cp (cd / && sudo cp -rf /my_backups/* .) after you pull the repo. You don't really want to create the repo in the root directory, that's why this is so complicated. Another problem is that this does not keep file owners and permissions. For that you need something like https://github.com/pangloss/gibak. Another that might work is https://gitorious.org/coldstorage.

Marko Poutiainen at Quora Visit the source

Was this solution helpful to you?

Other answers

The answer you are looking for here is Puppet (or something of its ilk).  You can use that to manage all of those configuration files and push the Puppet manifest up to Git.  Get started here: http://puppetlabs.com/

George Campbell

I'm not sure if that would be a viable solution for system-wide config files, but for my user configuration files, I have created a folder called .dotfiles which is the home of the git repository. I then symlink all configuration files I need into that (e.g. "ln -s ~/.dotfiles/.bashrc ~/.bashrc"). To avoid having sensitive information (e.g. passwords) synced, I put these into a separate file which is not synced, and then source that into the synced file. Above method of course means you need to setup the symlinks on a new system, but I have seen people who have a bash script which handles that part.

Danny Krøger

Joey Hess has published a tool called etckeeper which does a good job of tracking changes to the etc directory. You can use git, mercurial or bzr as your VCS backend. It has hooks into package managers so that commits are made before each package install. The main use is simply to record what changed when on a single machine. It isn't useful as a means to distribute configuration changes across multiple machines - solutions like Puppet or Chef would be better for that. See https://github.com/joeyh/etckeeper

Jon Seymour

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.