Interactive, single-file incremental backup tool with encryption, checksums, retention and restore—all in your terminal.
backup_main.py is an interactive, single-file CLI backup utility for Linux. It captures incremental snapshots, compresses changed files into tar.gz (or pigz), encrypts them with GPG, verifies integrity via SHA256, and auto-rotates old backups. A menu-driven interface simplifies configuration and restore.
- Overview
- Features
- Prerequisites
- Installation
- Configuration
- Usage
- Exclude Patterns
- Logging
- Email Notifications
- .backupignore Support
- Contributing
- License
- Author
backup_main.py is an all-in-one, interactive CLI utility for Linux (Debian/Ubuntu). It provides:
- Incremental backups based on file modification times
- Compressed archives (
.tar.gz) or parallel compression withpigz - GPG encryption of archives
- SHA256 checksums for integrity verification
- Automatic retention (rotation) of old backups
- Interactive restore of encrypted backups
- Persistent configuration stored in
~/.config/backup_main/config.json - Exclude patterns and
.backupignoresupport - Console and rotating file logging
- Optional email notifications on success or failure
Everything runs from a simple menu—no separate modules, just one file!
- Interactive Menu: Configure, run backup and restore without memorizing flags
- Persistent Config: Your settings saved in
~/.config/backup_main/config.json - Incremental Snapshots: Only changed or new files are archived
- Compression Options: Native
tar.gzor fasterpigzif installed - GPG Encryption: Secure archives with your GPG key
- Checksums: SHA256 record saved alongside each
.gpgfile - Retention: Automatically delete backups older than configured days
- Restore: List and decrypt any backup to a target folder
- Exclude Patterns: Filter out files or directories by glob pattern
- .backupignore: Place patterns in source dir for project-specific ignores
- Logging: Combines console output with daily rotating log files
- Email Alerts: SMTP notifications for success or failure
- Python 3.8+
- GPG (
gnupg) command-line tool - (Optional)
pigzfor parallel compression - An existing GPG key pair (public key on the machine for encryption)
- SMTP server credentials if you want email notifications
- Clone the repo
git clone https://github.com/bocaletto-luca/backup_main.py.git cd backup_main.py - Install the Python dependency
pip install python-gnupg
- Make the script executable
chmod +x backup_main.py
-
Launch the script
./backup_main.py
-
Select 1) Configure settings
-
Enter:
- Source directory (e.g.
/home/user/projects) - Backup directory (e.g.
~/backups) - GPG key ID (the public key for encryption)
- Retention days (how long to keep
.gpgbackups) - Exclude patterns (comma-separated globs)
- Log level (
DEBUG,INFO,WARN) - SMTP settings (server, port, username, password, from/to)
- Source directory (e.g.
-
The tool saves all settings to
~/.config/backup_main/config.json.
From the menu, choose 2) Run backup.
The script will:
- Load your config and verify paths/GPG key
- Scan source dir and load previous snapshot
- Archive only changed files to
bkp_<timestamp>.tar.gz - Encrypt archive to
bkp_<timestamp>.tar.gz.gpg - Generate
bkp_<timestamp>.tar.gz.gpg.sha256 - Delete old backups beyond retention
- Log actions and send optional email
From the menu, choose 3) Restore archive.
You will see a numbered list of encrypted backups.
Select one, then specify a restore folder.
The script will:
- Decrypt to a temporary
.tar.gz - Extract contents into your target directory
- Clean up temporary files
You can filter out files or directories by glob pattern. Examples:
*.tmpcache/***/*.log
Enter patterns in the configuration step (comma-separated).
Additionally, place a .backupignore file in your source directory to version-control ignore rules.
- Console: real-time INFO/WARN/DEBUG messages
- File:
backup.login your backup directory, rotated daily - Backup count: log files retained based on your retention setting
On each backup run (success or failure), you can send an email alert:
- SMTP server and credentials in config
- From and To addresses
- Subject indicates
[OK]or[FAIL]plus timestamp
Create a file named .backupignore in your source directory:
# ignore temp files
*.tmp
# ignore cache folder
cache/
These patterns are merged with your global exclude list.
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Commit and push your changes
- Open a Pull Request
For major changes, open an issue first to discuss.
This project is licensed under the GPL License.
Luca Bocaletto (@bocaletto-luca)
Interactive backup enthusiast, Python developer.