By Fathalla Ramadan
February 2026
If you’re running a home lab with even two or three routers, you know the pain:
“I spent hours configuring OSPF… and forgot to save. Now it’s gone.”
What if your automate home lab backup devices backed itself up every night—automatically?
In this guide, you’ll set up a simple, reliable backup system using Python and Netmiko that:
- Connects to all your devices
- Saves configs as timestamped files
- Runs nightly with no manual effort
This is Lab 26.1 from my IP Routing and Switching Lab Handout Book—now shared free for serious learners.
Let’s build it.
Important Note (2026):
This script requires real SSH access to network devices.
- Cisco Packet Tracer does not support SSH — backups won’t work with PT.
- GNS3 + Cisco IOSv is not legally accessible for most learners.
- FRRouting in GNS3 may support SSH, but only if manually configured—and appliance availability is limited.
Best use case: Run this against physical gear, Cisco Modeling Labs (CML), or EVE-NG with licensed images.
For learning: Test the script logic first (“dry-run”), then deploy when you have real access.
What You’ll Need
- A Windows, macOS, or Linux computer (your “automation server”)
- Python 3 installed (see our Netmiko setup guide)
- Network devices accessible via SSH (e.g., physical routers, CML, or EVE-NG — not Packet Tracer)
- Basic Python familiarity (copy-paste friendly!)
Step 1: Install Required Libraries
Open your terminal or Command Prompt and run:
pip install netmiko python-dotenv
Step 2: Create a Secure Credentials File
In your project folder, create a file named .env:
USERNAME=admin
PASSWORD=cisco123
Never commit this file to GitHub! Add
.envto your.gitignore.
Step 3: Create the Backup Script
Create a file named backup_lab.py:
import os
from datetime import datetime
from dotenv import load_dotenv
from netmiko import ConnectHandler
Load credentials
load_dotenv()
username = os.getenv(“USERNAME”)
password = os.getenv(“PASSWORD”)
Define your devices
devices = [
{
“host”: “192.168.1.10”,
“device_type”: “cisco_ios”,
“username”: username,
“password”: password,
},
{
“host”: “192.168.1.11”,
“device_type”: “cisco_ios”,
“username”: username,
“password”: password,
},
# Add more devices as needed
]
Create backup directory
backup_dir = “backups”
os.makedirs(backup_dir, exist_ok=True)
Get timestamp
timestamp = datetime.now().strftime(“%Y-%m-%d_%H-%M-%S”)
Backup each device
for device in devices:
try:
print(f”Backing up {device[‘host’]}…”)
connection = ConnectHandler(**device)
hostname = connection.find_prompt().replace(“#”, “”)
config = connection.send_command(“show running-config”)
connection.disconnect()
# Save to file
filename = f"{backup_dir}/{hostname}_{timestamp}.txt"
with open(filename, "w") as f:
f.write(config)
print(f"✅ Saved: {filename}")
except Exception as e:
print(f"❌ Failed to back up {device['host']}: {str(e)}")Customize: Replace IP addresses and add your devices.
Step 4: Test the Script
Run it manually:
python backup_lab.py
You’ll see:
Backing up 192.168.1.10…
Saved: backups/R1_2026-02-13_20-30-00.txt
Check the backups/ folder—your configs are there!
Step 5: Automate It (Run Every Night)
On Windows: Use Task Scheduler
- Open Task Scheduler
- Create Basic Task → Name:
Nightly Lab Backup - Trigger: Daily at 2:00 AM
- Action: Start a program
- Program:
python - Arguments:
C:\path\to\backup_lab.py
- Program:
- Finish
On macOS/Linux: Use cron
Run crontab -e and add:
0 2 * * * /usr/bin/python3 /path/to/backup_lab.py
Now your lab backs up every night at 2 AM—without you lifting a finger.
Pro Tips
- Version control: Store backups in a private Git repo for change tracking
- Email alerts: Add SMTP code to email you on failure
- Expand: Add switches, firewalls, or wireless controllers
Go Further
Want the full Lab 26.1 with error handling, logging, email notifications, and multi-vendor support (Cisco, Juniper, Arista)?
Get it in my IP Routing and Switching Lab Handout Book—used by learners in 30+ countries.
Final Thought
Automation isn’t about replacing you.
It’s about freeing you from repetitive tasks—so you can focus on design, troubleshooting, and innovation.
And automate home lab backup devices all starts with one script.
—
Fathalla Ramadan
Network Architect & Educator
35+ years in IT, networking, and technology education across the Middle East and beyond
