Compare commits
15 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 76824346b8 | |||
| 7e7cf1cf65 | |||
| 55e4539bf7 | |||
| d5eaea9600 | |||
| 0a89020ce1 | |||
| e831dd1eb1 | |||
| e0394a0a0f | |||
| 1f42ba75f2 | |||
| 45ad565459 | |||
| b4afe150e8 | |||
| 8bbe2fbde8 | |||
| 5253514d4c | |||
| 6f8392824d | |||
| 48eb2e562d | |||
| 192eb06c9d |
9 changed files with 283 additions and 192 deletions
165
.forgejo/workflows/release.yml
Normal file
165
.forgejo/workflows/release.yml
Normal file
|
|
@ -0,0 +1,165 @@
|
||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: rust:bookworm
|
||||||
|
volumes:
|
||||||
|
- /opt/runner/keys:/keys:ro
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Install tools
|
||||||
|
run: |
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y dpkg-dev git curl openssh-client
|
||||||
|
|
||||||
|
- name: Setup SSH
|
||||||
|
run: |
|
||||||
|
test -r /keys/forgejo_runner || { echo "Deploy key /keys/forgejo_runner chybi"; exit 1; }
|
||||||
|
install -m 600 /keys/forgejo_runner /tmp/forgejo_runner
|
||||||
|
echo "GIT_SSH_COMMAND=ssh -p 554 -i /tmp/forgejo_runner -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
|
- name: Checkout source
|
||||||
|
run: |
|
||||||
|
git clone ssh://git@git-ssh.janvete.com:554/seth/resticview.git src
|
||||||
|
cd src
|
||||||
|
git checkout "${{ github.ref_name }}"
|
||||||
|
|
||||||
|
- name: Build Linux release binary and .deb
|
||||||
|
working-directory: src
|
||||||
|
run: |
|
||||||
|
VERSION=${{ github.ref_name }}
|
||||||
|
VER=${VERSION#v}
|
||||||
|
mkdir -p dist
|
||||||
|
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
# .deb package
|
||||||
|
DEB_DIR="resticview_${VER}_amd64"
|
||||||
|
mkdir -p "${DEB_DIR}/DEBIAN" "${DEB_DIR}/usr/bin"
|
||||||
|
cp target/release/resticview "${DEB_DIR}/usr/bin/resticview"
|
||||||
|
chmod 755 "${DEB_DIR}/usr/bin/resticview"
|
||||||
|
|
||||||
|
cat > "${DEB_DIR}/DEBIAN/control" << CONTROL
|
||||||
|
Package: resticview
|
||||||
|
Version: ${VER}
|
||||||
|
Section: utils
|
||||||
|
Priority: optional
|
||||||
|
Architecture: amd64
|
||||||
|
Maintainer: janvete <jan.vete@example.com>
|
||||||
|
Description: TUI browser for restic backup repositories
|
||||||
|
CONTROL
|
||||||
|
|
||||||
|
dpkg-deb --build "${DEB_DIR}" "dist/${DEB_DIR}.deb"
|
||||||
|
|
||||||
|
# Linux tarball
|
||||||
|
STAGING=$(mktemp -d)
|
||||||
|
cp target/release/resticview "${STAGING}/resticview"
|
||||||
|
tar -czf "dist/resticview-${VERSION}-linux-amd64.tar.gz" -C "${STAGING}" resticview
|
||||||
|
rm -rf "${STAGING}"
|
||||||
|
|
||||||
|
- name: Print checksums
|
||||||
|
working-directory: src
|
||||||
|
run: |
|
||||||
|
echo "=== SHA256 checksums ==="
|
||||||
|
sha256sum dist/*
|
||||||
|
|
||||||
|
- name: Create Forgejo Release
|
||||||
|
working-directory: src
|
||||||
|
env:
|
||||||
|
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
||||||
|
FORGEJO_URL: https://git.janvete.com
|
||||||
|
run: |
|
||||||
|
VERSION=${{ github.ref_name }}
|
||||||
|
API="${FORGEJO_URL}/api/v1/repos/seth/resticview"
|
||||||
|
|
||||||
|
RELEASE_JSON=$(curl -sS -H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-X POST \
|
||||||
|
-d "{\"tag_name\":\"${VERSION}\",\"name\":\"${VERSION}\",\"draft\":false,\"prerelease\":false}" \
|
||||||
|
"${API}/releases")
|
||||||
|
|
||||||
|
echo "Create release response: ${RELEASE_JSON}"
|
||||||
|
RELEASE_ID=$(echo "${RELEASE_JSON}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||||
|
|
||||||
|
if [ -z "${RELEASE_ID}" ]; then
|
||||||
|
echo "Release may already exist, fetching existing release..."
|
||||||
|
EXISTING=$(curl -sS -H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||||
|
"${API}/releases/tags/${VERSION}")
|
||||||
|
echo "Existing release response: ${EXISTING}"
|
||||||
|
RELEASE_ID=$(echo "${EXISTING}" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "${RELEASE_ID}" ]; then
|
||||||
|
echo "Failed to create or fetch release"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
for ARCHIVE in dist/*; do
|
||||||
|
[ -e "${ARCHIVE}" ] || continue
|
||||||
|
NAME=$(basename "${ARCHIVE}")
|
||||||
|
case "${NAME}" in
|
||||||
|
*.tar.gz) CONTENT_TYPE="application/gzip" ;;
|
||||||
|
*.deb) CONTENT_TYPE="application/vnd.debian.binary-package" ;;
|
||||||
|
*) CONTENT_TYPE="application/octet-stream" ;;
|
||||||
|
esac
|
||||||
|
curl -sS -H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||||
|
-H "Content-Type: ${CONTENT_TYPE}" \
|
||||||
|
--data-binary "@${ARCHIVE}" \
|
||||||
|
"${API}/releases/${RELEASE_ID}/assets?name=${NAME}"
|
||||||
|
echo "Uploaded ${NAME}"
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Update APT repository
|
||||||
|
working-directory: src
|
||||||
|
run: |
|
||||||
|
VERSION=${{ github.ref_name }}
|
||||||
|
|
||||||
|
git clone ssh://git@git-ssh.janvete.com:554/seth/apt.git apt-repo
|
||||||
|
cp dist/*.deb apt-repo/
|
||||||
|
|
||||||
|
cd apt-repo
|
||||||
|
|
||||||
|
# Remove any corrupted .deb files left from previous failed runs
|
||||||
|
for f in *.deb; do
|
||||||
|
[ -e "$f" ] || continue
|
||||||
|
if ! dpkg-deb -I "$f" >/dev/null 2>&1; then
|
||||||
|
echo "Removing corrupted package: $f"
|
||||||
|
rm -f "$f"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
dpkg-scanpackages . > Packages
|
||||||
|
gzip -k -f Packages
|
||||||
|
|
||||||
|
cat > Release << RELEASE
|
||||||
|
Origin: janvete
|
||||||
|
Label: janvete
|
||||||
|
Suite: stable
|
||||||
|
Codename: stable
|
||||||
|
Version: 1.0
|
||||||
|
Architectures: amd64
|
||||||
|
Components: main
|
||||||
|
Description: janvete tools APT repository
|
||||||
|
Date: $(date -Ru)
|
||||||
|
RELEASE
|
||||||
|
|
||||||
|
{
|
||||||
|
echo "SHA256:"
|
||||||
|
for f in Packages Packages.gz *.deb; do
|
||||||
|
[ -e "$f" ] || continue
|
||||||
|
printf " %s %16d %s\n" "$(sha256sum "$f" | cut -d' ' -f1)" "$(stat -c%s "$f")" "$f"
|
||||||
|
done
|
||||||
|
} >> Release
|
||||||
|
|
||||||
|
git config user.email "forgejo-actions[bot]@janvete.com"
|
||||||
|
git config user.name "forgejo-actions[bot]"
|
||||||
|
git add -A
|
||||||
|
git commit -m "chore: add resticview ${VERSION}"
|
||||||
|
git push
|
||||||
68
.github/workflows/release.yml
vendored
68
.github/workflows/release.yml
vendored
|
|
@ -1,68 +0,0 @@
|
||||||
name: Release
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
tag:
|
|
||||||
description: 'Tag to release (e.g. v0.1.6)'
|
|
||||||
required: true
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-macos:
|
|
||||||
runs-on: macos-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: dtolnay/rust-toolchain@stable
|
|
||||||
- run: cargo build --release
|
|
||||||
- run: cargo test --release
|
|
||||||
- run: cargo clippy --release -- -D warnings
|
|
||||||
- uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: resticview-macos
|
|
||||||
path: target/release/resticview
|
|
||||||
|
|
||||||
build-linux:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: dtolnay/rust-toolchain@stable
|
|
||||||
- run: cargo install cargo-deb
|
|
||||||
- run: cargo build --release
|
|
||||||
- run: cargo test --release
|
|
||||||
- run: cargo clippy --release -- -D warnings
|
|
||||||
- run: cargo deb
|
|
||||||
- uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: resticview-linux
|
|
||||||
path: |
|
|
||||||
target/release/resticview
|
|
||||||
target/debian/*.deb
|
|
||||||
|
|
||||||
release:
|
|
||||||
needs: [build-macos, build-linux]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: resticview-macos
|
|
||||||
path: artifacts/macos
|
|
||||||
- uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: resticview-linux
|
|
||||||
path: artifacts/linux
|
|
||||||
- name: Create Release
|
|
||||||
uses: softprops/action-gh-release@v2
|
|
||||||
with:
|
|
||||||
tag_name: ${{ github.event.inputs.tag || github.ref_name }}
|
|
||||||
files: |
|
|
||||||
artifacts/macos/resticview
|
|
||||||
artifacts/linux/release/resticview
|
|
||||||
artifacts/linux/debian/*.deb
|
|
||||||
generate_release_notes: true
|
|
||||||
overwrite_files: true
|
|
||||||
|
|
@ -5,8 +5,8 @@ edition = "2024"
|
||||||
authors = ["janvete"]
|
authors = ["janvete"]
|
||||||
description = "TUI browser for restic backup repositories"
|
description = "TUI browser for restic backup repositories"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/janvete/resticview"
|
repository = "https://git.janvete.com/seth/resticview"
|
||||||
homepage = "https://github.com/janvete/resticview"
|
homepage = "https://git.janvete.com/seth/resticview"
|
||||||
keywords = ["cli", "tui", "restic", "backup"]
|
keywords = ["cli", "tui", "restic", "backup"]
|
||||||
categories = ["command-line-utilities"]
|
categories = ["command-line-utilities"]
|
||||||
|
|
||||||
|
|
|
||||||
18
Formula/resticview.rb
Normal file
18
Formula/resticview.rb
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
class Resticview < Formula
|
||||||
|
desc "TUI browser for restic backup repositories"
|
||||||
|
homepage "https://git.janvete.com/seth/resticview"
|
||||||
|
url "https://git.janvete.com/seth/resticview/archive/v0.1.4.tar.gz"
|
||||||
|
sha256 "79de9f0e8ecac078094e457677c316c6f0a37ca87de36d82ec0723c283aaa4b2"
|
||||||
|
license "MIT"
|
||||||
|
head "https://git.janvete.com/seth/resticview.git", branch: "main"
|
||||||
|
|
||||||
|
depends_on "rust" => :build
|
||||||
|
|
||||||
|
def install
|
||||||
|
system "cargo", "install", *std_cargo_args
|
||||||
|
end
|
||||||
|
|
||||||
|
test do
|
||||||
|
assert_match "TUI browser for restic backup repositories", shell_output("#{bin}/resticview --help")
|
||||||
|
end
|
||||||
|
end
|
||||||
29
README.md
29
README.md
|
|
@ -1,20 +1,39 @@
|
||||||
# resticview
|
# resticview
|
||||||
|
|
||||||
A TUI browser for restic backup repositories. Browse snapshots, explore the file tree of any snapshot, view repository stats, and restore whole snapshots or single paths on demand.
|
A TUI browser for restic backup repositories. Browse snapshots, explore the file tree of any snapshot, and restore whole snapshots or single paths on demand.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### macOS (Homebrew)
|
### macOS (Homebrew)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
brew tap janvete/tools
|
brew tap janvete/tools https://git.janvete.com/seth/homebrew-tools.git
|
||||||
brew install resticview
|
brew install resticview
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Debian / Ubuntu (.deb)
|
||||||
|
|
||||||
|
Add the janvete APT repository and install:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
echo "deb [trusted=yes] https://git.janvete.com/seth/apt/raw/branch/main ./" | sudo tee /etc/apt/sources.list.d/janvete.list
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install resticview
|
||||||
|
```
|
||||||
|
|
||||||
|
### Prebuilt binaries
|
||||||
|
|
||||||
|
Each [release](https://git.janvete.com/seth/resticview/releases) also ships standalone binaries: `resticview-macos` (Apple Silicon) and `resticview-linux` (x86_64). Put the file on your `PATH` and make it executable:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
chmod +x resticview-linux
|
||||||
|
sudo mv resticview-linux /usr/local/bin/resticview
|
||||||
|
```
|
||||||
|
|
||||||
### From source
|
### From source
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo install --git https://github.com/janvete/resticview
|
cargo install --git ssh://git@git-ssh.janvete.com:554/seth/resticview
|
||||||
```
|
```
|
||||||
|
|
||||||
`restic` must be installed and on `PATH`.
|
`restic` must be installed and on `PATH`.
|
||||||
|
|
@ -29,7 +48,7 @@ resticview --env-dir DIR # use a different env directory
|
||||||
resticview --select # always show the env file picker
|
resticview --select # always show the env file picker
|
||||||
```
|
```
|
||||||
|
|
||||||
The main view has three panels: snapshots (left), the file tree of the selected snapshot (middle), and repository stats (right). The focused panel has a highlighted border.
|
The main view has three panels: snapshots (left), the file tree of the selected snapshot (middle), and repository / snapshot info (right). The right panel shows the repository name, env file, total snapshot count, and details of the selected snapshot (time, host, user, paths, tags). The focused panel has a highlighted border.
|
||||||
|
|
||||||
Restore (`r`) asks for a target directory (pre-filled with `~/restic-restore-<id>`), asks for confirmation, and then runs `restic restore` in the background. With the focus on the snapshot list the whole snapshot is restored; with the focus on the file tree only the selected path is restored (`--include`).
|
Restore (`r`) asks for a target directory (pre-filled with `~/restic-restore-<id>`), asks for confirmation, and then runs `restic restore` in the background. With the focus on the snapshot list the whole snapshot is restored; with the focus on the file tree only the selected path is restored (`--include`).
|
||||||
|
|
||||||
|
|
@ -45,7 +64,7 @@ Restore (`r`) asks for a target directory (pre-filled with `~/restic-restore-<id
|
||||||
| `h` / `l` or `←` / `→` | collapse / expand directory |
|
| `h` / `l` or `←` / `→` | collapse / expand directory |
|
||||||
| `g` / `G` | jump to top / bottom |
|
| `g` / `G` | jump to top / bottom |
|
||||||
| `r` | restore selected snapshot or path |
|
| `r` | restore selected snapshot or path |
|
||||||
| `R` | refresh snapshots and repository stats |
|
| `R` | refresh snapshots |
|
||||||
| `Esc` | close prompt / dialog, clear status |
|
| `Esc` | close prompt / dialog, clear status |
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
|
||||||
52
src/app.rs
52
src/app.rs
|
|
@ -16,30 +16,30 @@ use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEventKind};
|
||||||
use ratatui::widgets::ListState;
|
use ratatui::widgets::ListState;
|
||||||
|
|
||||||
use crate::envfile::EnvFile;
|
use crate::envfile::EnvFile;
|
||||||
use crate::restic::{self, LsLine, Snapshot, Stats};
|
use crate::restic::{self, LsLine, Snapshot};
|
||||||
use crate::tree::Tree;
|
use crate::tree::Tree;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum Focus {
|
pub enum Focus {
|
||||||
Snapshots,
|
Snapshots,
|
||||||
Tree,
|
Tree,
|
||||||
Stats,
|
Repo,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Focus {
|
impl Focus {
|
||||||
pub fn next(self) -> Self {
|
pub fn next(self) -> Self {
|
||||||
match self {
|
match self {
|
||||||
Focus::Snapshots => Focus::Tree,
|
Focus::Snapshots => Focus::Tree,
|
||||||
Focus::Tree => Focus::Stats,
|
Focus::Tree => Focus::Repo,
|
||||||
Focus::Stats => Focus::Snapshots,
|
Focus::Repo => Focus::Snapshots,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prev(self) -> Self {
|
pub fn prev(self) -> Self {
|
||||||
match self {
|
match self {
|
||||||
Focus::Snapshots => Focus::Stats,
|
Focus::Snapshots => Focus::Repo,
|
||||||
Focus::Tree => Focus::Snapshots,
|
Focus::Tree => Focus::Snapshots,
|
||||||
Focus::Stats => Focus::Tree,
|
Focus::Repo => Focus::Tree,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +85,6 @@ pub enum BgMsg {
|
||||||
snapshot: String,
|
snapshot: String,
|
||||||
result: Result<Vec<LsLine>, String>,
|
result: Result<Vec<LsLine>, String>,
|
||||||
},
|
},
|
||||||
Stats(Result<Stats, String>),
|
|
||||||
Restore(Result<String, String>),
|
Restore(Result<String, String>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,8 +111,6 @@ pub struct App {
|
||||||
tree_generation: u64,
|
tree_generation: u64,
|
||||||
tree_cancel: Arc<AtomicBool>,
|
tree_cancel: Arc<AtomicBool>,
|
||||||
|
|
||||||
pub stats: LoadState<Stats>,
|
|
||||||
|
|
||||||
pub restore_state: RestoreState,
|
pub restore_state: RestoreState,
|
||||||
/// Last finished restore: (success, message).
|
/// Last finished restore: (success, message).
|
||||||
pub restore_outcome: Option<(bool, String)>,
|
pub restore_outcome: Option<(bool, String)>,
|
||||||
|
|
@ -144,7 +141,6 @@ impl App {
|
||||||
tree_cache: HashMap::new(),
|
tree_cache: HashMap::new(),
|
||||||
tree_generation: 0,
|
tree_generation: 0,
|
||||||
tree_cancel: Arc::new(AtomicBool::new(false)),
|
tree_cancel: Arc::new(AtomicBool::new(false)),
|
||||||
stats: LoadState::Loading,
|
|
||||||
restore_state: RestoreState::Idle,
|
restore_state: RestoreState::Idle,
|
||||||
restore_outcome: None,
|
restore_outcome: None,
|
||||||
restore_cancel: Arc::new(AtomicBool::new(false)),
|
restore_cancel: Arc::new(AtomicBool::new(false)),
|
||||||
|
|
@ -153,7 +149,6 @@ impl App {
|
||||||
rx,
|
rx,
|
||||||
};
|
};
|
||||||
app.spawn_snapshots();
|
app.spawn_snapshots();
|
||||||
app.spawn_stats();
|
|
||||||
app
|
app
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -180,16 +175,6 @@ impl App {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_stats(&mut self) {
|
|
||||||
self.stats = LoadState::Loading;
|
|
||||||
let env = self.env.clone();
|
|
||||||
let tx = self.tx.clone();
|
|
||||||
thread::spawn(move || {
|
|
||||||
let result = restic::stats(&env).map_err(|e| format!("{e:#}"));
|
|
||||||
let _ = tx.send(BgMsg::Stats(result));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Make sure the tree for the currently selected snapshot is loaded:
|
/// Make sure the tree for the currently selected snapshot is loaded:
|
||||||
/// serve it from the cache when possible, otherwise start a background
|
/// serve it from the cache when possible, otherwise start a background
|
||||||
/// load (cancelling any stale one).
|
/// load (cancelling any stale one).
|
||||||
|
|
@ -230,7 +215,7 @@ impl App {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Refresh snapshots and stats (`R`); drops the tree cache.
|
/// Refresh snapshots (`R`); drops the tree cache.
|
||||||
pub fn refresh(&mut self) {
|
pub fn refresh(&mut self) {
|
||||||
self.tree_cancel.store(true, Ordering::Relaxed);
|
self.tree_cancel.store(true, Ordering::Relaxed);
|
||||||
self.tree_generation += 1;
|
self.tree_generation += 1;
|
||||||
|
|
@ -238,7 +223,6 @@ impl App {
|
||||||
self.tree = None;
|
self.tree = None;
|
||||||
self.tree_status = TreeStatus::Idle;
|
self.tree_status = TreeStatus::Idle;
|
||||||
self.spawn_snapshots();
|
self.spawn_snapshots();
|
||||||
self.spawn_stats();
|
|
||||||
self.status = Some("refreshing…".to_string());
|
self.status = Some("refreshing…".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -286,12 +270,6 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BgMsg::Stats(Ok(stats)) => {
|
|
||||||
self.stats = LoadState::Ready(stats);
|
|
||||||
}
|
|
||||||
BgMsg::Stats(Err(e)) => {
|
|
||||||
self.stats = LoadState::Failed(e);
|
|
||||||
}
|
|
||||||
BgMsg::Restore(result) => {
|
BgMsg::Restore(result) => {
|
||||||
self.restore_state = RestoreState::Idle;
|
self.restore_state = RestoreState::Idle;
|
||||||
match result {
|
match result {
|
||||||
|
|
@ -355,7 +333,7 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Focus::Snapshots => self.focus = Focus::Tree,
|
Focus::Snapshots => self.focus = Focus::Tree,
|
||||||
Focus::Stats => {}
|
Focus::Repo => {}
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
@ -391,7 +369,7 @@ impl App {
|
||||||
tree.move_by(delta);
|
tree.move_by(delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Focus::Stats => {}
|
Focus::Repo => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -408,7 +386,7 @@ impl App {
|
||||||
tree.first();
|
tree.first();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Focus::Stats => {}
|
Focus::Repo => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -430,7 +408,7 @@ impl App {
|
||||||
tree.last();
|
tree.last();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Focus::Stats => {}
|
Focus::Repo => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -461,7 +439,7 @@ impl App {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Focus::Stats => {
|
Focus::Repo => {
|
||||||
self.status = Some("focus Snapshots or Files to restore".to_string());
|
self.status = Some("focus Snapshots or Files to restore".to_string());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -661,8 +639,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn focus_cycles() {
|
fn focus_cycles() {
|
||||||
assert_eq!(Focus::Snapshots.next(), Focus::Tree);
|
assert_eq!(Focus::Snapshots.next(), Focus::Tree);
|
||||||
assert_eq!(Focus::Tree.next(), Focus::Stats);
|
assert_eq!(Focus::Tree.next(), Focus::Repo);
|
||||||
assert_eq!(Focus::Stats.next(), Focus::Snapshots);
|
assert_eq!(Focus::Repo.next(), Focus::Snapshots);
|
||||||
assert_eq!(Focus::Snapshots.prev(), Focus::Stats);
|
assert_eq!(Focus::Snapshots.prev(), Focus::Repo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ impl EnvFile {
|
||||||
self.vars.get(key).map(String::as_str)
|
self.vars.get(key).map(String::as_str)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Value of RESTIC_REPOSITORY, for display in the picker and stats panel.
|
/// Value of RESTIC_REPOSITORY, for display in the picker and repo panel.
|
||||||
pub fn repository(&self) -> &str {
|
pub fn repository(&self) -> &str {
|
||||||
self.get("RESTIC_REPOSITORY")
|
self.get("RESTIC_REPOSITORY")
|
||||||
.unwrap_or("(no RESTIC_REPOSITORY)")
|
.unwrap_or("(no RESTIC_REPOSITORY)")
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,11 @@ use serde::Deserialize;
|
||||||
pub struct Snapshot {
|
pub struct Snapshot {
|
||||||
pub short_id: String,
|
pub short_id: String,
|
||||||
pub time: String,
|
pub time: String,
|
||||||
|
pub hostname: String,
|
||||||
|
pub username: String,
|
||||||
|
pub paths: Vec<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub tags: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// One line of `restic ls <id> --json` (either the snapshot header or a node).
|
/// One line of `restic ls <id> --json` (either the snapshot header or a node).
|
||||||
|
|
@ -47,13 +52,6 @@ impl LsLine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Result of `restic stats --json` (default mode).
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
pub struct Stats {
|
|
||||||
pub total_size: u64,
|
|
||||||
pub total_file_count: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn base_command(env: &HashMap<String, String>) -> Command {
|
fn base_command(env: &HashMap<String, String>) -> Command {
|
||||||
let mut cmd = Command::new("restic");
|
let mut cmd = Command::new("restic");
|
||||||
cmd.envs(env);
|
cmd.envs(env);
|
||||||
|
|
@ -136,19 +134,6 @@ pub fn ls(env: &HashMap<String, String>, snapshot: &str, cancel: &AtomicBool) ->
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `restic stats --json` (default mode).
|
|
||||||
pub fn stats(env: &HashMap<String, String>) -> Result<Stats> {
|
|
||||||
let out = base_command(env)
|
|
||||||
.args(["stats", "--json"])
|
|
||||||
.output()
|
|
||||||
.context("failed to run restic (is it installed and on PATH?)")?;
|
|
||||||
if !out.status.success() {
|
|
||||||
return Err(stderr_error(&out.stderr));
|
|
||||||
}
|
|
||||||
let text = String::from_utf8_lossy(&out.stdout);
|
|
||||||
serde_json::from_str(text.trim()).context("failed to parse restic stats output")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `restic restore <snapshot> --target <dir> [--include <path>]`.
|
/// `restic restore <snapshot> --target <dir> [--include <path>]`.
|
||||||
///
|
///
|
||||||
/// Polls the child so a running restore can be cancelled via `cancel`
|
/// Polls the child so a running restore can be cancelled via `cancel`
|
||||||
|
|
@ -214,11 +199,21 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_snapshot_json() {
|
fn parse_snapshot_json() {
|
||||||
// Real restic output carries many more fields; serde ignores them.
|
let json = r#"[{"time":"2026-08-15T21:02:18.148309+02:00","paths":["/Users/seth"],"hostname":"mac.local","username":"seth","id":"46dd2015bcdb","short_id":"46dd2015","tags":["daily","auto"]}]"#;
|
||||||
let json = r#"[{"time":"2026-08-15T21:02:18.148309+02:00","paths":["/Users/seth"],"hostname":"mac.local","username":"seth","id":"46dd2015bcdb","short_id":"46dd2015"}]"#;
|
|
||||||
let snaps: Vec<Snapshot> = serde_json::from_str(json).unwrap();
|
let snaps: Vec<Snapshot> = serde_json::from_str(json).unwrap();
|
||||||
assert_eq!(snaps[0].short_id, "46dd2015");
|
assert_eq!(snaps[0].short_id, "46dd2015");
|
||||||
assert_eq!(snaps[0].time, "2026-08-15T21:02:18.148309+02:00");
|
assert_eq!(snaps[0].time, "2026-08-15T21:02:18.148309+02:00");
|
||||||
|
assert_eq!(snaps[0].hostname, "mac.local");
|
||||||
|
assert_eq!(snaps[0].username, "seth");
|
||||||
|
assert_eq!(snaps[0].paths, vec!["/Users/seth"]);
|
||||||
|
assert_eq!(snaps[0].tags, vec!["daily", "auto"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_snapshot_json_without_tags() {
|
||||||
|
let json = r#"[{"time":"2026-08-15T21:02:18.148309+02:00","paths":["/Users/seth"],"hostname":"mac.local","username":"seth","id":"46dd2015bcdb","short_id":"46dd2015"}]"#;
|
||||||
|
let snaps: Vec<Snapshot> = serde_json::from_str(json).unwrap();
|
||||||
|
assert!(snaps[0].tags.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -247,17 +242,6 @@ mod tests {
|
||||||
assert_eq!(file.size, Some(1234));
|
assert_eq!(file.size, Some(1234));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn parse_stats_json() {
|
|
||||||
// `snapshots_count` (present since restic 0.19) is ignored.
|
|
||||||
let stats: Stats = serde_json::from_str(
|
|
||||||
r#"{"total_size":16942067259,"total_file_count":294549,"snapshots_count":6}"#,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(stats.total_size, 16942067259);
|
|
||||||
assert_eq!(stats.total_file_count, 294549);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn tilde_expansion() {
|
fn tilde_expansion() {
|
||||||
let home = dirs::home_dir().unwrap();
|
let home = dirs::home_dir().unwrap();
|
||||||
|
|
|
||||||
83
src/ui.rs
83
src/ui.rs
|
|
@ -26,7 +26,7 @@ pub fn draw(frame: &mut Frame, app: &mut App) {
|
||||||
|
|
||||||
draw_snapshots(frame, app, cols[0]);
|
draw_snapshots(frame, app, cols[0]);
|
||||||
draw_tree(frame, app, cols[1]);
|
draw_tree(frame, app, cols[1]);
|
||||||
draw_stats(frame, app, cols[2]);
|
draw_repo(frame, app, cols[2]);
|
||||||
draw_status(frame, app, chunks[1]);
|
draw_status(frame, app, chunks[1]);
|
||||||
draw_footer(frame, chunks[2]);
|
draw_footer(frame, chunks[2]);
|
||||||
|
|
||||||
|
|
@ -183,25 +183,26 @@ fn draw_tree(frame: &mut Frame, app: &mut App, area: Rect) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_stats(frame: &mut Frame, app: &App, area: Rect) {
|
fn draw_repo(frame: &mut Frame, app: &App, area: Rect) {
|
||||||
let focused = app.focus == Focus::Stats;
|
let focused = app.focus == Focus::Repo;
|
||||||
let block = panel_block("Repository".to_string(), focused);
|
let block = panel_block("Repository".to_string(), focused);
|
||||||
let label = Style::default().fg(Color::Gray);
|
let label = Style::default().fg(Color::Gray);
|
||||||
|
let value = Style::default();
|
||||||
let mut lines = vec![
|
let mut lines = vec![
|
||||||
Line::from(vec![
|
Line::from(vec![
|
||||||
Span::styled("Repository: ", label),
|
Span::styled("Repository: ", label),
|
||||||
Span::raw(app.repo.clone()),
|
Span::styled(app.repo.clone(), value),
|
||||||
]),
|
]),
|
||||||
Line::from(vec![
|
Line::from(vec![
|
||||||
Span::styled("Env file: ", label),
|
Span::styled("Env file: ", label),
|
||||||
Span::raw(app.env_rel_path.clone()),
|
Span::styled(app.env_rel_path.clone(), value),
|
||||||
]),
|
]),
|
||||||
Line::from(""),
|
Line::from(""),
|
||||||
];
|
];
|
||||||
match &app.snapshots {
|
match &app.snapshots {
|
||||||
LoadState::Ready(snaps) => lines.push(Line::from(vec![
|
LoadState::Ready(snaps) => lines.push(Line::from(vec![
|
||||||
Span::styled("Snapshots: ", label),
|
Span::styled("Snapshots: ", label),
|
||||||
Span::raw(snaps.len().to_string()),
|
Span::styled(snaps.len().to_string(), value),
|
||||||
])),
|
])),
|
||||||
LoadState::Loading => lines.push(Line::from(vec![
|
LoadState::Loading => lines.push(Line::from(vec![
|
||||||
Span::styled("Snapshots: ", label),
|
Span::styled("Snapshots: ", label),
|
||||||
|
|
@ -212,33 +213,45 @@ fn draw_stats(frame: &mut Frame, app: &App, area: Rect) {
|
||||||
Span::styled("error", Style::default().fg(Color::Red)),
|
Span::styled("error", Style::default().fg(Color::Red)),
|
||||||
])),
|
])),
|
||||||
}
|
}
|
||||||
match &app.stats {
|
|
||||||
LoadState::Loading => lines.push(Line::from(vec![
|
|
||||||
Span::styled("Stats: ", label),
|
|
||||||
Span::raw(format!("{} loading…", app.spinner())),
|
|
||||||
])),
|
|
||||||
LoadState::Failed(e) => {
|
|
||||||
lines.push(Line::from(vec![
|
|
||||||
Span::styled("Stats: ", label),
|
|
||||||
Span::styled("error", Style::default().fg(Color::Red)),
|
|
||||||
]));
|
|
||||||
lines.push(Line::from(""));
|
lines.push(Line::from(""));
|
||||||
lines.push(Line::from(Span::styled(
|
match app.selected_snapshot() {
|
||||||
e.clone(),
|
Some(snap) => {
|
||||||
Style::default().fg(Color::Red),
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
LoadState::Ready(stats) => {
|
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
Span::styled("Total size: ", label),
|
Span::styled("Snapshot: ", label),
|
||||||
Span::raw(human_size(stats.total_size)),
|
Span::styled(snap.short_id.clone(), value),
|
||||||
]));
|
]));
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
Span::styled("Files: ", label),
|
Span::styled("Time: ", label),
|
||||||
Span::raw(format_count(stats.total_file_count)),
|
Span::styled(format_time(&snap.time), value),
|
||||||
|
]));
|
||||||
|
lines.push(Line::from(vec![
|
||||||
|
Span::styled("Host: ", label),
|
||||||
|
Span::styled(snap.hostname.clone(), value),
|
||||||
|
]));
|
||||||
|
lines.push(Line::from(vec![
|
||||||
|
Span::styled("User: ", label),
|
||||||
|
Span::styled(snap.username.clone(), value),
|
||||||
|
]));
|
||||||
|
lines.push(Line::from(vec![
|
||||||
|
Span::styled("Paths: ", label),
|
||||||
|
Span::styled(snap.paths.join(", "), value),
|
||||||
|
]));
|
||||||
|
if !snap.tags.is_empty() {
|
||||||
|
lines.push(Line::from(vec![
|
||||||
|
Span::styled("Tags: ", label),
|
||||||
|
Span::styled(snap.tags.join(", "), value),
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
None => {
|
||||||
|
lines.push(Line::from(vec![Span::styled(
|
||||||
|
"no snapshot selected",
|
||||||
|
Style::default().fg(Color::Gray),
|
||||||
|
)]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
frame.render_widget(
|
frame.render_widget(
|
||||||
Paragraph::new(lines).block(block).wrap(Wrap { trim: false }),
|
Paragraph::new(lines).block(block).wrap(Wrap { trim: false }),
|
||||||
area,
|
area,
|
||||||
|
|
@ -355,18 +368,6 @@ pub fn human_size(bytes: u64) -> String {
|
||||||
format!("{value:.1} {}", UNITS[unit])
|
format!("{value:.1} {}", UNITS[unit])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format_count(n: u64) -> String {
|
|
||||||
let s = n.to_string();
|
|
||||||
let mut out = String::new();
|
|
||||||
for (i, c) in s.chars().enumerate() {
|
|
||||||
if i > 0 && (s.len() - i).is_multiple_of(3) {
|
|
||||||
out.push(',');
|
|
||||||
}
|
|
||||||
out.push(c);
|
|
||||||
}
|
|
||||||
out
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
@ -389,10 +390,4 @@ mod tests {
|
||||||
assert_eq!(human_size(3158099665), "2.9 GiB");
|
assert_eq!(human_size(3158099665), "2.9 GiB");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn count_formatting() {
|
|
||||||
assert_eq!(format_count(294549), "294,549");
|
|
||||||
assert_eq!(format_count(6), "6");
|
|
||||||
assert_eq!(format_count(1000), "1,000");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue