Skip to content

Back up Git repositories from the Docker host

Deploy and operate the Compose stack in /home/igresc/git-backup/ on docker.local.isabelsoler.es. Deploy stacks by hand as igresc, who belongs to the docker group. The Docker host VM is outside IaC management. ADR 006 defines the recovery policy.

Prepare the NAS storage

TrueNAS provides NFS storage, ZFS snapshots, and the existing B2 sync. The B2 task for this dataset intentionally uses no encryption. The owner chose this on 2026-10-27 because these repositories hold no secret values and could be public. Keep backup scripts, credentials, and Git-serving code in Docker containers.

  1. Create the dedicated dataset /mnt/tank/backups/github with POSIX ACLs, ownership root:root, and mode 0700.
  2. Export it only to the Docker host, 192.168.1.32, and enable NFSv4 in the NFS service. Set Maproot User and Group to root and leave Mapall unset. The backup runs as root inside its container and needs root access on this export.
  3. Include the dataset in the ZFS snapshot policy. It contains mirrors, bundles, history, and cached ISOs. Credentials stay in the stack's ./private bind mount on the Docker host.
  4. In Data Protection > Cloud Sync Tasks, configure the task Backblaze B2 - /mnt/tank/backups/github:
    • Direction PUSH, Transfer Mode SYNC, bucket homelab-igresc-backups, folder /github.
    • Schedule: daily, a few hours after the 02:15 UTC backup. For example, choose Custom and enter 0 6 * * *.
    • Use Snapshot: on. The upload reads a ZFS snapshot and can't copy a bundle while the job writes it.
    • Remote Encryption: off.
  5. In Backblaze, open Buckets > homelab-igresc-backups > Lifecycle Settings and choose Use custom lifecycle rules, as ADR 006 sets for every NAS bucket: 30 days from hiding to deleting, and cancel unfinished large files after 7 days if the form offers it, otherwise with the b2 CLI. Leave File Path and the days from uploading to hiding empty, or B2 hides and then deletes current files. SYNC deletes in B2 what the job prunes on the NAS, so old versions are the safety net.

Install the Compose stack

The repository copy in scripts/git-backup/ is the source of truth. Make changes in Git first, then copy them to the host. Keep one folder per stack under /home/igresc/, as with the other stacks. Dockge lists these stacks.

  1. Review scripts/git-backup/config.json. It lists 35 repositories: 34 owned by igresc and Aquadays/Aquadays. New repositories do not join automatically. Audit both owners from your workstation:

    gh repo list igresc --limit 100 --json name,isPrivate,isArchived
    gh repo list Aquadays --limit 100 --json name,isPrivate,isArchived
    
  2. Keep talos_versions aligned with talos_version in terraform/variables_talos.tf. CI checks the committed default. Keep both versions during an upgrade if recovery still needs the old version.

  3. From the repository root, create the stack folder and copy the files:

    ssh igresc@docker.local.isabelsoler.es 'mkdir -p /home/igresc/git-backup'
    scp scripts/git-backup/{Dockerfile,.dockerignore,compose.yaml,backup.py,askpass.py,serve.py,entrypoint.py,config.json,sshd_config} \
      igresc@docker.local.isabelsoler.es:/home/igresc/git-backup/
    
  4. In an SSH terminal as igresc on the Docker host, build the image:

    cd /home/igresc/git-backup
    docker compose build
    

This builds homelab-git-backup:local without starting the schedule or endpoint. The image contains scripts and config under /opt/git-backup. Renovate tracks its pinned Dockerfile base image.

The services use network_mode: bridge. The host's Docker address pools are exhausted, so the stack uses the existing bridge without a project network. Logging inherits the daemon's gelf driver and central collector. docker compose logs reads the local cache through Docker dual logging.

Docker mounts the named NFS volume git-backup_backups at /srv/git-backup inside containers. Defaults use nebula.local.isabelsoler.es, :/mnt/tank/backups/github, and nfsvers=4.2,hard,rw. For overrides, create an optional .env in the stack folder with GIT_BACKUP_NFS_SERVER, GIT_BACKUP_NFS_PATH, or GIT_BACKUP_SSH_PORT. Keep secrets out of this file.

Use NFSv4. Its locking is part of the protocol. NFSv3 locking needs the rpc-statd host service, and Docker volume mounts do not start it. Do not add nolock, soft, or a local fallback. The script checks findmnt --mountpoint before writing. NAS outages can block hard-mounted I/O, including shutdown. Kuma detects missed heartbeats. See Docker NFS volumes.

Docker fixes volume driver options at creation. To change NFS options, wait for an active backup to finish, then remove the containers and inspect the volume definition:

    cd /home/igresc/git-backup
    docker compose --profile flux down
    docker volume inspect git-backup_backups

Confirm that this volume points to the NAS export. Then remove only its mount definition:

    docker volume rm git-backup_backups

This does not delete NAS data. Update the settings and run a manual backup to recreate the volume. Restart only the services that were enabled. Preserve ./private, ./ssh, and the NAS dataset. Do not use docker compose down -v.

The job caches upstream metal-amd64.iso and sha256sum.txt for each configured Talos version. It checks SHA-256 on every run and prunes other versions only after all requested versions pass. This is the stock recovery ISO. The custom NoCloud installer with extensions still comes from Image Factory. See Talos release assets.

Create the read-only GitHub tokens

Fine-grained tokens are limited to one resource owner, so this stack needs two. The tokens map in config.json selects a token file for each owner. A repository's optional owner defaults to igresc. Every configured owner needs a token entry, and every token file must stay outside backup_dir.

  1. In GitHub, open Settings > Developer settings > Personal access tokens > Fine-grained tokens > Generate new token.
  2. Name it Docker host Git backup and select resource owner igresc.
  3. Select All repositories, or Only select repositories with every igresc repository in config.json. The token must cover all configured igresc repositories. Grant only Contents: Read-only and Metadata: Read-only.
  4. Set Expiration to No expiration for this unattended personal-account job, or set a renewal reminder if you choose an expiry. Review access during the yearly recovery drill. See GitHub token documentation.
  5. In an interactive SSH terminal as igresc, write the token through the container's hidden prompt:

    cd /home/igresc/git-backup
    docker compose run --rm git-backup set-secret github-token
    

Create the organization token next:

  1. An Aquadays organization owner must allow fine-grained tokens. Open the organization token settings (Settings > Third-party Access > Personal access tokens > Settings). On the Fine-grained tokens tab, select Allow access via fine-grained personal access tokens, choose an approval option, and save. See GitHub's organization token policy.
  2. In your personal settings, create a second fine-grained token named Docker host Git backup (Aquadays) with resource owner Aquadays. If Aquadays is missing from the list, the organization setting is not saved. Select Only select repositories and pick Aquadays. Grant Contents: Read-only. GitHub includes Metadata: Read-only. Use No expiration if the organization allows it. Otherwise take the longest allowed lifetime and set a renewal reminder.
  3. Save it through the hidden prompt:

    cd /home/igresc/git-backup
    docker compose run --rm git-backup set-secret github-token-aquadays
    
  4. If the organization requires approval, approve the request at the pending requests page before running the backup.

  5. Check that both token files exist:

    docker compose run --rm git-backup ls -l /etc/git-backup/private
    

Expect github-token, github-token-aquadays, and kuma-url, plus last-success after the first successful run, all -rw------- root root.

The command accepts kuma-url and the basenames of token files in config.json, currently github-token and github-token-aquadays. It refuses non-TTY input. It writes one nonempty line atomically with mode 0600, owned by container root, under /etc/git-backup/private. This path is inside the container and backed by ./private in the stack folder, outside the NFS tree. The entrypoint sets the root-owned directory to mode 0700. Token values do not enter arguments, environment variables, shell history, Git URLs, mirror config, or logs. Rotate each token with its set-secret command, run a backup, and revoke the old token after success.

Configure the external failure monitor

  1. Create a Push monitor in external Uptime Kuma. Use a 25-hour (90000 s) heartbeat interval, zero retries, and an enabled notification route. A run takes minutes, so a 24-hour interval would alert on normal days.
  2. Save its HTTPS push URL through the hidden prompt:

    cd /home/igresc/git-backup
    docker compose run --rm git-backup set-secret kuma-url
    
  3. Confirm an up heartbeat after the first backup. A missing URL logs a warning and skips the ping. Other ping errors fail the run. The job sends up only when all repositories and the Talos cache pass, otherwise down.

  4. Configure a separate monitor for the TrueNAS to B2 task. A Git fetch does not prove offsite freshness.

Run once and enable the schedule

  1. As igresc on the Docker host, run the backup and inspect its output:

    cd /home/igresc/git-backup
    docker compose run --rm git-backup run
    

Expect one <name>: mirror updated and bundle verified line per repository on its first run, then Talos <version>: ISO checksum verified, Kuma: up notification accepted, and finished with 0 failures. A second run takes seconds and logs <name>: unchanged; bundle skipped for every repository. Git transport details are suppressed to protect credentials. On failure, use this table:

| Message | Likely cause | Fix |
| --- | --- | --- |
| `<name>: git clone failed (exit 128)` | The owner's token is missing, wrong, unapproved, or doesn't cover the repository | Fix the token, then rerun |
| `<name>: git ls-remote failed (exit 128)` | Same token problems for a repository already backed up | Same |
| `<name>: <file> fails its checksum` or `is unreadable` | A bundle on the NAS is damaged | The job already wrote a new bundle. Check the NAS pool. |
| `another backup run holds the lock` | Another run is active | Wait. Never delete `.lock`. |

For NAS problems, verify the mount inside the container:

```bash
docker compose run --rm git-backup findmnt --mountpoint /srv/git-backup
```
  1. Run Run Now on the B2 task once. Confirm in the Backblaze web UI that homelab-igresc-backups/github/ contains bundles/ with each repository, including bundles/Aquadays/Aquadays/. Later runs copy new bundles only when repositories change. Local bundles are also unencrypted. Secrets in ./private never enter the NAS dataset.
  2. Restore one bundle.
  3. Enable the schedule:

    cd /home/igresc/git-backup
    docker compose up -d git-backup
    

The scheduler runs daily at 02:15 UTC and catches up on start if the last successful completion is missing, invalid, or at least 24 hours old. A failed attempt waits until the next daily slot or container restart. 5. Check the service and next run:

```bash
cd /home/igresc/git-backup
docker compose ps -a
docker compose logs --tail 100 git-backup
docker compose run --rm git-backup schedule-status
```

The scheduler logs its next UTC slot. schedule-status reports startup due logic without starting a backup. After the first scheduled run, check all mirrors, bundle dates, Kuma, and B2 task success before relying on the backup:

```bash
docker compose logs --since 24h git-backup | tail -5
```

Expect finished with 0 failures.

The last-success marker lives in ./private so container replacement does not reset it and the SSH endpoint cannot read it. Only a fully successful run advances it, while holding /srv/git-backup/.lock. Manual runs use the same lock and marker. Overlapping runs fail without changing the marker. Never delete the lock file. The kernel releases the lock when the process exits.

For an existing mirror, the job compares upstream advertised refs with local refs, ignoring HEAD and peeled annotated tag entries. If they match, it skips the old-main protection bundle and fetch. See git ls-remote. It then compares the mirror's refs with those in the newest retained dated bundle. If they match and the bundle still has the SHA-256 digest recorded in its .sha256 file after verification, it logs unchanged; bundle skipped and still prunes retained bundles. A bundle that fails the digest or can't be read gets replaced by a new verified bundle, and that run reports failure once. A bundle without a digest file gets replaced without failure. Otherwise it writes a self-contained bundle of all Git refs. It also creates a bundle when none is retained, including after a successful fetch whose bundle step failed. See git bundle list-heads.

Retention keeps the newest bundle from each of the latest 30 dates that have a bundle and the first bundle from each of the latest 12 months that have a bundle. After the initial bundle, new dates exist only when repository refs change or no dated bundle remains. This is not a rolling 30-calendar-day window. A bundle can satisfy both rules. Dates use UTC. An old bundle date can be healthy when the repository is unchanged. Check the success marker and Kuma for job freshness. Before accepting any bundle, the job restores it into a temporary bare repository and runs git fsck --full. Allow scratch space for one repository restore in addition to its mirror and retained bundles. Header verification alone cannot detect packed-object corruption. Git LFS payloads, issues, releases, Actions artifacts, and packages are outside Git bundle coverage.

The existing igresc paths stay at mirrors/<name>.git, bundles/<name>/, and history/<name>/. Other owners use mirrors/<owner>/<name>.git, bundles/<owner>/<name>/, and history/<owner>/<name>/. Logs use <name> for igresc and <owner>/<name> for other owners. A default-owner repository cannot have the same name as another configured owner because their directories would collide.

If main loses history or is deleted, the job keeps a verified old-main bundle under the repository's history directory and reports failure. The mirror and its new dated bundle still reflect upstream. Inspect the retained history before accepting the rewrite. History bundles are never pruned automatically. A failed fetch or an interrupted run can also leave a history bundle. Keep it until you have checked the repository. Other repositories still run after a failure.

Add a repository

  1. Add the repository to repos in scripts/git-backup/config.json. Set owner for repositories outside igresc, and add that owner to tokens with a new token file. Validate, commit, and push.
  2. If the igresc token uses Only select repositories, edit it on GitHub and add the repository. The token value stays the same. A new owner needs its own token, created as in the organization token steps.
  3. Update the stack and run a manual backup.

Update the stack

Wait for an active backup to finish. Make the change in Git, then copy the changed files from scripts/git-backup/ to the stack folder with scp. On the Docker host, rebuild the image:

    cd /home/igresc/git-backup
    docker compose build

If the schedule is enabled, replace its container:

    docker compose up -d git-backup

If the Flux endpoint is enabled, replace its container too:

    docker compose --profile flux up -d flux-ssh

Leave disabled services stopped. Check logs after replacing each container.

Disable or roll back the stack

Wait for an active backup to finish. Stop scheduling as igresc:

    cd /home/igresc/git-backup
    docker compose stop git-backup

To stop and remove both service containers, use:

    docker compose --profile flux down

Restore the normal Flux source before stopping an endpoint that Flux uses. Stopping an active job can leave a partial file or an extra history bundle. The next run compares refs and verifies any new bundle before accepting it.

To roll back an image or configuration change, revert the change in Git and copy the previous stack files to the host. Keep scheduling stopped while you rebuild and test a manual backup:

    cd /home/igresc/git-backup
    docker compose build
    docker compose run --rm git-backup run

Versions before commit efcebdd ignore .sha256 files and owner folders such as Aquadays/, and back up only igresc repositories. After an upgrade from such a version, the first run replaces each old bundle once because it has no checksum file. This is not a failure.

After success, restart only the services that were enabled. Preserve ./private, ./ssh, the NFS volume, NAS snapshots, mirrors, bundles, and history files.

Restore a bundle

Copy a selected bundle to a recovery workstation. Use an empty directory for verification, since git bundle verify needs a Git repository:

    git init --bare verify.git
    git -C verify.git bundle verify /absolute/path/to/selected.bundle
    git clone --mirror /absolute/path/to/selected.bundle recovered.git
    git -C recovered.git fsck --full
    git -C recovered.git log -1 --oneline main

Check the commit against the intended recovery point. Clone recovered.git into a working checkout when you need files. To restore upstream, review the refs first and obtain approval before pushing. A mirror push can delete refs. For an old-main protection bundle, only main is restored.

Prepare the read-only Flux SSH endpoint

The optional flux-ssh service uses the Compose flux profile and is off by default. It uses container root with PermitRootLogin forced-commands-only. Each key has restrict and a forced command, and sshd enforces the same command globally. Passwords, shells, forwarding, user startup files, and TTYs are disabled. The handler permits only git-upload-pack of the exact homelab path. The backup volume is read-only, the container filesystem is read-only, and the ./private bind mount is absent. This avoids user and ACL management on the NAS. Only the capabilities sshd needs for identities, privilege separation, and its listening port remain. No host SSH configuration changes.

  1. After a successful backup, create ./authorized_keys by hand in the stack folder. Add one line per cluster using this form. Replace the sample key with the cluster's plain ed25519 public key:

    restrict,command="/usr/local/bin/python3 /opt/git-backup/serve.py" ssh-ed25519 AAAA... staging
    

Staging's public key is identity.pub at OpenBao kv/infra/github/flux-staging. Add production Talos once its key exists. No private Flux key goes on the Docker host. Leave production k3s unchanged. 2. Allow the endpoint port only from trusted LAN and cluster networks. Confirm that existing firewall rules permit that access. The default host port is 2222. Override GIT_BACKUP_SSH_PORT in the optional .env if needed. Start the endpoint:

```bash
cd /home/igresc/git-backup
docker compose --profile flux up -d flux-ssh
```

The container copies authorized_keys to a root-owned file in /run, so sshd can enforce StrictModes. After changing keys, restart it to reload:

```bash
docker compose --profile flux restart flux-ssh
```
  1. Get the persisted ed25519 host-key fingerprint over a trusted administrator connection:

    cd /home/igresc/git-backup
    docker compose exec flux-ssh ssh-keygen -lf /var/lib/git-backup/ssh/ssh_host_ed25519_key.pub -E sha256
    

The key is generated on first start in ./ssh. Preserve that bind mount across image rebuilds. From the recovery workstation, collect its public key and compare fingerprints before trusting it:

```bash
ssh-keyscan -p 2222 -t ed25519 docker.local.isabelsoler.es > docker-known-hosts
ssh-keygen -lf docker-known-hosts -E sha256
```
  1. With the Flux identity and verified known hosts, test git ls-remote and a clone. Confirm that shell access and git-receive-pack are denied. Use:

ssh://root@docker.local.isabelsoler.es:2222/srv/git-backup/mirrors/homelab.git

Known hosts must identify [docker.local.isabelsoler.es]:2222. Store identity, identity.pub, and known_hosts in the Flux SSH Secret through the approved secret workflow. Never commit private keys. See Flux SSH authentication. 5. Once the source URL is a bootstrap input, set it to this URL and select the matching Secret. Keep branch main and the cluster's sync path. Today kubernetes/clusters/staging/flux-system/flux-instance.yaml sets the source and Flux reconciles it from Git. Follow Cilium and Flux bootstrap when that input exists. Do not patch a live GitRepository whose owner can revert it. 6. In an approved staging drill with GitHub blocked, confirm a successful reconcile, restore the normal bootstrap source, and confirm reconciliation. Record evidence in the commit message.

To disable the endpoint, restore the normal bootstrap source first. Then stop its container:

    cd /home/igresc/git-backup
    docker compose --profile flux stop flux-ssh

Preserve ./ssh, ./authorized_keys, and all backups.

docs/runbooks/git-backup.md