Backup Server Configurations to Git

When you have multiple servers it pain to remember every configuration and it may take hours to configure servers again incase you need.
It is also impractical to copy each files.

There are few tools available but they come with overhead attached moreover its fun to write custom solutions 🙂

1. Create directory
2. cd into it.
3. Initialize git
4. Add a remote
5. Create branch specifically for that server
6. Check out branch
7. Add shell script
8. Make a commit and push to server.

Content of backup.sh

Then, Don’t forget to generate SSH key adding key to your git server.

Now i can either setup a cron job or add command to daily backup script to update configuration files.
using

from remote.

Simple automatic versioning using git

Many times while working on projects its hard to keep track of which version is in staging server, which is on production and which other developers of team are working on, Especially when you are a small startup with limited number of resources. (Its really painful to setup automatic deployment in gitlab).

Here is what i started following in every project :
Version of server should increase with number of commits, major increments will be done manually based on release date, number of issues solved. For automatic commit based versioning add following lines to .git/hooks/pre-commit.

git add Version && echo $(cat Version)+0.0001 | bc | awk '{printf "%0.4f", $0 > "Version"}'

Also make sure that file is executable by

chmod +x .git/hooks/pre-commit

I follow following version numbering system :
+1.00000 – Major version
+0.1 – Minor Version
+0.0001 – Commit