The Backup Checker is a web application that monitors server backups by:
- Scanning network for available servers using nmap
- Scanning specified directories for backup files
- Matching backup files to servers based on hostname/IP
- Displaying backup status in a web interface
class DatabaseManager:
# Initialize SQLite database with two tables:
# 1. scanned_files: Store backup file information
# - id, filename, filepath, last_modified, size, scan_time
# 2. scanned_servers: Store discovered server information
# - id, hostname, ip_address, detected_os, open_ports, last_scan, is_reachable, scan_time
def add_scanned_file(filename, filepath, last_modified, size):
# Insert or update file record in database
# Return file_id
def add_scanned_server(hostname, ip, os, ports):
# Insert or update server record in database
# Return server_id
def get_all_scanned_files():
# Return all files from database
def get_all_servers():
# Return all servers from database
def clear_scanned_files():
# Delete all file records
def clear_scanned_servers():
# Delete all server records
class DirectoryScanner:
def scan_directories():
# 1. Load directories from config.json
# 2. For each configured directory:
# - Walk through directory recursively
# - For each file found:
# * Get file metadata (name, path, modified time, size)
# * Store in database via DatabaseManager
# 3. Return list of all found files
class SubnetScanner:
def scan_subnets():
# 1. Load subnets from config.json
# 2. For each subnet:
# - Use nmap to scan network
# - For each host found:
# * Get hostname, IP, OS, open ports
# * Store in database via DatabaseManager
# 3. Return list of all found servers
# Flask REST API endpoints:
@app.route('/api/files', methods=['GET'])
def get_files():
# 1. Get all files from database
# 2. Format timestamps and metadata
# 3. Return JSON response
@app.route('/api/servers', methods=['GET'])
def get_servers():
# 1. Get all servers from database
# 2. Get all files from database
# 3. For each server:
# - Find matching backup files (by hostname/IP)
# - Determine backup status:
# * GREEN = backup < 1 year old
# * YELLOW = backup exists but > 1 year old
# * RED = no backup found
# 4. Return JSON response
@app.route('/api/scan/directories', methods=['POST'])
def scan_directories():
# 1. Create DirectoryScanner
# 2. Run scan
# 3. Return success/failure response
@app.route('/api/scan/servers', methods=['POST'])
def scan_servers():
# 1. Create SubnetScanner
# 2. Run scan
# 3. Return success/failure response
@app.route('/api/config', methods=['GET', 'PUT'])
def handle_config():
# GET: Return current config
# PUT: Update config with new values
function BackupStatus():
// 1. On component mount:
// - Fetch servers and files from API
// - Format data for display
// 2. Render data grid showing:
// - Hostname
// - IP Address
// - OS
// - Backup File
// - Backup Time
// - Status (with color-coded chip)
// 3. Allow sorting and filtering
// 4. Provide CSV/Excel export
function Servers():
// 1. Display list of discovered servers
// 2. Show server details:
// - Hostname
// - IP
// - OS
// - Open ports
// 3. Provide "Scan Servers" button
// 4. Allow CSV export
function Files():
// 1. Display list of discovered backup files
// 2. Show file details:
// - Filename
// - Path
// - Size
// - Last modified
// 3. Allow CSV export
function Directories():
// 1. Display configured scan directories
// 2. Provide "Scan Directories" button
// 3. Show scan results
function DataTable(data, columns):
// 1. Render MUI DataGrid with:
// - Sortable columns
// - Status filtering
// - Export buttons
// 2. Handle background colors based on status
// 3. Format dates and sizes
function ScanButton(onClick):
// 1. Show loading state during scan
// 2. Handle errors
// 3. Provide visual feedback
1. Check and install dependencies (nmap)
2. Start backend service:
- Run Flask app on port 5000
- Initialize database if needed
3. Start frontend service:
- Run npm dev server
4. Handle cleanup on shutdown
1. User initiates scan (manual or scheduled):
a. Server Scan:
- Scan configured subnets with nmap
- Store results in database
b. Directory Scan:
- Scan configured directories
- Store file info in database
2. Frontend periodically:
- Fetches updated data
- Updates UI with new status
- Shows warnings for old/missing backups
For each server:
1. Find backup files matching hostname/IP
2. Get most recent backup's age
3. Determine status:
- GREEN: backup < 1 year old
- YELLOW: backup exists but > 1 year old
- RED: no backup found
4. Update UI with status and details
{
"directories_to_scan": [
"./example/nas01/",
"./example/nas02/"
],
"subnets_to_scan": [
"172.17.0.0/24",
"10.197.38.0/24"
]
}
CREATE TABLE scanned_files (
id INTEGER PRIMARY KEY AUTOINCREMENT,
filename TEXT NOT NULL,
filepath TEXT NOT NULL,
last_modified TIMESTAMP,
size INTEGER,
scan_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
CREATE TABLE scanned_servers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
hostname TEXT NOT NULL,
ip_address TEXT,
detected_os TEXT,
open_ports TEXT,
last_scan TIMESTAMP,
is_reachable BOOLEAN,
scan_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
- Requires root access for nmap scanning
- Database file permissions set to 666 for shared access
- CORS enabled for development
- No authentication implemented yet
- Backup file matching based on hostname/IP in filename
- No standardized backup filename format
- SQLite database (not suitable for large deployments)
- Root access requirement for nmap