diff --git a/docs/DATA_PERSISTENCE.md b/docs/DATA_PERSISTENCE.md new file mode 100644 index 0000000..8e8cdcd --- /dev/null +++ b/docs/DATA_PERSISTENCE.md @@ -0,0 +1,52 @@ +# Durable Docker state + +The bot stores runtime state in `/app/data`: + +- `global_memory.json` — global facts and preferences; +- `sessions/` — conversation history; +- `calendar_token.json` — Google OAuth token, if enabled. + +`docker-compose.yml` mounts the host directory `${DATA_DIR_HOST:-./data}` to `/app/data` and sets `DATA_DIR=/app/data` inside the container. + +## First deployment / migration + +Back up the existing state before recreating the container: + +```bash +mkdir -p data +cp -a data "data.backup.$(date +%Y%m%d-%H%M%S)" + +# If the old container has the only copy, copy it BEFORE removing it: +docker cp homeagent:/app/data/. ./data/ + +docker compose config +docker compose up -d --build +``` + +If the old state was written into the container layer at another path, find it first: + +```bash +docker exec homeagent sh -lc 'find /app /root -maxdepth 4 -type f \( -name global_memory.json -o -path "*/sessions/*.json" \) -print' +``` + +## Verify after restart + +```bash +docker compose exec homeagent sh -lc '\ +printf "DATA_DIR=%s\\n" "$DATA_DIR"; \ +mount | grep /app/data; \ +ls -la /app/data; \ +find /app/data/sessions -type f 2>/dev/null | head' +``` + +Then restart and verify the same files remain: + +```bash +docker compose restart homeagent +``` + +## Important + +- Do not run `docker compose down -v` before backing up `data/`. +- Check `df -h .` and `docker system df`: a previous `No space left on device` error can prevent writes. +- This change cannot recover data that was already deleted; it only prevents future loss once deployed.