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-1Building configuration...Current configuration : 4573 bytes!! Last configuration change at 02:50:05 UTC Sat Jun 2 2018 by cisco!version 15.6service 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 Chapter11_1.py ...

Get Mastering Python Networking - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.