# Export the audit trail

The audit trail can go to your log collector each day, or into a file for any time range.

Requires [OSMates Team](https://osmates.com/docs/editions#what-team-adds).

## Export each day to a folder

1. Add `AuditExportFolder` to your [organization's profile](https://osmates.com/docs/organization-policy), with the folder.
2. To keep more or fewer than 30 exports, add `AuditExportKeep`.
3. Have your collector take each `osmates-audit-<time>.jsonl` file from the folder.

The first export holds the whole trail, and each later one the records since the one before. People can't change the folder or turn the export off.

Without a profile, set the folder in Terminal:

```sh
osmates audit schedule ~/Library/Logs/OSMates\ Audit
```

Run `osmates audit schedule` alone to see the last export and the next one.

## Export a time range

To export the records since 1 November 2026 to a file:

```sh
osmates audit export --since 2026-11-01 --to audit.jsonl
```

Add `--machine` or `--client` for one machine's or one agent's records.

## Verify an export

To check the exports in a folder against the trail:

```sh
osmates audit verify --against ~/Library/Logs/OSMates\ Audit
```

It exits 1 when a record was changed or removed, or doesn't match the trail.

Your collector can also check an export without OSMates:

- The first line names the export's [schema](https://osmates.com/schemas/0/files/audit-export.json).
- Each line between the first and the last is a record as OSMates stored it.
- A record's `hash` is the SHA-256 of its line without the `hash` member.
- A record's `prev` is the `hash` of the record before.
- The first record's `prev` matches the last `hash` of the export before.
- The last line counts the records. An export without it was cut short.

## Limits

- A folder must be a full path or start with `~/`. A wrong `AuditExportFolder` or `AuditExportKeep` is left out.
- An export is only as safe as its folder. Programs running as the person can change a folder the person can write to.
