A lightweight, resource-optimized Go utility for creating scheduled backups of any folder with automatic retention management.
This tool creates timestamped ZIP archives of any specified folder and maintains a configurable backup history. Originally created for backing up Obsidian vaults, it works with any directory you need to preserve. The utility is specifically optimized to use minimal system resources, making it ideal for background operation via task schedulers.
- Creates ZIP backups of any folder with minimal resource usage
- Resource-optimized: Low CPU priority, single-core usage, minimal memory footprint
- Names backups with precise timestamps for easy identification
- Configurable backup retention (easily adjustable via constants)
- Simple configuration through constants at the top of the code
- Minimal dependencies
- Cross-platform (Windows, macOS, Linux)
- Optimized for background operation and task scheduling
- Go 1.16 or higher
# Clone the repository
git clone https://github.com/binge-coder/Folder-Backup-Utility.git
cd Folder-Backup-Utility
# Install dependencies (automatically fetches required packages)
go mod download
All configuration is done through constants at the top of backup-script.go
for easy modification:
// Configuration constants - modify these as needed
const (
SOURCE_FOLDER_PATH = `C:\path\to\your\folder` // Folder you want to back up
BACKUP_FOLDER_PATH = `C:\path\to\backup\storage` // Where backups will be stored
MAX_BACKUPS_TO_KEEP = 3 // Maximum number of backup files to keep
)
Simply update these constants to match your requirements:
SOURCE_FOLDER_PATH
: The folder you want to backupBACKUP_FOLDER_PATH
: Where backup files will be storedMAX_BACKUPS_TO_KEEP
: How many recent backups to maintain (older ones are automatically deleted)
# Build the executable
go build -ldflags="-s -w" -o backup-script.exe backup-script.go
# Run the backup
./backup-script.exe
Use Task Scheduler for optimal resource management:
- Open Task Scheduler
- Create a new task
- Set the trigger (daily/weekly/etc.)
- Action: Start a program
- Browse to your
backup-script.exe
location - In "Conditions" tab, check "Start the task only if the computer is on AC power" (optional)
- In "Settings" tab, check "Run task as soon as possible after a scheduled start is missed"
Note: The script automatically sets itself to low priority and uses minimal resources, making it ideal for background operation.
Use cron:
# Edit crontab
crontab -e
# Add a line to run daily at 2 AM, for example:
0 2 * * * /path/to/backup-script
- Resource Optimization: Sets low CPU priority and limits to single core usage
- Backup Creation: Creates the backup folder if it doesn't exist
- Archive Generation: Generates a timestamped ZIP file with minimal compression for speed
- Cleanup: Counts existing backups and removes the oldest ones based on
MAX_BACKUPS_TO_KEEP
- Resource Management: Uses frequent garbage collection and brief pauses to minimize system impact
- CPU Usage: Limited to single core with low priority
- Memory Usage: Optimized with frequent garbage collection
- Compression: Disabled for faster operation and lower CPU usage
- I/O: Throttled with small delays between operations
- Background Friendly: Designed to run without impacting system performance
The script uses the mholt/archiver library for creating ZIP archives. All dependencies will be automatically downloaded when you run go mod download
.
Resource Optimization Settings:
- Compression is disabled for faster operation
- Single CPU core usage to avoid system slowdown
- Low process priority on Windows
- Frequent garbage collection to minimize memory usage
- I/O throttling with small delays between operations
These settings prioritize system responsiveness over backup speed, making it ideal for scheduled background operation.
This project is open source and available under the MIT License.