Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ BACKUP_INTERVAL_MS=
# event, each tagged with the program version and a random installation ID
# (nothing else), to the maintainers' trace service. Nothing about the users or
# repositories being backed up is sent.
# Set to false to turn it off. See CONFIG.md and
# Set to false to turn it off. It fails closed: anything but true, on, yes or 1
# (blank or a typo included) turns it off. See CONFIG.md and
# https://danielstephenson.dev/usage-reporting
USAGE_REPORTING_ENABLED=true

# The switch every trace client honours, checked before USAGE_REPORTING_ENABLED:
# off (or false, 0, no) turns reporting off. Leave empty for "not set".
# off (or false, 0, no -- anything but true, on, yes or 1) turns reporting off.
# Leave empty for "not set".
TRACE_USAGE_REPORTING=

# The https://consoledonottrack.com convention: 1 (or true, yes) turns it off too.
# The https://consoledonottrack.com convention: 1 (or true, yes -- anything but
# 0, false, off or no) turns it off too.
DO_NOT_TRACK=

# Pins the installation ID sent as the 'install' tag. Leave empty to have one
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Fixed

- Usage reporting now stays off once it is turned off. `usage.reporting.enabled` / `USAGE_REPORTING_ENABLED` used to turn reporting off only for `false`: `off`, `no`, `0`, a blank value or a typo all left it on. It now fails closed and is read through the trace client's `allowsReporting` helper: only `true`, `on`, `yes` or `1` (any case) keeps reporting on, and anything else turns it off. `docker-compose.yml` now passes a blank `USAGE_REPORTING_ENABLED` through as blank (off) instead of replacing it with `true`. The vendored `TraceClient` is now trace-client-java 0.8.0, whose `TRACE_USAGE_REPORTING` and `DO_NOT_TRACK` checks fail closed too: `TRACE_USAGE_REPORTING` set to anything but blank or `true`/`on`/`yes`/`1`, `DO_NOT_TRACK` set to anything but blank or `0`/`false`/`off`/`no`, or an environment that cannot be read, turns reporting off

### Added

- Usage reporting to the maintainers' trace service: a `startup` event once per process and a `backup-completed` event when a backup run finishes, each tagged with the program version and a random installation ID (`TRACE_INSTALL_ID`, or a UUID kept in `~/.config/gh-backup/trace-install-id`) and nothing else, sent from a background thread that never delays a backup or holds up exit by more than the client's 5-second timeout. Nothing about the users, organizations or repositories being backed up is sent. On by default; a one-line notice is logged the first time it runs on a machine (recorded in `~/.config/gh-backup/usage-reporting-notice-shown`), and it is turned off with `-Dusage.reporting.enabled=false` or `USAGE_REPORTING_ENABLED=false` (`usage.reporting.endpoint` and `usage.reporting.key` are documented in `CONFIG.md`; the Docker daemon takes `USAGE_REPORTING_ENABLED` from `.env`)
Expand All @@ -20,7 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Unit tests for `POST /api/backups` request validation: a missing or blank `userOrOrg`, a leading, trailing or doubled hyphen, characters outside letters, digits and hyphens, and a name longer than 39 characters each return `400 Bad Request` without starting a backup or reporting a completed one, while a 39-character name and a single inner hyphen are accepted; a successful backup reports exactly one `backup-completed` event and a failed one reports none. Before these, the `400` behavior documented in `COMMANDS.md` was untested.
- Unit tests for the clone/fetch progress monitor's `backup.progress.overwrite` handling and update edge cases: overwrite mode is the default when the property is unset, `false` (or any value other than `true`) selects one line per update, progress reported before any task has begun is ignored, an update reaching or overshooting the task's total leaves the `100%` line to the end of the task, and in overwrite mode each update rewrites the current line. Before these, the system property documented in `COMMANDS.md` and `CONFIG.md` was not read by any test.
- Unit tests for two `BackupService` paths that had no assertions: a repository whose directory already exists but is not a Git repository is reported as a failed update (`✗ Failed to update`, then named in the failure summary) without being cloned over or having its contents touched, while the other repositories are still backed up; and a relative `backup.directory` is resolved against the working directory and normalized, as the path printed by `status` shows. Before these, the update-failure branch was never run by a test and the relative-path test only checked that nothing was thrown.
- Unit tests for `UsageReportingService`'s value handling and no-home path: only `false` (in any case, with surrounding spaces) turns reporting off, while values such as `no`, `0` and `off` leave it on, as `COMMANDS.md` documents for `USAGE_REPORTING_ENABLED`; the version is trimmed and a missing or blank one is sent as `unknown`; the installation ID file sits next to the notice marker; and without a usable home directory there is no notice marker and no installation ID, while the `startup` event is still sent. Before these, only the `false`/blank cases and the unfiltered `@project.version@` placeholder were tested.
- Unit tests for `UsageReportingService`'s value handling and no-home path: only `true`, `on`, `yes` or `1` (in any case, with surrounding spaces) keeps reporting on, while `false`, `no`, `0`, `off`, a blank value and typos turn it off, as `COMMANDS.md` documents for `USAGE_REPORTING_ENABLED` (see Fixed); the version is trimmed and a missing or blank one is sent as `unknown`; the installation ID file sits next to the notice marker; and without a usable home directory there is no notice marker and no installation ID, while the `startup` event is still sent. Before these, only the `false`/blank cases and the unfiltered `@project.version@` placeholder were tested.

### Changed

Expand Down
6 changes: 3 additions & 3 deletions COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ java -Dspring.profiles.active=web -Dserver.port=9000 -jar target/gh-backup-2.0.0

### `-Dusage.reporting.enabled=<true|false>`

**Description:** Turn usage reporting off with `false`. When on, a `startup` event and a `backup-completed` event, carrying only the program version and a random installation ID, are sent to the maintainers' trace service; see [`usage.reporting.enabled`](CONFIG.md#usagereportingenabled) for exactly what is sent and the other ways to opt out.
**Description:** Turn usage reporting off with `false` (or anything but `true`, `on`, `yes` or `1`). When on, a `startup` event and a `backup-completed` event, carrying only the program version and a random installation ID, are sent to the maintainers' trace service; see [`usage.reporting.enabled`](CONFIG.md#usagereportingenabled) for exactly what is sent and the other ways to opt out.
**Default:** `true`
**Example:**
```bash
Expand All @@ -156,7 +156,7 @@ java -jar target/gh-backup-2.0.0-SNAPSHOT-8-8-2026.jar octocat

### `USAGE_REPORTING_ENABLED`

**Description:** Set to `false` to turn usage reporting off, the same as `-Dusage.reporting.enabled=false`. Any other value, or leaving it unset or empty, leaves reporting on.
**Description:** Set to `false` to turn usage reporting off, the same as `-Dusage.reporting.enabled=false`. It fails closed: only `true`, `on`, `yes` or `1` (any case) keeps reporting on, and any other value — `off`, `no`, `0`, empty, a typo — turns it off. Leaving it unset leaves reporting on.
**Required:** No
**Example:**
```bash
Expand All @@ -166,7 +166,7 @@ java -jar target/gh-backup-2.0.0-SNAPSHOT-8-8-2026.jar octocat

### `TRACE_USAGE_REPORTING` and `DO_NOT_TRACK`

**Description:** The opt-outs every trace client honours, checked before gh-backup's own setting. `TRACE_USAGE_REPORTING=off` (also `false`, `0`, `no`) or `DO_NOT_TRACK=1` (also `true`, `yes`) turns usage reporting off regardless of `usage.reporting.enabled`.
**Description:** The opt-outs every trace client honours, checked before gh-backup's own setting. `TRACE_USAGE_REPORTING=off` (or any value but blank, `true`, `on`, `yes` or `1`) or `DO_NOT_TRACK=1` (or any value but blank, `0`, `false`, `off` or `no`) turns usage reporting off regardless of `usage.reporting.enabled`.
**Required:** No
**Example:**
```bash
Expand Down
8 changes: 4 additions & 4 deletions CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ java -Dlogging.level.root=INFO -jar target/gh-backup-2.0.0-SNAPSHOT-8-8-2026.jar

**Type:** boolean
**Default:** `true`
**Description:** Whether gh-backup reports that it was used to the maintainers' trace service. When on, two events are sent, both from a background thread that never blocks or delays a backup: `startup` once per process and `backup-completed` when a backup run finishes. Both carry the same two tags and nothing else: `version`, the program version, and `install`, a random installation ID that lets installations be counted rather than events. The installation ID is the value of the `TRACE_INSTALL_ID` environment variable when that is set and not blank; otherwise it is a random UUID written the first time reporting runs to `~/.config/gh-backup/trace-install-id` and reused after that (delete the file to get a new one). Nothing about the users, organizations or repositories being backed up is sent, and no usernames, hostnames, IP addresses or paths. The first time reporting runs on a machine, one `INFO` line saying so is logged, and a marker file (`~/.config/gh-backup/usage-reporting-notice-shown`) keeps it from repeating; delete that file to see the notice again. gh-backup has no settings file of its own, which is why the marker and the installation ID file live there. If the JVM has no usable home directory (`user.home` unset or blank), there is nowhere to keep the marker or the installation ID, so the notice is logged on every run and events carry no `install` tag unless `TRACE_INSTALL_ID` is set. Setting the property to `false` sends nothing, logs no notice, writes no marker, and neither reads nor writes the installation ID file. As with every other property, it can also be set in an `application.properties` next to the JAR, and it is read from a `USAGE_REPORTING_ENABLED` environment variable, which is how the Docker image is configured. Independently of this property, the environment variables every trace client honours also turn reporting off and are checked first: `TRACE_USAGE_REPORTING=off` (also `false`, `0`, `no`) and `DO_NOT_TRACK=1` (also `true`, `yes`; see https://consoledonottrack.com). Details on what trace collects and why: https://danielstephenson.dev/usage-reporting
**Description:** Whether gh-backup reports that it was used to the maintainers' trace service. When on, two events are sent, both from a background thread that never blocks or delays a backup: `startup` once per process and `backup-completed` when a backup run finishes. Both carry the same two tags and nothing else: `version`, the program version, and `install`, a random installation ID that lets installations be counted rather than events. The installation ID is the value of the `TRACE_INSTALL_ID` environment variable when that is set and not blank; otherwise it is a random UUID written the first time reporting runs to `~/.config/gh-backup/trace-install-id` and reused after that (delete the file to get a new one). Nothing about the users, organizations or repositories being backed up is sent, and no usernames, hostnames, IP addresses or paths. The first time reporting runs on a machine, one `INFO` line saying so is logged, and a marker file (`~/.config/gh-backup/usage-reporting-notice-shown`) keeps it from repeating; delete that file to see the notice again. gh-backup has no settings file of its own, which is why the marker and the installation ID file live there. If the JVM has no usable home directory (`user.home` unset or blank), there is nowhere to keep the marker or the installation ID, so the notice is logged on every run and events carry no `install` tag unless `TRACE_INSTALL_ID` is set. Setting the property to `false` — or to anything but `true`, `on`, `yes` or `1` (any case), blank or a typo included, since it fails closed — sends nothing, logs no notice, writes no marker, and neither reads nor writes the installation ID file. As with every other property, it can also be set in an `application.properties` next to the JAR, and it is read from a `USAGE_REPORTING_ENABLED` environment variable, which is how the Docker image is configured. Independently of this property, the environment variables every trace client honours also turn reporting off and are checked first: `TRACE_USAGE_REPORTING=off` (or any value but blank, `true`, `on`, `yes` or `1`) and `DO_NOT_TRACK=1` (or any value but blank, `0`, `false`, `off` or `no`; see https://consoledonottrack.com). Details on what trace collects and why: https://danielstephenson.dev/usage-reporting

**Override at runtime:**
```bash
Expand Down Expand Up @@ -189,9 +189,9 @@ When the image built from the included `Dockerfile` is used, the container alway
| `BACKUP_INTERVAL_MS` | `backup.scheduled.interval.ms` | *(empty)* | Delay between scheduled backups, in milliseconds. Passed to the application only when non-empty; when empty, the default of `86400000` (24 hours) from `application-daemon.properties` applies. |
| `BACKUP_DIRECTORY` | `backup.directory` | `/backups` | Backup directory inside the container. |
| `GITHUB_TOKEN` | *(read directly by the application)* | *(unset)* | GitHub personal access token, as described above. |
| `USAGE_REPORTING_ENABLED` | `usage.reporting.enabled` *(read directly by the application)* | *(unset)* | When unset, the application's default of `true` applies; `docker-compose.yml` passes `true` unless `.env` gives it a non-empty value. Set to `false` to stop the daemon reporting `startup` and `backup-completed` events to the trace service, as described above. |
| `TRACE_USAGE_REPORTING` | *(read directly by the vendored trace client)* | *(unset)* | `off` (or `false`, `0`, `no`) stops reporting regardless of `USAGE_REPORTING_ENABLED`. |
| `DO_NOT_TRACK` | *(read directly by the vendored trace client)* | *(unset)* | `1` (or `true`, `yes`) stops reporting too, per https://consoledonottrack.com. |
| `USAGE_REPORTING_ENABLED` | `usage.reporting.enabled` *(read directly by the application)* | *(unset)* | When unset, the application's default of `true` applies; `docker-compose.yml` passes `true` only when `.env` does not set it, and passes an empty value through as empty, which is off. Set to `false` (or anything but `true`/`on`/`yes`/`1`) to stop the daemon reporting `startup` and `backup-completed` events to the trace service, as described above. |
| `TRACE_USAGE_REPORTING` | *(read directly by the vendored trace client)* | *(unset)* | `off` (or any value but blank, `true`, `on`, `yes` or `1`) stops reporting regardless of `USAGE_REPORTING_ENABLED`. |
| `DO_NOT_TRACK` | *(read directly by the vendored trace client)* | *(unset)* | `1` (or any value but blank, `0`, `false`, `off` or `no`) stops reporting too, per https://consoledonottrack.com. |
| `TRACE_INSTALL_ID` | *(read directly by the application)* | *(unset)* | Pins the installation ID sent as the `install` tag. When unset, the ID file is kept inside the container, so a recreated container counts as a new installation. |

Of these, `GITHUB_TOKEN`, `SCHEDULED_USERS`, `BACKUP_INTERVAL_MS`, `USAGE_REPORTING_ENABLED`, `TRACE_USAGE_REPORTING`, `DO_NOT_TRACK` and `TRACE_INSTALL_ID` are wired through to a `.env` file by the included `docker-compose.yml` (see `.env.example`); that file pins `BACKUP_DIRECTORY` to `/backups` and mounts the host's `./backups` directory there so backups persist outside the container.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ To turn it off, any one of these is enough:
- `TRACE_USAGE_REPORTING=off` (also `false`, `0`, `no`) in the environment — the switch every trace client honours, checked before gh-backup's own setting
- `DO_NOT_TRACK=1` (also `true`, `yes`) in the environment, per [consoledonottrack.com](https://consoledonottrack.com)

Every switch fails closed, so an opt-out is never read as "on": `usage.reporting.enabled` / `USAGE_REPORTING_ENABLED` keeps reporting on only for `true`, `on`, `yes` or `1` (any case) and turns it off for anything else, blank or a typo included; `TRACE_USAGE_REPORTING` set to anything but blank or one of those values turns it off; `DO_NOT_TRACK` set to anything but blank, `0`, `false`, `off` or `no` turns it off.

See [`usage.reporting.enabled`](CONFIG.md#usagereportingenabled) in the Configuration Guide, and for what trace collects and why: https://danielstephenson.dev/usage-reporting

## Contributing
Expand Down
6 changes: 4 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ services:
# Usage reporting to the maintainers' trace service (startup and
# backup-completed events, nothing about what is backed up).
# Set USAGE_REPORTING_ENABLED=false or TRACE_USAGE_REPORTING=off to turn
# it off (DO_NOT_TRACK=1 too); see CONFIG.md and
# it off (DO_NOT_TRACK=1 too). A blank USAGE_REPORTING_ENABLED is passed
# through as blank (not replaced by true), and anything but true/on/yes/1
# is read as off; see CONFIG.md and
# https://danielstephenson.dev/usage-reporting
- USAGE_REPORTING_ENABLED=${USAGE_REPORTING_ENABLED:-true}
- USAGE_REPORTING_ENABLED=${USAGE_REPORTING_ENABLED-true}
- TRACE_USAGE_REPORTING=${TRACE_USAGE_REPORTING:-}
- DO_NOT_TRACK=${DO_NOT_TRACK:-}

Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/github/backup/UsageReportingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
* {@code application.properties}, or as {@code USAGE_REPORTING_ENABLED=false}
* in the environment), or with the environment variables every trace client
* honours, {@code TRACE_USAGE_REPORTING=off} and {@code DO_NOT_TRACK=1}, which
* the client checks before anything this service passes it. The first time
* the client checks before anything this service passes it. Every switch fails
* closed: {@code usage.reporting.enabled} keeps reporting on only for
* {@code true}, {@code on}, {@code yes} or {@code 1}, and anything else --
* {@code off}, {@code no}, {@code 0}, blank, a typo -- turns it off. The first time
* reporting runs on a machine, one notice is logged saying so; a marker file
* under the user's config directory ({@code ~/.config/gh-backup/}) keeps it
* from being repeated. Without a usable home directory there is nowhere to keep
Expand Down Expand Up @@ -95,8 +98,9 @@ static File installIdFile(Path noticeMarker) {

private static TraceClient buildClient(String enabled, String endpoint, String key, String version,
File installIdFile) {
// A blank value (an empty environment variable, say) means "default", i.e. on.
boolean on = enabled == null || enabled.isBlank() || !"false".equalsIgnoreCase(enabled.trim());
// Fails closed: only true, on, yes or 1 (any case) keeps reporting on. Anything else --
// false, off, no, 0, blank, a typo -- turns it off, so an opt-out is never read as on.
boolean on = TraceClient.allowsReporting(enabled);
try {
return TraceClient.builder(endpoint, APPLICATION, version)
.key(key)
Expand Down
Loading