Emerging Member
Posts: 80
Registered: ‎05-14-2016
Kudos: 109
Solutions: 2

Scripts to push commits to git

[ Edited ]

I'm not thrilled with the way system config-management commit-archive location works, and I wanted to push every commit to a git repo, so I've whipped up some scripts to do just that.

 

https://github.com/tbyehl/edgerouter-backup

 

The scripts don't require any extra packages on the EdgeRouter and don't modify any files that are part of the OS. It send the backups to a git repository directory on a remote host using scp, then executes the git commands on the remote host over ssh.

 

The whole thing is ~40 lines of Bash in three scripts, plus a configuration file and an SSH key. Should be pretty simple to understand and the readme runs through everything you need to get it running except for the git portion and generating ssh keys.

 

Works on my ER-8 and ER-X-SFP on v1.9.1. Will test it against an ER-L and ER-8-XG soon.

 

Credit to this thread for helping me figure out how to hook into commit and persist across reboots:

 

https://community.ubnt.com/t5/EdgeMAX/Post-commit-scripts/m-p/1053637/thread-id/44579

Emerging Member
Posts: 80
Registered: ‎05-14-2016
Kudos: 109
Solutions: 2

Re: Scripts to push commits to git

I've made a bunch of tweaks since posting this, the most awesome of which is that it now also generates a backup of /config that is directly restorable from the web interface.

 

https://github.com/tbyehl/edgerouter-backup/releases/tag/v1.0.3

Established Member
Posts: 1,710
Registered: ‎05-03-2016
Kudos: 595
Solutions: 163

Re: Scripts to push commits to git

The GUI backup is just a tar file of the entire /config dir. So that should be very straightforward.

Emerging Member
Posts: 80
Registered: ‎05-14-2016
Kudos: 109
Solutions: 2

Re: Scripts to push commits to git

Indeed. I've improved on their method slightly by making the .tar.gz file reproducible. If you download the backup config from the UI twice in a row and hash them, you'll get two different hash values even though the contents of /config haven't changed.

 

It's a small thing but when you're putting things in source control you don't want files changing needlessly.