⚡ Key takeaways
hermes backupmakes one zip with your keys in it. Fine offline, wrong for Git.- The agent’s “brain” (config, skills, memory, sessions) is a few MB; the rest of
~/.hermesis gigabytes of rebuildable tools and caches. - A backup needs a gate, not just an ignore list: a duplicate login token would have ended up on GitHub.
- Run the script with
--dry-rununtil the file list looks right, then schedule it.
An agent that runs for weeks builds up memory, skills and sessions you don’t want to lose. This Hermes Agent backup runs every night to a private GitHub repository, with a script that searches every file for your real secret values before it pushes. I built it on my own Hermes Agent VPS, and the gate caught a leaked token on the first dry run.
Why not just use hermes backup?
Hermes has a built-in backup: hermes backup writes the whole Hermes home to one zip, and hermes import restores it. That zip includes .env and auth.json, your keys and logins. Keep it as an offline copy. For an automatic, off-server backup in Git, you want the opposite: everything except the secrets.
Step 1: a private repo and a deploy key
A deploy key is an SSH key that works for one repository only, so no personal token lives on the server. Create an empty private repository first, then on the server:
ssh-keygen -t ed25519 -N "" -C "hermes-brain deploy key" -f ~/.ssh/hermes-brain_ed25519 cat ~/.ssh/hermes-brain_ed25519.pub
Add that public key in the repository under Settings, Deploy keys, and tick Allow write access. Instead of trusting GitHub’s host key on first contact, I pinned it from api.github.com/meta, which is served over TLS, and gave the repository its own SSH alias:
curl -s https://api.github.com/meta | python3 -c "import json,sys; [print('github.com', k) for k in json.load(sys.stdin)['ssh_keys']]" >> ~/.ssh/known_hosts
# ~/.ssh/config
Host github-hermes-brain
HostName github.com
User git
IdentityFile ~/.ssh/hermes-brain_ed25519
IdentitiesOnly yes
StrictHostKeyChecking yes
Now turn ~/.hermes itself into a git repository:
cd ~/.hermes git init -b main git remote add origin git@github-hermes-brain:YOUR_GITHUB_USER/hermes-brain.git git config user.name "hermes-backup" git config user.email "hermes-backup@localhost"
Step 2: decide what to leave out
I started with the obvious exclusions: .env, auth.json, *.key, hermes-agent/ and logs/. A dry run showed that this list was not enough:
- Size: 2.8 GB with
tools/,cache/andinstalls/. Without them, the brain is a few MB. - Secrets: Hermes keeps a second copy of the login token in
shared/nous_auth.json. - Databases: live SQLite files cannot be copied safely, so the script makes consistent snapshots first.
This is the .gitignore I ended up with. The file names are from Hermes v0.23.0, so check your own with a dry run:
# ~/.hermes/.gitignore # secrets .env .env.* auth.json *auth*.json *.key *.pem *.token # big or rebuildable hermes-agent/ tools/ installs/ cache/ *_cache/ logs/ backups/ telemetry/ source-checks/ # live databases (the script writes safe copies to db-snapshots/) *.db *.db-wal *.db-shm # runtime noise *.lock *.tmp runtime/ state/ cron/ticker_* gateway.pid gateway_state.json
Step 3: the backup script and its gate
An ignore list is a promise about file names. It says nothing about what is inside the files that remain. So before every commit, the script reads the real secret values from .env and auth.json and searches every file about to be committed for them, including the database snapshots. If it finds one, it stops, names the file and pushes nothing. It also refuses forbidden file names, nested git repositories and anything over 100 MB.
Save this as ~/.local/bin/hermes-brain-backup and run chmod 755 on it. With --dry-run it runs every check and lists what would be committed, but commits and pushes nothing.
#!/usr/bin/env bash
# ~/.local/bin/hermes-brain-backup
# Nightly backup of ~/.hermes to a private GitHub repo. What stays out is listed in ~/.hermes/.gitignore.
# Usage: hermes-brain-backup real run (output goes to a log file)
# hermes-brain-backup --dry-run run every check and show the result, commit and push nothing
set -euo pipefail
DRY=0; [ "${1:-}" = "--dry-run" ] && DRY=1
H="$HOME/.hermes"
LOG="$HOME/.local/state/hermes-brain-backup.log"
mkdir -p "$(dirname "$LOG")" "$HOME/.cache"
if [ "$DRY" = 0 ]; then exec >>"$LOG" 2>&1; fi
echo "=== $(date -Is) start (dry-run=$DRY) ==="
exec 9>"$HOME/.cache/hermes-brain-backup.lock"
flock -n 9 || { echo "previous run still active, skipping"; exit 0; }
cd "$H"
# 1) Consistent copies of the live SQLite databases (the .db files themselves are ignored by git)
python3 - <<'PY'
import os, sqlite3
home = os.path.expanduser("~/.hermes")
out = os.path.join(home, "db-snapshots")
os.makedirs(out, exist_ok=True)
skip = {"hermes-agent","tools","installs","cache","logs","backups","telemetry","source-checks","db-snapshots",".git"}
for root, dirs, files in os.walk(home):
dirs[:] = [d for d in dirs if d not in skip and not d.endswith("_cache")]
for f in files:
if f.endswith(".db"):
src = os.path.join(root, f)
rel = os.path.relpath(src, home).replace(os.sep, "__")
dst = os.path.join(out, rel + ".sqlite3")
try:
s = sqlite3.connect("file:" + src + "?mode=ro", uri=True)
d = sqlite3.connect(dst)
s.backup(d); d.close(); s.close()
print("snapshot:", rel)
except Exception as e:
print("snapshot FAILED:", rel, e)
PY
# 2) Rebuild the index from scratch, so anything newly ignored also leaves the next commit
git rm -r -q --cached -f . >/dev/null 2>&1 || true
git add -A
# 3) Safety gates: when in doubt, stop and never push
BAD="$(git ls-files | grep -E '(^|/)(\.env(\..*)?|auth\.json)$|\.(key|pem)$|^hermes-agent/|^logs/' || true)"
if [ -n "$BAD" ]; then echo "STOP: forbidden file in the index:"; echo "$BAD"; exit 2; fi
LINKS="$(git ls-files -s | awk '$1=="160000"{print $4}')"
if [ -n "$LINKS" ]; then echo "STOP: nested git repo in the index:"; echo "$LINKS"; exit 4; fi
python3 - <<'PY'
import json, os, re, subprocess, sys
home = os.path.expanduser("~/.hermes")
secrets = set()
envp = os.path.join(home, ".env")
if os.path.exists(envp):
for line in open(envp, encoding="utf-8", errors="ignore"):
line = line.strip()
if not line or line.startswith("#") or "=" not in line: continue
k, v = line.split("=", 1)
v = v.strip().strip('"').strip("'")
if re.search(r"KEY|TOKEN|SECRET|PASS|CRED", k, re.I) and len(v) >= 12:
secrets.add(v)
def strings(o, key=""):
if isinstance(o, dict):
for k, x in o.items(): yield from strings(x, str(k))
elif isinstance(o, list):
for x in o: yield from strings(x, key)
elif isinstance(o, str): yield key, o
ap = os.path.join(home, "auth.json")
if os.path.exists(ap):
try:
for k, s in strings(json.load(open(ap))):
if len(s) >= 16 and re.search(r"token|secret|key|password|credential|cookie|bearer", k, re.I) and not re.search(r"(_at|_url|type|id)$", k, re.I):
secrets.add(s)
except Exception: pass
names = [n for n in subprocess.run(["git","diff","--cached","--name-only","-z"],capture_output=True,cwd=home).stdout.split(b"\0") if n]
bad, total = [], 0
for n in names:
p = os.path.join(home, n.decode())
try: data = open(p,"rb").read()
except Exception: continue
total += len(data)
if any(s.encode() in data for s in secrets) or re.search(rb"-----BEGIN [A-Z ]*PRIVATE KEY-----", data):
bad.append(n.decode())
if bad:
print("STOP: secret found in:", ", ".join(sorted(set(bad)))); sys.exit(3)
if total > 100*1024*1024:
print("STOP: too big for a backup (%d MB)" % (total//1048576)); sys.exit(5)
print("secret check OK: %d values checked in %d files (%.1f MB)" % (len(secrets), len(names), total/1048576))
PY
# 4) Dry run: show what would be committed, then stop
if [ "$DRY" = 1 ]; then
echo "== files per top-level folder =="; git ls-files | awk -F/ '{print ($2==""?"(loose file)":$1)}' | sort | uniq -c | sort -rn
exit 0
fi
# 5) Commit and push
if git diff --cached --quiet; then echo "no changes"; exit 0; fi
git commit -q -m "backup $(date -Is)"
git push -q origin HEAD:main
echo "=== $(date -Is) done: pushed ($(git rev-parse --short HEAD)) ==="
The gate earned its place on the first dry run. Search for the actual secret values, not just file names: it stopped on shared/nous_auth.json, a duplicate of the login token that my ignore list did not cover, before anything left the server.
One mistake of my own is worth copying as a rule: I hid the error output of a git rm --cached command, so it failed silently and the token file stayed in the index. Never hide errors from security steps.
Step 4: test it, then schedule it
- Run
~/.local/bin/hermes-brain-backup --dry-run. - Read the file list and add anything unexpected to
.gitignore. - Repeat until the list looks right.
- Run it once without
--dry-runand check the commit on GitHub. - Run it once in a bare environment like cron’s:
env -i HOME=$HOME PATH=/usr/bin:/bin ~/.local/bin/hermes-brain-backup. - Add it with
crontab -e.
17 3 * * * /home/youruser/.local/bin/hermes-brain-backup
Cron uses the server’s time zone, which was Europe/Vilnius on my VPS. The job ran and pushed at 03:17 on both nights after, and GitHub’s latest commit matched the one on the server.
Two honest caveats: the backup contains your conversation history and memories, which is why the repository must be private, and I have not tested a restore yet. Do that on a spare machine before you rely on it.
Troubleshooting
The script stops with “secret found”
That is the gate working. It names the file that contains a secret value. Add that file to .gitignore and run the script with --dry-run again before the next push.
“STOP: too big for a backup”
A large folder is not ignored yet. The dry run lists the files per top-level folder; add the big one to .gitignore.
This article is part of the Agentic AI series.
The Tested Weekly
One email a week with the guides we tested, sources linked. No spam.