Backup of etc
On my nginx proxy-server, I wanted to take backup of my configuration and setup in case if the disk fails me. I considered using GIT only to push changes every day, week, etc., but there was to hard to maintain. I needed to make crontab to run a script and the script contained running git in differents folders. Then I found, ‘etckeeper’, which makes the whole process easier.
What is ‘etckeeper’ ?
‘Etckeeper’ is a revision tool who use git, mercurial, bazaar or darcs, I prefer git. It stores the metadata of the file and commit/pushes daily.
How to install and use it ?
Since I’m using ‘etckeeper’ under debian, the showcase will be shown using debian.
First of all, we need to install the app we are using, in our case, etckeeper and git.
- Update the system and install ‘etckeeper’ and ‘git’
sudo apt update && sudo apt install etckeeper git
- Change configuration for etckeeper
sudo vim /etc/etckeeper/etckeeper.conf
- Here you need to change the usage of vcs, search for
VCS=
and set this to git (VCS=git
)
- Change your folder to
/etc
and start initate revision of the folder
cd /etc
sudo etckeeper init
- This will create a
.git
folder with files and subfolders and a.gitignore
file.
If you haven’t setup git before, you should set your git config first. Using these commands, it’ll create a .gitconfig file in your home folder(~)
git config --global user.name "My Name"
git config --global user.email "my@email.name"
- You should check out the git status to see if you dont want to backup with git.
sudo etckeeper vcs status | less
- This will provide you a list of files that will be taken backup, if you dont want to take backup of it, you could set the line in
.gitignore
When git is set, use etckeeper to commit.
sudo etckeeper commit "some comments"
- You can check out your commits, see and do changes by using the
vcs
sudo etckeeper vcs log #checks the logs
sudo etckeeper vcs show <id> #checks commit changes
sudo etckeeper vcs diff <id>..<id2> #checks the different between the commits
sudo etckeeper vcs checkout <id2> #revokes the change of the commit
sudo etckeeper vcs checkout <id> /etc/<filename> #revokes changes of the commit on the file