Skip to content

techoraye/BtrfsGuard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 

Repository files navigation

🛡️ BtrfsGuard

Never break your Linux system again. Automatic Btrfs snapshots before every package install, upgrade, or risky command.

# One-line Quick Install
curl -sS https://raw.githubusercontent.com/techoraye/btrfsguard/main/install.sh | sudo bash

📚 Table of Contents


🎯 What Does It Do?

BtrfsGuard acts as an intelligent safety net for your Linux system. It automatically creates snapshots before you:

  • Install/Update Packages (emerge, apt, pacman, dnf, zypper, etc.)
  • Run Universal Managers (flatpak, snap, pip, npm, cargo)
  • Modify Boot Configs (grub-mkconfig, mkinitcpio, dracut)
  • Run Custom Risky Commands (via snap-wrap)

If something breaks → Just rollback. That's it.


✨ Why BtrfsGuard?

Problem BtrfsGuard Solution
😱 System broke after update 🔄 Rollback in seconds from the GRUB menu
🤔 "What did this install change?" 📊 See exact file differences with snapper diff
🔥 Kernel panic after upgrade 🚀 Boot into the "Pre-update" snapshot instantly
💾 Snapshots eating space? 🧹 Smart deduplication & automatic lock cleanup
🐚 Use Zsh or Fish? ✅ Native support for Bash, Zsh, and Fish

🔧 Requirements

⚠️ CRITICAL: Btrfs Filesystem Required

BtrfsGuard ONLY works with the Btrfs filesystem. ```bash

Check if your root is Btrfs

df -T /

> [!IMPORTANT]
> If you don't see `btrfs` in the Type column, the installer will safely exit without making changes to your system.

### Other Requirements
* **Root/sudo access**
* **Git** (for auto-updates)
* **Snapper** (auto-installed by the script if missing)

---

## 🚀 Getting Started

### 1. Manual Installation
If you prefer not to use the one-liner, follow these steps:
```bash
git clone https://github.com/techoraye/btrfsguard.git
cd btrfsguard
sudo bash install.sh

2. Just Use Your System

You don't need to change your habits. These commands now auto-create snapshots:

sudo emerge -auDN @world
sudo apt upgrade
sudo pacman -Syu
sudo dnf install blender

3. Rollback When Needed

If a transaction fails or you don't like the changes:

# List snapshots to find your "Pre" ID
snapper list

# Undo the specific changes (example: undoing IDs 10 to 11)
snapper undochange 10..11

📦 Supported Distributions & Tools

Category Supported Tools
Distros Gentoo, Arch, Debian, Ubuntu, Fedora, RHEL, openSUSE, Alpine, Void
Managers emerge, apt, pacman, dnf, zypper, apk, xbps-install
AUR Helpers yay, paru
Universal flatpak, snap, pip, npm, yarn, cargo, gem
System grub-mkconfig, update-grub, kernel-install, dracut, mkinitcpio

🔥 Real-World Examples

Example 1: Rescue from a "Black Screen"

  1. Reboot your PC.
  2. In the GRUB menu, select "Btrfs snapshots".
  3. Select the snapshot created right before your last update.
  4. Once booted, run sudo snapper rollback to make it permanent.

Example 2: Protect Custom Commands

Use the built-in wrapper for anything not automatically covered:

snap-wrap rm -rf /etc/some-config-folder
# Snapshot created! If you regret the deletion, undo it instantly.

🎓 Essential Commands

Command Description
snapper list View all system snapshots
snap-status Check BtrfsGuard status and recent activity
snap-wrap <cmd> Manually snapshot a specific command
snapper-cleanup Clean orphaned locks and check storage
btrfsguard-update Check for and install BtrfsGuard updates

🧠 Smart Features

  1. Nested Snapshot Prevention: If you run a command that triggers a snapshot, and that command calls another command (like emerge calling dispatch-conf), BtrfsGuard detects the active session and prevents redundant snapshots.
  2. Pre/Post Pairing: Unlike simple cron jobs, BtrfsGuard creates paired snapshots. This allows Snapper to calculate the exact delta (difference) of the transaction.
  3. Shell Agnostic: Native support for Bash, Zsh, and Fish. It installs the correct aliases and event traps automatically.

🔄 Updating

BtrfsGuard includes a self-protection update mechanism:

sudo btrfsguard-update

It will:

  1. Check the GitHub repo for a new version.
  2. Create a snapshot of your system before updating itself.
  3. Apply the update and reload your configuration.

📜 License

Distributed under the MIT License. See LICENSE for more information.


Made with ❤️ for the Linux community

Report BugRequest Feature

About

Universal, intelligent filesystem snapshots for every Linux distribution and package manager

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages