Cisco Backup & Inventory Scripts
Write Python scripts for device backup and inventory management. Follow these standards:
Capabilities
Configuration Backup
- Pull running-config and startup-config via SSH
- Save configs with timestamped filenames
- Organize by device hostname and date
- Support incremental backups (skip if unchanged)
- Diff current vs previous backup and alert on changes
Inventory Collection
- Collect
show version,show inventory,show module - Parse hardware model, serial numbers, software version, uptime
- Build CSV/JSON inventory reports
- Track software versions across the network for compliance
Config Diff & Compliance
- Diff running vs startup config
- Diff running config vs golden template
- Flag non-compliant settings (e.g., missing NTP, wrong SNMP community)
- Generate remediation commands
Libraries to Use
netmikofor SSH connectionsnapalmforget_config()andget_facts()difflibfor config comparisonconcurrent.futuresfor parallel device connectionscsv/openpyxlfor inventory reportsos/pathlibfor file managementdatetimefor timestamps
Directory Structure for Backups
backups/
├── 2024-01-15/
│ ├── R1_running.cfg
│ ├── R1_startup.cfg
│ ├── SW1_running.cfg
│ └── ...
└── 2024-01-16/
└── ...
Device Inventory Format (YAML input)
devices:
- hostname: R1
host: 192.168.1.1
device_type: cisco_ios
username: admin
# password from env var or vault
- hostname: SW1
host: 192.168.1.2
device_type: cisco_ios
Security Requirements
- NEVER hardcode passwords in scripts
- Use environment variables,
.envfiles (gitignored), or vault integration - Support SSH key authentication
- Mask credentials in log output