Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’Ύ Network Config Backup Tool

Python Netmiko Git License

Automated network configuration backup with Git versioning, compliance checking, and change detection

Features β€’ Installation β€’ Usage β€’ Supported Devices


🎯 Overview

The Network Config Backup Tool provides enterprise-grade automated configuration backup for multi-vendor network environments. It combines Netmiko for device connectivity, Git for version control, and intelligent diff analysis for change detection.

Why This Tool?

Challenge Solution
Manual backups are inconsistent Scheduled automated backups
No version history Git-based versioning with full history
Change tracking is difficult Automated diff reports and notifications
Multi-vendor complexity Unified interface for Cisco, Juniper, Arista, Palo Alto
Compliance verification Built-in compliance rule engine

⚑ Features

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    CORE CAPABILITIES                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  πŸ“¦ BACKUP          β”‚  πŸ“Š ANALYSIS        β”‚  πŸ”” ALERTS          β”‚
β”‚  ─────────────────  β”‚  ─────────────────  β”‚  ─────────────────  β”‚
β”‚  β€’ Running Config   β”‚  β€’ Diff Detection   β”‚  β€’ Email Reports    β”‚
β”‚  β€’ Startup Config   β”‚  β€’ Change Summary   β”‚  β€’ Slack Webhook    β”‚
β”‚  β€’ Full State       β”‚  β€’ Compliance Check β”‚  β€’ Teams Notify     β”‚
β”‚  β€’ Custom Commands  β”‚  β€’ Security Audit   β”‚  β€’ Syslog           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  πŸ”„ VERSION CONTROL β”‚  πŸ“… SCHEDULING      β”‚  πŸ” SECURITY        β”‚
β”‚  ─────────────────  β”‚  ─────────────────  β”‚  ─────────────────  β”‚
β”‚  β€’ Git Integration  β”‚  β€’ Cron Jobs        β”‚  β€’ Encrypted Creds  β”‚
β”‚  β€’ Branch per Site  β”‚  β€’ Interval Based   β”‚  β€’ SSH Key Auth     β”‚
β”‚  β€’ Commit History   β”‚  β€’ On-Demand        β”‚  β€’ Vault Support    β”‚
β”‚  β€’ Tag Releases     β”‚  β€’ Change Triggered β”‚  β€’ Audit Logging    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ–₯️ Supported Devices

Vendor Platforms Connection
Cisco IOS, IOS-XE, IOS-XR, NX-OS, ASA SSH
Juniper Junos (SRX, EX, MX, QFX) SSH/NETCONF
Arista EOS SSH/eAPI
Palo Alto PAN-OS SSH/API
Fortinet FortiOS SSH
HP/Aruba ProCurve, ArubaOS SSH
Linux Any SSH-accessible server SSH

πŸ“¦ Installation

# Clone repository
git clone https://github.com/tamersaid2022/network-config-backup.git
cd network-config-backup

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Linux/Mac

# Install dependencies
pip install -r requirements.txt

# Initialize Git repository for backups
cd backups && git init

Requirements

netmiko>=4.2.0
paramiko>=3.3.0
pyyaml>=6.0
gitpython>=3.1.0
cryptography>=41.0.0
jinja2>=3.1.0
rich>=13.0.0
python-dotenv>=1.0.0
schedule>=1.2.0
requests>=2.31.0

πŸš€ Usage

Quick Start

from network_backup import NetworkBackup

# Initialize backup manager
backup = NetworkBackup(
    inventory="inventory.yaml",
    backup_dir="./backups",
    git_enabled=True
)

# Backup all devices
results = backup.backup_all()

# Backup specific device
backup.backup_device("core-router-01")

# Generate change report
report = backup.diff_report(days=7)

Command Line Interface

# Backup all devices in inventory
python network_backup.py backup --all

# Backup specific device
python network_backup.py backup --device core-router-01

# Backup by group/tag
python network_backup.py backup --group datacenter

# Show recent changes
python network_backup.py diff --days 7

# Run compliance check
python network_backup.py compliance --rules rules/security.yaml

# Schedule backups (runs every 6 hours)
python network_backup.py schedule --interval 6h

πŸ“‹ Configuration

Inventory File (inventory.yaml)

# inventory.yaml
---
defaults:
  username: admin
  timeout: 30
  
devices:
  core-router-01:
    host: 192.168.1.1
    device_type: cisco_ios
    groups: [datacenter, core]
    
  core-router-02:
    host: 192.168.1.2
    device_type: cisco_ios
    groups: [datacenter, core]
    
  firewall-01:
    host: 192.168.1.10
    device_type: paloalto_panos
    groups: [datacenter, security]
    
  switch-access-01:
    host: 192.168.2.1
    device_type: cisco_ios
    groups: [access, floor1]
    
groups:
  datacenter:
    backup_commands:
      - show running-config
      - show version
      - show inventory
      
  security:
    backup_commands:
      - show config running
      - show system info

Compliance Rules (rules/security.yaml)

# rules/security.yaml
---
name: "Security Baseline"
version: "1.0"

rules:
  - name: "SSH Version 2 Required"
    pattern: "ip ssh version 2"
    required: true
    severity: HIGH
    remediation: "Configure 'ip ssh version 2'"
    
  - name: "No Telnet"
    pattern: "transport input telnet"
    prohibited: true
    severity: CRITICAL
    remediation: "Remove telnet from line configurations"
    
  - name: "Enable Secret Configured"
    pattern: "enable secret"
    required: true
    severity: HIGH
    
  - name: "NTP Configured"
    pattern: "ntp server"
    required: true
    severity: MEDIUM
    
  - name: "Logging Enabled"
    pattern: "logging buffered"
    required: true
    severity: MEDIUM

πŸ“Š Sample Outputs

Backup Summary

╔══════════════════════════════════════════════════════════════════╗
β•‘              NETWORK CONFIGURATION BACKUP REPORT                 β•‘
╠══════════════════════════════════════════════════════════════════╣
β•‘  Timestamp:    2024-01-15 14:30:00                               β•‘
β•‘  Total Devices: 25                                               β•‘
β•‘  Successful:    23                                               β•‘
β•‘  Failed:        2                                                β•‘
╠══════════════════════════════════════════════════════════════════╣
β•‘  BACKUP STATUS                                                   β•‘
β•‘  β”œβ”€ core-router-01      βœ… SUCCESS    2.3 KB   Changed          β•‘
β•‘  β”œβ”€ core-router-02      βœ… SUCCESS    2.1 KB   No Change        β•‘
β•‘  β”œβ”€ firewall-01         βœ… SUCCESS    45 KB    Changed          β•‘
β•‘  β”œβ”€ switch-access-01    ❌ FAILED     Timeout                   β•‘
β•‘  └─ switch-access-02    βœ… SUCCESS    1.8 KB   No Change        β•‘
╠══════════════════════════════════════════════════════════════════╣
β•‘  GIT COMMIT: a3f7c2d - "Automated backup 2024-01-15"            β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

Change Detection Report

╔══════════════════════════════════════════════════════════════════╗
β•‘              CONFIGURATION CHANGE REPORT (7 Days)                β•‘
╠══════════════════════════════════════════════════════════════════╣
β•‘  Device: core-router-01                                          β•‘
β•‘  Changes: 3 commits                                              β•‘
╠══════════════════════════════════════════════════════════════════╣
β•‘                                                                  β•‘
β•‘  [2024-01-15 10:30] Added VLAN 100                              β•‘
β•‘  ──────────────────────────────────────────────────────────────  β•‘
β•‘  + vlan 100                                                      β•‘
β•‘  +  name PRODUCTION                                              β•‘
β•‘  + interface Vlan100                                             β•‘
β•‘  +  ip address 10.100.0.1 255.255.255.0                         β•‘
β•‘                                                                  β•‘
β•‘  [2024-01-14 16:45] Updated ACL                                 β•‘
β•‘  ──────────────────────────────────────────────────────────────  β•‘
β•‘  - access-list 101 permit ip 10.0.0.0 0.255.255.255 any        β•‘
β•‘  + access-list 101 permit ip 10.0.0.0 0.0.255.255 any          β•‘
β•‘                                                                  β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

Compliance Report

╔══════════════════════════════════════════════════════════════════╗
β•‘              COMPLIANCE AUDIT REPORT                             β•‘
╠══════════════════════════════════════════════════════════════════╣
β•‘  Baseline:    Security Baseline v1.0                             β•‘
β•‘  Devices:     25 scanned                                         β•‘
β•‘  Compliant:   20 (80%)                                           β•‘
β•‘  Non-Compliant: 5 (20%)                                          β•‘
╠══════════════════════════════════════════════════════════════════╣
β•‘  FINDINGS                                                        β•‘
β•‘                                                                  β•‘
β•‘  πŸ”΄ CRITICAL (2)                                                 β•‘
β•‘  β”œβ”€ switch-access-05: Telnet enabled on VTY lines               β•‘
β•‘  └─ switch-access-12: Telnet enabled on VTY lines               β•‘
β•‘                                                                  β•‘
β•‘  🟠 HIGH (3)                                                     β•‘
β•‘  β”œβ”€ switch-access-03: SSH version 1 in use                      β•‘
β•‘  β”œβ”€ switch-access-07: No enable secret configured               β•‘
β•‘  └─ switch-access-09: SSH version 1 in use                      β•‘
β•‘                                                                  β•‘
β•‘  🟑 MEDIUM (5)                                                   β•‘
β•‘  └─ 5 devices missing NTP configuration                         β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

πŸ—οΈ Project Structure

network-config-backup/
β”œβ”€β”€ network_backup.py        # Main backup script
β”œβ”€β”€ inventory.yaml           # Device inventory
β”œβ”€β”€ config/
β”‚   └── settings.yaml        # Global settings
β”œβ”€β”€ rules/
β”‚   β”œβ”€β”€ security.yaml        # Security compliance rules
β”‚   β”œβ”€β”€ best-practices.yaml  # Best practice checks
β”‚   └── pci-dss.yaml        # PCI-DSS requirements
β”œβ”€β”€ backups/                 # Git-versioned backups
β”‚   β”œβ”€β”€ datacenter/
β”‚   β”‚   β”œβ”€β”€ core-router-01.cfg
β”‚   β”‚   └── core-router-02.cfg
β”‚   └── branch/
β”‚       └── branch-router-01.cfg
β”œβ”€β”€ reports/
β”‚   └── compliance_YYYYMMDD.html
β”œβ”€β”€ templates/
β”‚   └── report.html.j2       # Report template
└── requirements.txt

πŸ” Security Best Practices

Practice Implementation
Credential Storage Use environment variables or HashiCorp Vault
SSH Keys Prefer key-based authentication over passwords
Encryption Encrypt backup files at rest
Access Control Restrict backup directory permissions
Audit Trail Git commit history provides full audit trail
Secrets in Git Never commit credentials - use .gitignore

Environment Variables

# .env file (never commit this!)
NETWORK_USER=admin
NETWORK_PASSWORD=SecureP@ss123
VAULT_TOKEN=hvs.xxxxxxxxxxxxx
SLACK_WEBHOOK=https://hooks.slack.com/...

πŸ“… Scheduling Options

Cron Job (Linux)

# Run every 6 hours
0 */6 * * * /path/to/venv/bin/python /path/to/network_backup.py backup --all

# Daily at 2 AM
0 2 * * * /path/to/venv/bin/python /path/to/network_backup.py backup --all

Built-in Scheduler

# Run continuously with interval
python network_backup.py schedule --interval 6h --notify slack

Windows Task Scheduler

# Create scheduled task
schtasks /create /tn "NetworkBackup" /tr "python C:\backup\network_backup.py backup --all" /sc hourly /mo 6

πŸ”” Notifications

Slack Integration

# config/settings.yaml
notifications:
  slack:
    enabled: true
    webhook_url: ${SLACK_WEBHOOK}
    channel: "#network-alerts"
    on_change: true
    on_failure: true

Email Alerts

notifications:
  email:
    enabled: true
    smtp_server: smtp.company.com
    recipients:
      - netops@company.com
    on_change: true
    on_failure: true
    daily_summary: true

🀝 Contributing

Contributions are welcome! Please read our Contributing Guide for details.


πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘¨β€πŸ’» Author

Tamer Khalifa - Network Automation Engineer

CCIE LinkedIn GitHub


⭐ Star this repo if you find it useful! ⭐

About

Multi-vendor network configuration backup tool with Git versioning, change detection, compliance auditing, and automated scheduling for Cisco, Juniper, Arista, and Palo Alto devices

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages