Automating configuration backup
In this example, we will use PyGithub to back up a directory containing our router configurations. We have seen how we can retrieve the information from our devices with Python or Ansible; we can now check them into GitHub.Â
We have a subdirectory, named config
, with our router configs in text format:Â
$ ls configs/ iosv-1 iosv-2 $ cat configs/iosv-1 Building configuration... Current configuration : 4573 bytes ! ! Last configuration change at 02:50:05 UTC Sat Jun 2 2018 by cisco ! version 15.6 service timestamps debug datetime msec ...
We can use the following script to retrieve the latest index from our GitHub repository, build the content that we need to commit, and automatically commit the configuration:
$ cat Chapter10_1.py #!/usr/bin/env python3 # reference: https://stackoverflow.com/questions/38594717/how-do-i-push-new-files-to-github from github import Github, InputGitTreeElement import os github_token = '<token>' configs_dir = 'configs' github_repo...