At my job we are looking to backup our switch configs to a Github private repo. We use observium and rancid to grab the configs. Next we want to automate the sync to Guthub.
These options will be used for the commits
git config --global user.name "Your Name" git config --global user.email "firstname.lastname@example.org"
This will clone the repo. Be sure to execute this command where you want it to be. This might ask for credentials from Github.
git clone REPO_NAME
Once you have the repo setup if you can start to automate it. We are looking to backup some files to the repo. This is a sample script i wrote
#! /bin/bash #! Do a Git Pull before files are added to the repo git pull #! This section will copy the files from somewhere to somewhere else but only if they are newer rsync --progress -r -u /source/* /destination #!This section will add the files to the repo git add *.* #!Commit the files git commit -m "From Server" #!Push the files up git push
One thing i ran into was that certain operations required a username and password. I created a .netrc file in the home directory with permissions of 600. inside of that file I had the following options.
Host Server-Name Hostname github.com User My.Username login Github.account password My.Password IdentiyFile /Path/to/ssh/key
This can used as a check to see status of repo and sync
To execute this I used Crontab.