Skip to content

Keeping History

Outcome: reports that survive log rotation — GoAccess's counted model saved to disk with --persist, resumed with --restore, and added to run after run.

The problem rotation makes

Servers rotate their logs: at midnight or at a size limit, access.log is renamed away and a fresh one starts. Yesterday's file alone knows yesterday. Run GoAccess on today's file and the report begins from zero — fine for a glance, useless for "this month so far".

GoAccess's answer is to persist not the log but the counts. With --persist it writes its whole counted model to a folder of database files on exit; with --restore a later run loads that model first and adds the new log's lines on top. Reports accumulate; logs can rotate away on schedule.

The workflow, run for real

The lab split its 27-line log into a 20-line first part and a 7-line second part — yesterday and today, in miniature (transcripts t08 and t09-persistence.txt):

mkdir db
goaccess part1.log --log-format=COMBINED \
  --persist --db-path=db -o run1.json
# ... the server rotates; a new log appears ...
goaccess part2.log --log-format=COMBINED \
  --restore --db-path=db -o run2.json

The first report totals 20. The second totals 27 — the restored 20 plus the new 7 — with the same 5 unique visitors the full log reports. Nothing was double-counted, because each part was fed exactly once: that discipline is yours to keep. Restore the same lines twice and they will be counted twice; persistence remembers what you fed it, not what you meant.

Inside db/ the lab counted 151 small .db files — one per panel, metric and key family. You never edit these. You back the folder up or delete it, as a whole, like any small database.

The sharp edge, met head-on

The lab's first attempt failed, and the failure is worth the space it takes:

Fatal error has occurred
Error occurred at: src/persistence.c - set_db_path - 67
Unable to open the specified db path/file 'db'. No such file or directory

--db-path must name a directory that already exists. GoAccess will fill it, but will not create it. One mkdir is the whole fix — and the run is a good example of this tool's manners: when it cannot proceed it says so, names its file and line, and stops, rather than guessing. (The report file for that run was still written before the persistence step failed — check a run's totals before trusting that its storage half succeeded.)

Keeping only the recent past

Unbounded history is its own problem, so persistence pairs with --keep-last:

--keep-last=<days>   Keep the last N days in storage

With it set, restored runs prune data older than the window as they go, and the database folder holds a rolling month (or whatever span you choose) instead of everything since the beginning. The lab did not exercise this flag against a multi-day log — its log spans an hour — so it is documented here from the program's own help text rather than from a run, and criteria.md says so. Two neighbouring facts were run: the persisted model restores across separate invocations and processes, and the default --db-path, when you omit it, is the system temporary folder — which is exactly why you name your own: history kept in a temp folder is history one cleanup away from gone.