8000 GitHub - jolynini/unbrick: System state snapshot/diff/restore for Debian/Ubuntu — git status for your whole system · GitHub
[go: up one dir, main page]

Skip to content
jolyniniPublic

About

System state snapshot/diff/restore for Debian/Ubuntu — git status for your whole system

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unbrick

git status for your whole system. unbrick snapshots installed packages, enabled systemd services, and the hashes (+ content) of config files you care about, then lets you diff or restore against a saved snapshot — cheap and fast, with no Btrfs/LVM filesystem snapshotting required.

Install

From source

go install github.com/jolynini/unbrick@latest

Build a .deb

sudo apt build-dep .   # or: sudo mk-build-deps -i debian/control
dpkg-buildpackage -us -uc -b
sudo apt install ../unbrick_*.deb

The debian/ packaging builds against Debian's own golang-*-dev packages (cobra, fatih/color, yaml.v3, and their own transitive dependencies) rather than a vendored copy, via GO111MODULE=off and a GOPATH that layers this source over /usr/share/gocode. Plain go build ./... outside of Debian packaging still uses go.mod/go.sum as normal (fetching over the module proxy the first time, same as any other Go project).

Quick start

# Take a baseline snapshot
unbrick save --name baseline

# ... install stuff, edit configs, enable services ...

# See what changed since the last snapshot (vs. current live state)
unbrick diff

# List all snapshots
unbrick list

# Inspect one in full
unbrick show baseline

# Bring the system back to that snapshot (shows a plan first, always)
sudo unbrick restore baseline --dry-run
sudo unbrick restore baseline

Commands

unbrick save [--name <label>]

Captures:

  • Packages — every dpkg-installed package and its version.
  • Services — every systemd unit enabled via systemctl list-unit-files --state=enabled.
  • Configs — sha256 + mtime (and a compressed copy of the actual content, so diff/restore have something to work with) for every file under the tracked paths in ~/.unbrick/config.yaml (default: /etc, ~/.bashrc, ~/.profile, ~/.config).

Snapshots are written to ~/.unbrick/snapshots/<timestamp>[-<label>]/. File content is deduplicated in a shared object store at ~/.unbrick/objects/, so an unchanged file across many snapshots costs disk space exactly once. The newest retention_count snapshots (default 10) are kept; older ones are pruned automatically. save never modifies anything outside ~/.unbrick.

unbrick diff [<snapshot-id>] [--against <snapshot-id>]

  • No arguments: diffs the latest snapshot against current live state.
  • <snapshot-id>: diffs that snapshot against live state instead.
  • --against <snapshot-id>: diffs two stored snapshots against each other, without touching live state at all.
  • --json: machine-readable output instead of colored text.

Shows three sections: packages added/removed/version-changed, services newly enabled/disabled, and configs added/modified/removed. Always read-only.

unbrick restore [<snapshot-id>] [--dry-run] [--only packages|services|configs] [--yes]

Builds a plan (reusing the same diff logic as diff) comparing live state against the target snapshot, shows it, and only then asks what to do:

  • Packages: missing ones are installed pinned to the snapshot's version; packages present now but absent from the snapshot are listed and require an explicit yes before removal — --yes does not skip this one confirmation, by design.
  • Configs: for each changed or missing tracked file, you're prompted per file — [r]estore / [s]kip / [d]iff. The live version is always backed up to ~/.unbrick/pre-restore-backup/<run-id>/ before being overwritten. Files present now but absent from the snapshot are reported but never deleted automatically.
  • Services: re-enables/disables units to match the snapshot.

--dry-run shows the plan and exits without prompting or changing anything. Package installs/removals and service changes need root — run sudo unbrick restore ... (or just unbrick restore --dry-run to review without root).

unbrick list

Table of every stored snapshot: ID, timestamp, label, and package/service/ config counts.

unbrick show <snapshot-id>

Full manifest 70A7 contents for one snapshot (--json for the raw manifest).

Configuration

~/.unbrick/config.yaml, created with defaults on first run:

tracked_paths:
  - /etc
  - ~/.bashrc
  - ~/.profile
  - ~/.config
ignore_patterns:
  - "*.log"
  - "*.sock"
  - "*.pid"
  - "*/cache/*"
  - "*/Cache/*"
retention_count: 10
max_file_size_bytes: 2097152 # 2MB

Directories that get noisy application state under ~/.config (browser profiles, chat client caches, etc.) will show up as frequent diffs unless you narrow tracked_paths or add ignore patterns — diff/restore are only as useful as what you choose to track.

.unbrickignore

Drop a .unbrickignore file in any tracked directory to exclude paths under it, gitignore-style (one pattern per line, # for comments, trailing / for directory-only matches). This is a practical subset of gitignore syntax — no negation, no ** — sufficient for excluding cache/log/socket paths.

Design notes

  • Read-only by default: save, diff, list, and show never modify anything outside ~/.unbrick. Only restore touches live system state, and only after showing a plan and getting confirmation.
  • Fast: package/service capture shells out to dpkg-query and systemctl; config file hashing is parallelized across a worker pool sized to GOMAXPROCS. A snapshot of a typical desktop system (~5k packages, ~4k tracked config files) takes well under a second.
  • No extra runtime dependencies: everything is driven by dpkg, apt-get, and systemctl, which are already present on any Debian/ Ubuntu system. The Go module dependencies (cobra, fatih/color, yaml.v3) are compiled into the single static binary at build time, not fetched at runtime.
  • Known limitation: pruning old snapshots (retention_count) does not currently garbage-collect object-store blobs that no remaining snapshot references — deleted snapshots' unique file content is left on disk rather than risking data loss on a prune. A gc subcommand to reclaim that space is a natural next addition.

Development

go build ./...
go test ./...
gofmt -l .

The diff engine (internal/diffengine) is the correctness-critical core — it has unit test coverage for added/removed/changed packages, services, and configs, including nil-manifest edge cases (no prior snapshot).

About

System state snapshot/diff/restore for Debian/Ubuntu — git status for your whole system

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0