A personal bash-based solution for creating full system backups and performing selective restoration of Ubuntu/Debian systems. Originally created during a system crash emergency, the updated and documented for github.
Current Phase: Testing Suite Development
Script Status: Core functionality complete, working towards comprehensive testing
Documentation: In progress
This suite consists of two complementary scripts that work together to provide complete system backup and restoration capabilities. Originally written in a situation to recover from a crashed system, these scripts have been improved and refined over the years for personal use. The documentation and testing framework have been added post-creation to make the code shareable nd deployable.
Repository: https://github.com/sudo-haggis/backup-n-restore
- Package Management: Captures installed packages (APT, Snap, Flatpak)
- System Configuration: Backs up cron jobs, system files, and repository configurations
- Home Directory Archive: Compressed backup with intelligent exclusions for cache/temp files
- Size Optimization: Excludes common large directories (node_modules, build dirs, caches)
- Progress Monitoring: Real-time feedback during long-running operations
- Timing Reports: Performance metrics for each backup operation
- Interactive Package Restoration: Choose which package sets to reinstall
- Selective Home Recovery: Granular control over user directory restoration
- Repository Management: Restore APT sources and custom repositories
- Error Handling: Failed package tracking and reporting
- Safety Confirmations: Multiple prompts prevent accidental overwrites
- User Selection: Choose specific users and directories to restore
- OS: Ubuntu 16.04+ / Debian 9+ (tested on Ubuntu 20.04+)
- Shell: Bash 4.0+
- Privileges: sudo access required
- Storage: External drive recommended for backups
tar
(compression/extraction)dpkg
(package management)apt
/apt-mark
(package installation)snap
(if using Snap packages)flatpak
(if using Flatpak - optional)mount
/umount
(file system operations)
# Clone the repository
git clone https://github.com/sudo-haggis/backup-n-restore.git
cd backup-n-restore
# Make scripts executable
chmod +x backup_script.sh
chmod +x restoration_script.sh
# Run with sudo privileges
sudo ./backup_script.sh
# The script will:
# 1. Mount the specified system partition
# 2. Create timestamped backup directory
# 3. Backup packages, configurations, and cron jobs
# 4. Optionally backup home directories (interactive prompt)
Backup Structure:
BACKUP_YY-MM-DD/
├── installed_packages.txt # All installed packages
├── manual_packages.txt # Manually installed packages
├── snap_packages.txt # Snap package list
├── user_crontab.txt # User cron jobs
├── etc/ # System configuration files
├── home_backup.tar.gz # Compressed home directories
└── home_backup_repost.txt # Backup summary report
# Run restoration script with backup directory
sudo ./restoration_script.sh /path/to/backup/directory
# Interactive options:
# - Choose which package types to restore
# - Select specific home directories
# - Preview package lists before installation
# - Granular user and directory selection
- Target: Dedicated test machine with Ubuntu 22.04
- Test Data: Simulated user environments with various package configurations
- Scenarios: Fresh installs, partial system corruption, migration testing
- Full system backup and restoration
- Selective package restoration
- Home directory recovery scenarios
- Cross-version Ubuntu migration
- Error handling and recovery procedures
- Performance benchmarking with various data sizes
- Edge cases (missing dependencies, permission issues)
Testing documentation will be updated as comprehensive testing progresses
CRITICAL - READ BEFORE USE:
- These scripts perform destructive operations on system files
- NEVER run on production systems without thorough testing
- Always test restoration procedures in isolated environments first
- Backup operations require significant disk space and time
- Home directory restoration WILL OVERWRITE existing files
- Ensure adequate free space before starting backup operations
File | Purpose |
---|---|
backup_script.sh |
Main backup script - creates comprehensive system snapshots |
restoration_script.sh |
Restoration script - selective recovery from backups |
README.md |
Project documentation and usage guide |
tests/ |
Testing scripts and documentation (planned) |
Current Focus: Establishing proper testing procedures on dedicated hardware to validate functionality and document real-world performance. The scripts work for personal use but need comprehensive testing before broader sharing.
- Personal Tool: Originally created for personal system recovery, improved over time for multi-machine use
- Ubuntu Focus: Scripts optimized for Ubuntu/Debian systems based on personal usage patterns
- Storage Requirements: Home directory backups can be substantial - plan accordingly
- Recovery Time: Full restoration may take several hours depending on data size
- Network Requirements: Package restoration requires internet connectivity
- Documentation Added Later: Testing framework and documentation created post-hoc to enable sharing
MIT License - feel free to use, modify, and share as needed.
⚡ Remember: These tools were born from necessity - test thoroughly before trusting with important data!