How cesaremiliano79/backups works
1. Overall shape
This is a small, single-purpose Python 3.10+ command-line utility. The repository has one executable script, backup.py, plus an external config.json that controls behavior. There is no service layer, database, or UI; the architecture is centered on filesystem traversal and copy/restore operations.
2. Primary runtime boundary
The program runs on Windows and operates entirely through the local filesystem and Windows network shares. Its main external boundary is a destination folder that can be either a local path or a UNC share on another machine in the LAN. The backup target is expected to support read/write access over the network.
3. Entry points / modes
There are two operating modes exposed through the console:
- default execution: create backups
- restaurar: restore the latest backup
This makes the script behave like a small command dispatcher inside one process rather than separate tools.
4. Configuration subsystem
config.json is the core control plane. It defines:
- source directories to scan
- destination path
- allowed file extensions
- maximum retained versions per source folder
- log file location
- user identity placeholder support via Windows environment variables
The config is an explicit boundary between code and deployment environment, which is important for diagramming because it determines where data is read from and written to.
5. Source discovery and path resolution
Source paths are not hardcoded to a specific username. Instead, the tool resolves %USERNAME% and %USERPROFILE% at runtime so it can adapt to the logged-in Windows account. This means the scanner operates on user-profile-relative folders like Desktop and Documents, regardless of machine or account name.
6. File selection and filtering
The backup process walks each configured source tree recursively, but only includes files whose extensions appear in extensiones_permitidas. This acts as a filter stage before any copying occurs, reducing irrelevant data movement and narrowing the backup set to business-relevant documents.
7. Change detection
The program uses MD5 hashes to compare file contents. Hashing is the key mechanism for detecting:
- unchanged files during backup
- files that should not be overwritten during restore unless they differ
- file-level differences across versions
This makes the system content-aware rather than relying only on timestamps.
8. Backup storage model
Each run creates a dated versioned folder under the destination. The folder name combines the source folder name and a timestamp, creating a version history per source directory. This is a simple snapshot model: each backup run produces a new immutable version folder, and old versions are later pruned when the maximum count is exceeded.
9. Retention and cleanup
max_versiones defines the retention policy per source folder. When the number of backups exceeds this limit, older versions are deleted. This is a dedicated housekeeping step in the backup flow and should be shown as a post-processing stage in the architecture diagram.
10. Logging and observability
The tool writes an execution log to a configured text file. The log records:
- backed up files and timestamps
- ignored files due to extension rules
- deleted old versions
- unchanged files detected by MD5
- total space used at completion
This is the only persistent operational telemetry in the system and acts as the audit trail.
11. Restore path
In restore mode, the program locates the most recent backup for each source folder and copies files back to their original locations. Restoration is selective: it only overwrites files whose hashes differ, reducing unnecessary churn and preserving unchanged local files.
12. Infrastructure assumptions
The design assumes a Windows LAN environment, often with a shared folder on another computer or server. The README’s use of UNC paths and cmdkey indicates the destination may be protected by network credentials. There is no cloud dependency; the architecture is explicitly local-network-first.
13. Packaging / deployment
The repo is intended to run either as a Python script or as a standalone Windows executable built with PyInstaller. In executable mode, backup.exe and config.json are deployed together, which makes configuration external to the binary and keeps the deployment portable.
14. Key architectural boundaries to draw
For a diagram, the important boundaries are:
- user/operator invoking CLI
- backup.py orchestration layer
- config.json configuration input
- source directories on the local machine
- destination backup folder or network share
- log file output
The main data flow is source scan → filter → hash compare → copy/version → log, with restore using the reverse path back to the original source locations.
Main entry points: backup.py backup.py · config.json config.json
Components 16
Runtime
CLI orchestration and execution flow inside backup.py
- CLI user · Invokes backup or restore mode from the console
- backup.py · Single entry script that coordinates backup and restore flows
backup.py - Mode dispatch · Selects default backup or restaurar restore mode
- Extension filter · Keeps only files whose extensions are allowed by configuration
- Scanner · Traverses each source tree to discover candidate files
- MD5 compare · Hashes files to detect unchanged content and restore differences
- Retention · Deletes older backup versions beyond max_versiones
- Restore flow · Finds latest backup and copies differing files back to original locations
Storage
Local source paths, backup destination, and log output
- Source trees · Configured user-profile-relative folders scanned recursively
- Version store · Creates dated per-source backup folders under the destination
- Backup target · Destination folder or Windows network share used for versioned backups
- Execution log · Writes backed up, ignored, unchanged, deleted, and total-space records
- Log file · Configured persistent output for operational audit trail
- Windows FS · Local filesystem and UNC network-share access boundary
Config
External configuration and environment resolution
- Path resolve · Expands %USERNAME% and %USERPROFILE% into concrete Windows paths
- config.json · External control plane for sources, destination, extensions, retention, and logging
config.json
Connections 21
- CLI user → backup.py: run · User starts the script from the console
- backup.py → Mode dispatch: choose mode · Dispatches between backup and restaurar modes
- Mode dispatch → Path resolve: load config · Reads runtime settings and expands environment placeholders
- Path resolve → config.json: read · Configuration is the external control plane
- Mode dispatch → Scanner: backup · Default mode scans source trees for files to copy
- Scanner → Source trees: traverse · Recursively walks configured source folders
- Scanner → Extension filter: filter · Drops files whose extensions are not permitted
- Extension filter → MD5 compare: check content · Allowed files are compared by MD5
- MD5 compare → Version store: new or changed · Changed content is written into a new version folder
- Version store → Backup target: store · Creates dated snapshot folders under the destination
- Version store → Execution log: record · Logs copied files and run summary
- Scanner → Execution log: ignore/track · Logs skipped files and unchanged files
- Version store → Retention: prune · Enforces per-source maximum retained versions
- Retention → Backup target: delete old · Removes outdated snapshot folders from the backup target
- Mode dispatch → Restore flow: restore · Restore mode reverses the flow toward original paths
- Restore flow → Backup target: read latest · Loads the most recent backup version for each source
- Restore flow → MD5 compare: compare · Only overwrites files whose hashes differ
- Restore flow → Source trees: restore to · Copies files back to their original source locations
- Restore flow → Execution log: record · Logs restore actions and outcomes
- Execution log → Log file: write · Persists the audit trail to the configured text file
- backup.py → Windows FS: operate on · All file movement happens through the local filesystem or UNC share