# Borg 2.0.0b5 One-File Build (Variante A: mit `pyfuse3`)

Diese Anleitung beschreibt den Neuaufbau von Null auf Debian **Bookworm** (Build-Host), um ein tragbares **Borg 2.0.0b5**-Einzelbinary zu erzeugen, das auf Debian **Trixie** (Ziel) läuft – **inkl. `mount`-Support** via `pyfuse3`.

## Voraussetzungen (Bookworm)

```bash
sudo apt update
sudo apt install -y git python3-venv python3-dev build-essential pkg-config \
  libssl-dev libxxhash-dev liblz4-dev libzstd-dev libacl1-dev libfuse3-dev \
  liblzma-dev libb2-dev ca-certificates
```

## Build per Skript

```bash
chmod +x build.sh
./build.sh
```

Ergebnis: `/opt/borg2-b5-build/dist/borg2-b5`

## Manuell bauen (Kurzfassung)

```bash
python3 -m venv /opt/borg2-b5-build
source /opt/borg2-b5-build/bin/activate
python -m pip install -U "pip<25" "setuptools<70" wheel "Cython==0.29.36" pkgconfig "setuptools-scm<8"

cd /opt
git clone --depth 1 --branch 2.0.0b5 https://github.com/borgbackup/borg.git borg-b5-src

export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig
export BORG_CYTHONIZE=1
export BORG_OPENSSL_PREFIX=/usr
export BORG_LIBXXHASH_PREFIX=/usr
export BORG_LIBLZ4_PREFIX=/usr
export BORG_LIBZSTD_PREFIX=/usr
export BORG_LIBB2_PREFIX=/usr
export BORG_LIBLZMA_PREFIX=/usr
export BORG_LIBACL_PREFIX=/usr

cd /opt/borg-b5-src
python -m pip install --no-build-isolation --no-cache-dir .

cd /
python - <<'PY'
import borg, sys, inspect
print("borg", borg.__version__, "python", sys.version.split()[0])
print("from:", inspect.getsourcefile(borg) or borg.__file__)
PY

python -m pip install pyfuse3

cat > /opt/borg2-b5-build/borg2_entry.py <<'EOF'
import os, sys, types
os.environ.setdefault("BORG_SELFTEST", "disabled")
m = types.ModuleType("borg.selftest")
def _selftest(*a, **kw): return 0
m.selftest = _selftest
sys.modules["borg.selftest"] = m
ver = types.ModuleType("borg._version")
ver.version = "2.0.0b5"
sys.modules["borg._version"] = ver
import borg.archiver as A
if __name__ == "__main__":
    A.main()
EOF

python -m pip install "pyinstaller>=6,<7"
cd /opt/borg2-b5-build
python -m PyInstaller -F -n borg2-b5 -c borg2_entry.py \
  --collect-data borg --collect-binaries borg --collect-all pyfuse3 \
  --exclude-module borg.testsuite \
  --hidden-import=packaging.version --hidden-import=packaging.specifiers \
  --clean -y

./dist/borg2-b5 --version
```

## Deployment (Trixie)

```bash
scp /opt/borg2-b5-build/dist/borg2-b5 root@trixie:/usr/local/bin/
ssh root@trixie 'chmod +x /usr/local/bin/borg2-b5 && borg2-b5 --version'
```

### Für `mount` auf Trixie

```bash
sudo apt install -y fuse3
# /etc/fuse.conf: 'user_allow_other' aktivieren (optional)
sudo usermod -aG fuse <user>
mkdir -p /mnt/borg && chown <user>:<user> /mnt/borg

export BORG_FUSE_IMPL=pyfuse3
borg2-b5 mount -o allow_other,default_permissions \
  ssh://borg@backup-server/srv/borg-repos/deb12::ARCHIVENAME /mnt/borg
# Unmount
borg2-b5 umount /mnt/borg   # oder: fusermount3 -u /mnt/borg
```

## Beispiele

```bash
export BORG_REMOTE_PATH=borg2
borg2-b5 rlist  ssh://borg@backup-server/srv/borg-repos/deb12
borg2-b5 create --stats \
  ssh://borg@backup-server/srv/borg-repos/deb12::'{now:%Y-%m-%d_%H%M%S}' \
  /etc /var/www
```

## Troubleshooting

- `ModuleNotFoundError: borg._version`: Nicht-editable installieren (`pip install .`), Import **außerhalb** des Repo-Ordners testen; Entry-Stub liefert Fallback.
- `__set_name__`-Fehler: Cython 0.29.x verwenden; Source-Build erzwingen.
- Native Libs nicht gefunden: `PKG_CONFIG_PATH` + `BORG_*_PREFIX=/usr` setzen.
- `mount not available`: Binary mit `pyfuse3` bauen **und** auf Trixie `fuse3` installieren; `BORG_FUSE_IMPL=pyfuse3` setzen.
