Skip to content

What it says on the tin, BASH based backup and restore script i wrote and used to save after a system crash one time.

License

Notifications You must be signed in to change notification settings

sudo-haggis/backup-n-restore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🏴‍☠️ System Backup & Restoration Suite

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.

🚧 Development Status

Current Phase: Testing Suite Development
Script Status: Core functionality complete, working towards comprehensive testing
Documentation: In progress

⚓ Overview

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

🧰 Features

Backup Script (backup_script.sh)

  • 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

Restoration Script (restoration_script.sh)

  • 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

🔧 Requirements

System Requirements

  • 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

Dependencies

  • 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)

📋 Installation

# 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

🚀 Usage

Creating System Backups

# 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

Restoring from Backups

# 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

🧪 Testing Status

Test Environment Setup

  • 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

Planned Test Cases

  • 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)

Current Test Results

Testing documentation will be updated as comprehensive testing progresses

⚠️ Safety Warnings

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

📁 Project Structure

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)

🔄 Development Plans

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.

📝 Notes

  • 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

📄 License

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!

About

What it says on the tin, BASH based backup and restore script i wrote and used to save after a system crash one time.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages