Skip to content

Backup Server Configurations to Git

git · linux · server · snippets · By Madhurendra Sachan ·

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.

mkdir backup
cd backup/  
git init
git remote add git@tikaj.com:tikaj/ConfigurationBackups.git
git branch $(hostname)
git checkout $(hostname)

#This file contains space delimited configuration file name and path relative to git.
touch ConfigurationFiles.list

vi backup.sh

Content of backup.sh

#!/bin/bash
BASEDIR=$(dirname $0)

cd $BASEDIR

while read line; do 
 IFS=' ' read -a A <<< "$line"
 cp ${A[0]} $BASEDIR/${A[1]} 
done < ConfigurationFiles.list


#Add new files and commit changes
git add --all :/
git commit -m "Update configuration files."
git push origin  $(hostname)
 

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

git push -u origin  $(hostname)

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

ssh mad@tikaj.com "bash /root/backup/backup.sh"

from remote.

IOT Push Button (Like Amazon Dash)

Amazon Dash button is an incredible piece of hardware and another example of “applied engineering” in Amazon, just like Kindle. The inspiration for this project isn’t directly derived from amazon dash, I wasn’t aware of it until I started digging the internet but at end, I had to set the performance goal to Amazon dash, because

arduino · linux · server · snippets ·

Cheap BLE : JDY-08

Disclaimer : This post is based on my experience which is completely subjective, in no way I am promoting any application or product 😉 I have been trying to get my hands into BLE4.0 modules since long. As always I was looking for small, cheap solution, JDY-08 was one of solution I came across –

arduino · linux ·

Adding a display over network !

You are doomed if your laptop has only one HDMI Port & you are running Linux in that box. Unlike windows – where there are tons of easy to run solution, & there are still tons of solutions if you have big numbers in your pocket. Certainly – I neither wish to spend money on external VGA/HDMI

linux · server · snippets ·