Using GIT to restore a deleted config file

in git •  8 years ago 

I use Nagios for monitoring at work and recently found that a config file had been accidentally deleted.

My first thought was to restore the file from an earlier backup however this would have required finding which backup contained the missing file which could have taken at least half an hour.

Then I remembered that on each Nagios server I keep the configuration directory (/etc/nagios) under git version control so it would be fairly easy to restore any uncommitted changes.

The missing file was /etc/nagios/okconfig/contacts/MG.cfg

I ran the following commands to restore the file

cd /etc/nagios/okconfig/contacts
git status

which showed
deleted: okconfig/contacts/ManagedServices.cfg

git checkout -- .

Whala! My deleted file was back.
Note: Different commands would be required if the change had already been committed.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!