Practice Targets Review (Backup Automation, Scan Tools)
🏷️ Final Capstone Engineer Script project / Next Steps After This Curriculum
🧭 Context Introduction
Throughout this curriculum, you have built foundational Python skills by working through real-world automation scenarios. Now, it is time to shift your focus toward two critical practice targets that will solidify your understanding and prepare you for larger-scale engineering projects: Backup Automation and Scan Tools. These targets are not just exercises—they represent the types of tasks you will encounter daily in production environments. By mastering these, you will gain confidence in writing scripts that are reliable, maintainable, and safe to run in live systems.
⚙️ Practice Target 1: Backup Automation
Backup automation is one of the most common and valuable applications of Python scripting. The goal here is to create scripts that can copy, compress, and archive important files or directories, while also handling errors gracefully and logging results for later review.
Key concepts to practice:
- File and directory traversal – Using modules like os and shutil to walk through folder structures and identify files that need to be backed up.
- Compression and archiving – Creating .zip or .tar.gz archives using the zipfile or tarfile modules.
- Timestamping – Appending date and time strings to backup filenames so you never overwrite an older backup.
- Error handling – Wrapping file operations in try-except blocks to catch permission errors, missing files, or disk space issues.
- Logging – Writing backup status (success, failure, file count, size) to a .log file using the logging module.
What a successful backup script should do:
- Accept a source directory and a destination directory as inputs.
- Create a compressed archive of the source directory.
- Name the archive with the current date and time.
- Log the start time, end time, file count, and total size.
- Handle errors like missing source paths or insufficient disk space without crashing.
🛠️ Practice Target 2: Scan Tools
Scan tools are scripts that examine systems, networks, or files for specific patterns, configurations, or vulnerabilities. They are essential for monitoring, compliance, and security tasks. Building your own scan tools will teach you how to parse data, make network connections, and generate reports.
Key concepts to practice:
- Port scanning – Using the socket module to attempt connections to a range of IP addresses and ports, identifying which ports are open.
- File scanning – Reading through log files or configuration files to find specific keywords, error codes, or patterns using regular expressions (re module) .
- System scanning – Gathering system information like disk usage, running processes, or environment variables using os, psutil, or platform.
- Result formatting – Outputting scan results in a clean, readable format, either to the console or to a .csv or .json file for further analysis.
- Rate limiting and timeouts – Adding delays between connection attempts and setting timeouts to avoid overwhelming a network or getting stuck on unresponsive hosts.
What a successful scan tool should do:
- Accept a target (IP range, file path, or directory) as input.
- Perform the scan with clear progress indicators.
- Collect results and store them in a structured format.
- Handle common errors like connection timeouts, permission denials, or malformed input.
- Provide a summary at the end showing how many items were scanned and how many matched the criteria.
📊 Comparison Table: Backup Automation vs. Scan Tools
| Feature | Backup Automation | Scan Tools |
|---|---|---|
| Primary Goal | Preserve data by creating copies | Discover information or anomalies |
| Key Modules | os, shutil, zipfile, tarfile, logging | socket, re, os, psutil, csv, json |
| Common Output | Compressed archive files + log file | Console report, CSV, or JSON file |
| Error Handling Focus | Missing files, disk full, permissions | Timeouts, unreachable hosts, bad data |
| Safety Consideration | Never overwrite existing backups | Avoid overwhelming target systems |
| Typical Schedule | Daily or weekly cron jobs | On-demand or scheduled audits |
🕵️ Why These Two Targets Matter
Backup automation and scan tools represent opposite ends of a critical spectrum in engineering work:
- Backup automation is about preservation and recovery. It teaches you to write scripts that must be reliable above all else. A failed backup can mean lost data, so your error handling and logging must be thorough.
- Scan tools are about discovery and awareness. They teach you to interact with systems and networks, parse unstructured data, and present findings clearly. A good scan tool helps engineers understand what is running, what is exposed, and what needs attention.
By practicing both, you will develop a balanced skill set that covers data safety and system visibility—two pillars of professional engineering scripting.
✅ Final Thoughts for Practice
As you work through these practice targets, keep the following principles in mind:
- Start small – Begin with a single directory backup or a single-port scan before expanding to full automation.
- Test with safe targets – Use test folders and localhost IPs until your script is stable.
- Read your logs – After each run, check the log file to understand what happened and where improvements are needed.
- Refactor and reuse – Once a script works, look for ways to make it more flexible (e.g., using command-line arguments or configuration files).
- Document your code – Add comments and a brief README so that you (or another engineer) can understand the script months later.
These two practice targets will serve as the foundation for more advanced projects, including multi-server orchestration, cloud resource management, and automated incident response. Master them now, and you will be ready for whatever comes next.
This file reviews two practice targets—backup automation and scan tools—showing how Python can automate file backups and run network or system scans.
🛠️ Example 1: Simple File Copy Backup
This example shows how to copy a single file to a backup folder using shutil.
import shutil
import os
source_file = "config.txt"
backup_folder = "backups"
os.makedirs(backup_folder, exist_ok=True)
shutil.copy(source_file, backup_folder)
📤 Output: config.txt copied into backups/ folder
🛠️ Example 2: Timestamped Backup Name
This example shows how to add a timestamp to the backup filename to avoid overwriting.
import shutil
import os
from datetime import datetime
source_file = "config.txt"
backup_folder = "backups"
os.makedirs(backup_folder, exist_ok=True)
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
backup_name = f"config_backup_{timestamp}.txt"
shutil.copy(source_file, os.path.join(backup_folder, backup_name))
📤 Output: config_backup_20250321_143022.txt created in backups/
🛠️ Example 3: Backup All Files in a Directory
This example shows how to back up every file from one folder into a backup folder.
import shutil
import os
source_dir = "project_files"
backup_dir = "backups/project_files_backup"
os.makedirs(backup_dir, exist_ok=True)
for filename in os.listdir(source_dir):
full_path = os.path.join(source_dir, filename)
if os.path.isfile(full_path):
shutil.copy(full_path, backup_dir)
📤 Output: All files from project_files copied into backups/project_files_backup/
🛠️ Example 4: Ping Scan a List of IP Addresses
This example shows how to use subprocess to ping multiple IPs and report which are reachable.
import subprocess
ip_list = ["192.168.1.1", "192.168.1.10", "8.8.8.8"]
for ip in ip_list:
result = subprocess.run(["ping", "-c", "1", ip], capture_output=True, text=True)
if result.returncode == 0:
print(f"{ip} is reachable")
else:
print(f"{ip} is unreachable")
📤 Output:
192.168.1.1 is reachable
192.168.1.10 is unreachable
8.8.8.8 is reachable
🛠️ Example 5: Port Scan a Single Host
This example shows how to check if common ports are open on a target host using socket.
import socket
target_host = "192.168.1.1"
ports_to_scan = [22, 80, 443, 8080]
for port in ports_to_scan:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex((target_host, port))
if result == 0:
print(f"Port {port} is open")
else:
print(f"Port {port} is closed")
sock.close()
📤 Output:
Port 22 is open
Port 80 is open
Port 443 is closed
Port 8080 is closed
Comparison Table: Backup Automation vs Scan Tools
| Feature | Backup Automation | Scan Tools |
|---|---|---|
| Purpose | Copies and preserves files | Checks network or system status |
| Key Python modules | shutil, os, datetime |
subprocess, socket |
| Common outputs | New files in backup folders | Reachable/unreachable, open/closed ports |
| Typical use case | Daily file protection | Network troubleshooting or security checks |
🧭 Context Introduction
Throughout this curriculum, you have built foundational Python skills by working through real-world automation scenarios. Now, it is time to shift your focus toward two critical practice targets that will solidify your understanding and prepare you for larger-scale engineering projects: Backup Automation and Scan Tools. These targets are not just exercises—they represent the types of tasks you will encounter daily in production environments. By mastering these, you will gain confidence in writing scripts that are reliable, maintainable, and safe to run in live systems.
⚙️ Practice Target 1: Backup Automation
Backup automation is one of the most common and valuable applications of Python scripting. The goal here is to create scripts that can copy, compress, and archive important files or directories, while also handling errors gracefully and logging results for later review.
Key concepts to practice:
- File and directory traversal – Using modules like os and shutil to walk through folder structures and identify files that need to be backed up.
- Compression and archiving – Creating .zip or .tar.gz archives using the zipfile or tarfile modules.
- Timestamping – Appending date and time strings to backup filenames so you never overwrite an older backup.
- Error handling – Wrapping file operations in try-except blocks to catch permission errors, missing files, or disk space issues.
- Logging – Writing backup status (success, failure, file count, size) to a .log file using the logging module.
What a successful backup script should do:
- Accept a source directory and a destination directory as inputs.
- Create a compressed archive of the source directory.
- Name the archive with the current date and time.
- Log the start time, end time, file count, and total size.
- Handle errors like missing source paths or insufficient disk space without crashing.
🛠️ Practice Target 2: Scan Tools
Scan tools are scripts that examine systems, networks, or files for specific patterns, configurations, or vulnerabilities. They are essential for monitoring, compliance, and security tasks. Building your own scan tools will teach you how to parse data, make network connections, and generate reports.
Key concepts to practice:
- Port scanning – Using the socket module to attempt connections to a range of IP addresses and ports, identifying which ports are open.
- File scanning – Reading through log files or configuration files to find specific keywords, error codes, or patterns using regular expressions (re module) .
- System scanning – Gathering system information like disk usage, running processes, or environment variables using os, psutil, or platform.
- Result formatting – Outputting scan results in a clean, readable format, either to the console or to a .csv or .json file for further analysis.
- Rate limiting and timeouts – Adding delays between connection attempts and setting timeouts to avoid overwhelming a network or getting stuck on unresponsive hosts.
What a successful scan tool should do:
- Accept a target (IP range, file path, or directory) as input.
- Perform the scan with clear progress indicators.
- Collect results and store them in a structured format.
- Handle common errors like connection timeouts, permission denials, or malformed input.
- Provide a summary at the end showing how many items were scanned and how many matched the criteria.
📊 Comparison Table: Backup Automation vs. Scan Tools
| Feature | Backup Automation | Scan Tools |
|---|---|---|
| Primary Goal | Preserve data by creating copies | Discover information or anomalies |
| Key Modules | os, shutil, zipfile, tarfile, logging | socket, re, os, psutil, csv, json |
| Common Output | Compressed archive files + log file | Console report, CSV, or JSON file |
| Error Handling Focus | Missing files, disk full, permissions | Timeouts, unreachable hosts, bad data |
| Safety Consideration | Never overwrite existing backups | Avoid overwhelming target systems |
| Typical Schedule | Daily or weekly cron jobs | On-demand or scheduled audits |
🕵️ Why These Two Targets Matter
Backup automation and scan tools represent opposite ends of a critical spectrum in engineering work:
- Backup automation is about preservation and recovery. It teaches you to write scripts that must be reliable above all else. A failed backup can mean lost data, so your error handling and logging must be thorough.
- Scan tools are about discovery and awareness. They teach you to interact with systems and networks, parse unstructured data, and present findings clearly. A good scan tool helps engineers understand what is running, what is exposed, and what needs attention.
By practicing both, you will develop a balanced skill set that covers data safety and system visibility—two pillars of professional engineering scripting.
✅ Final Thoughts for Practice
As you work through these practice targets, keep the following principles in mind:
- Start small – Begin with a single directory backup or a single-port scan before expanding to full automation.
- Test with safe targets – Use test folders and localhost IPs until your script is stable.
- Read your logs – After each run, check the log file to understand what happened and where improvements are needed.
- Refactor and reuse – Once a script works, look for ways to make it more flexible (e.g., using command-line arguments or configuration files).
- Document your code – Add comments and a brief README so that you (or another engineer) can understand the script months later.
These two practice targets will serve as the foundation for more advanced projects, including multi-server orchestration, cloud resource management, and automated incident response. Master them now, and you will be ready for whatever comes next.
Interactive Views
You are currently in 📚 All-in-One mode. Use the tabs at the top to switch to 📖 Theory Only or 💻 Code Only views.
This file reviews two practice targets—backup automation and scan tools—showing how Python can automate file backups and run network or system scans.
🛠️ Example 1: Simple File Copy Backup
This example shows how to copy a single file to a backup folder using shutil.
import shutil
import os
source_file = "config.txt"
backup_folder = "backups"
os.makedirs(backup_folder, exist_ok=True)
shutil.copy(source_file, backup_folder)
📤 Output: config.txt copied into backups/ folder
🛠️ Example 2: Timestamped Backup Name
This example shows how to add a timestamp to the backup filename to avoid overwriting.
import shutil
import os
from datetime import datetime
source_file = "config.txt"
backup_folder = "backups"
os.makedirs(backup_folder, exist_ok=True)
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
backup_name = f"config_backup_{timestamp}.txt"
shutil.copy(source_file, os.path.join(backup_folder, backup_name))
📤 Output: config_backup_20250321_143022.txt created in backups/
🛠️ Example 3: Backup All Files in a Directory
This example shows how to back up every file from one folder into a backup folder.
import shutil
import os
source_dir = "project_files"
backup_dir = "backups/project_files_backup"
os.makedirs(backup_dir, exist_ok=True)
for filename in os.listdir(source_dir):
full_path = os.path.join(source_dir, filename)
if os.path.isfile(full_path):
shutil.copy(full_path, backup_dir)
📤 Output: All files from project_files copied into backups/project_files_backup/
🛠️ Example 4: Ping Scan a List of IP Addresses
This example shows how to use subprocess to ping multiple IPs and report which are reachable.
import subprocess
ip_list = ["192.168.1.1", "192.168.1.10", "8.8.8.8"]
for ip in ip_list:
result = subprocess.run(["ping", "-c", "1", ip], capture_output=True, text=True)
if result.returncode == 0:
print(f"{ip} is reachable")
else:
print(f"{ip} is unreachable")
📤 Output:
192.168.1.1 is reachable
192.168.1.10 is unreachable
8.8.8.8 is reachable
🛠️ Example 5: Port Scan a Single Host
This example shows how to check if common ports are open on a target host using socket.
import socket
target_host = "192.168.1.1"
ports_to_scan = [22, 80, 443, 8080]
for port in ports_to_scan:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex((target_host, port))
if result == 0:
print(f"Port {port} is open")
else:
print(f"Port {port} is closed")
sock.close()
📤 Output:
Port 22 is open
Port 80 is open
Port 443 is closed
Port 8080 is closed
Comparison Table: Backup Automation vs Scan Tools
| Feature | Backup Automation | Scan Tools |
|---|---|---|
| Purpose | Copies and preserves files | Checks network or system status |
| Key Python modules | shutil, os, datetime |
subprocess, socket |
| Common outputs | New files in backup folders | Reachable/unreachable, open/closed ports |
| Typical use case | Daily file protection | Network troubleshooting or security checks |