Enterprise-grade backup automation utility with robust error handling and stream isolation.
-
Standard shell backup scripts (using cp or simple tar) often suffer from "Silent Failures"—where a script exits successfully even if partial data corruption occurred. The engineering challenge was to design a system that guarantees data integrity by strictly validating input states, enforcing atomic operations, and allowing granular control over file exclusions via .bassignore without hardcoding paths.
Logic Flow: Priority handling between CLI Args and Config Files
log_message() {
LEVEL=$1
MESSAGE=$2
TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")
LOG_ENTRY="${LEVEL}: [${TIMESTAMP}] ${MESSAGE}"
# Strict Stream Separation:
# Errors to stderr (fd2) for pipeline monitoring
# Info to stdout (fd1) for user feedback
if [ "$LEVEL" == "ERROR" ]; then
echo "${LOG_ENTRY}" >&2
else
echo "${LOG_ENTRY}"
fi
# Persistent audit trail
echo "${LOG_ENTRY}" >> "${LOG_FILE}"
}I chose Bash over Python for this specific tool to ensure zero-dependency portability across any Unix-based CI/CD environment. While Python offers better exception handling, Bash provides direct interaction with filesystem streams (tar pipes). To mitigate Bash's loose error handling, I implemented explicit exit code checks ($?) after every critical operation instead of relying on set -e, allowing for graceful cleanup routines.
Validated against 4 distinct input scenarios (Args, Config, Dry-run, Invalid)
The system implements Dual-Stream Logging. Critical failures (Missing Source, Permission Denied) are routed to stderr to break build pipelines immediately, while operational logs go to archive.log. Input validation logic prevents execution if target directories cannot be created or source is unreadable.
Replaced ad-hoc backup commands with a standardized, version-controlled utility. The introduction of dry-run mode allows teams to verify backup manifest generation without disk I/O, preventing accidental storage saturation. The .bassignore pattern matching reduced backup size by excluding temporary build artifacts automatically.