From 453a6975f110b030771d1db7aee6dd9b58ed6380 Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Tue, 17 Nov 2026 18:49:00 -0700 Subject: [PATCH 1/2] Log the usage-reporting notice every run when there is no home directory With user.home unset or blank there is no marker path, and the notice was skipped while the startup and backup-completed events were still sent. Log it on every run instead, and describe the case in README.md and CONFIG.md. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + CONFIG.md | 2 +- README.md | 2 +- .../github/backup/UsageReportingService.java | 21 ++++++++++++------- .../backup/UsageReportingServiceTest.java | 17 +++++++++++++-- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2cbdb7..256721c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed +- The usage-reporting notice is now logged on every run when the JVM has no usable home directory (`user.home` unset or blank), instead of never: with nowhere to keep the `~/.config/gh-backup/usage-reporting-notice-shown` marker, the `startup` and `backup-completed` events were previously sent without the notice ever appearing, contrary to `README.md` and `CONFIG.md`, which now describe this case - Documentation accuracy: `USER_GUIDE.md` now describes the web interface served in web mode — the backup form, which takes one user or organization per submission and shows the server's success or error message, and the status section with its totals, refresh button and remembered list, card and gallery views — where it previously only said to open `http://localhost:8080` - `POST /api/backups` now answers a backup that fails with an unchecked exception (such as a `GHException` from github-api while listing repositories) with `500 Internal Server Error` and `{ "success": false, "message": "Error: ..." }`, as `COMMANDS.md` documents, instead of Spring Boot's default error body, which has no `message`, so the web UI showed only `Failed to create backup.`. No `backup-completed` event is reported for it. Previously only an `IOException` was handled this way; the command line and daemon already handled both - The interactive `backup` command now backs up each name it is given, so `backup octocat github` backs up `octocat` and then `github`, as the command line does, instead of looking up the single name `octocat github` on GitHub and failing. A name that fails is reported and the others are still backed up; the command still counts as one backup run for usage reporting, and its usage hint reads `Usage: backup [user/org2] ...` diff --git a/CONFIG.md b/CONFIG.md index 0374fa8..ac66048 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -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. 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` 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 **Override at runtime:** ```bash diff --git a/README.md b/README.md index 2201f6a..3b8c60b 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Please fill out a bug report [here](https://github.com/Stephenson-Software/gh-ba ## Usage reporting -Usage reporting is on by default: gh-backup reports that it was used to the maintainers' [trace](https://danielstephenson.dev/usage-reporting) service at `https://trace.danielstephenson.dev`, sending a `startup` event once per process and a `backup-completed` event when a backup run finishes, each carrying its name and version. Apart from the installation ID described below, nothing else is sent: nothing about the users, organizations or repositories being backed up, and no usernames, hostnames, IP addresses, paths or command-line arguments. A one-line notice is logged the first time it runs on a machine (recorded in `~/.config/gh-backup/usage-reporting-notice-shown`). +Usage reporting is on by default: gh-backup reports that it was used to the maintainers' [trace](https://danielstephenson.dev/usage-reporting) service at `https://trace.danielstephenson.dev`, sending a `startup` event once per process and a `backup-completed` event when a backup run finishes, each carrying its name and version. Apart from the installation ID described below, nothing else is sent: nothing about the users, organizations or repositories being backed up, and no usernames, hostnames, IP addresses, paths or command-line arguments. A one-line notice is logged the first time it runs on a machine (recorded in `~/.config/gh-backup/usage-reporting-notice-shown`), or on every run when there is no usable home directory to record it in. Every event also carries a random installation ID (the tag `install`), so installations can be counted rather than events. It is the value of `TRACE_INSTALL_ID` when that is set, and otherwise a random UUID written the first time reporting runs to `~/.config/gh-backup/trace-install-id`, next to the notice marker, and reused after that (in the Docker image that directory is inside the container, so a recreated container counts as a new installation unless `TRACE_INSTALL_ID` is set). It identifies no person, account, host or address. Delete the file to get a new one. Every opt-out below also stops it: when reporting is off, no ID is made up and the file is neither read nor written. diff --git a/src/main/java/com/github/backup/UsageReportingService.java b/src/main/java/com/github/backup/UsageReportingService.java index d5d0619..a351e9b 100644 --- a/src/main/java/com/github/backup/UsageReportingService.java +++ b/src/main/java/com/github/backup/UsageReportingService.java @@ -35,8 +35,9 @@ * the client checks before anything this service passes it. 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. gh-backup has no settings file of its own, which is why - * a marker file is used. Details: + * from being repeated. Without a usable home directory there is nowhere to keep + * the marker, so the notice is logged on every run instead. gh-backup has no + * settings file of its own, which is why a marker file is used. Details: * https://danielstephenson.dev/usage-reporting * *

Every path through this class is exception-safe: a bad endpoint, an @@ -156,17 +157,15 @@ public void close() { private void showFirstRunNoticeOnce() { if (noticeMarker == null) { + // Nowhere to record that it was shown, so it is shown every run rather than never. + logNotice(); return; } try { if (Files.exists(noticeMarker)) { return; } - log.info("Usage reporting is on: gh-backup sends its name, version and a random installation ID " - + "with a startup event and a backup-completed event (nothing else) to " - + "https://trace.danielstephenson.dev - nothing about accounts or repositories. Turn it off with " - + "-Dusage.reporting.enabled=false, USAGE_REPORTING_ENABLED=false or " - + "TRACE_USAGE_REPORTING=off. Details: " + DETAILS_URL); + logNotice(); Files.createDirectories(noticeMarker.getParent()); Files.writeString(noticeMarker, "The usage-reporting notice was shown once; delete this file to see it again.\n"); } catch (IOException | RuntimeException cannotPersist) { @@ -174,4 +173,12 @@ private void showFirstRunNoticeOnce() { log.debug("Could not record that the usage-reporting notice was shown: {}", cannotPersist.getMessage()); } } + + private static void logNotice() { + log.info("Usage reporting is on: gh-backup sends its name, version and a random installation ID " + + "with a startup event and a backup-completed event (nothing else) to " + + "https://trace.danielstephenson.dev - nothing about accounts or repositories. Turn it off with " + + "-Dusage.reporting.enabled=false, USAGE_REPORTING_ENABLED=false or " + + "TRACE_USAGE_REPORTING=off. Details: " + DETAILS_URL); + } } diff --git a/src/test/java/com/github/backup/UsageReportingServiceTest.java b/src/test/java/com/github/backup/UsageReportingServiceTest.java index 0dbc0f3..fc36cd1 100644 --- a/src/test/java/com/github/backup/UsageReportingServiceTest.java +++ b/src/test/java/com/github/backup/UsageReportingServiceTest.java @@ -239,7 +239,7 @@ void noDefaultMarkerWithoutAUsableHomeDirectory() { } @Test - void withoutAHomeDirectoryTheStartupEventIsStillSentButNoNoticeOrInstallationId() throws Exception { + void withoutAHomeDirectoryTheNoticeIsLoggedEveryRunAndNoInstallationIdIsMadeUp() throws Exception { assumeTrue(System.getenv("TRACE_INSTALL_ID") == null, "TRACE_INSTALL_ID would pin an ID"); UsageReportingService service = new UsageReportingService("true", endpoint(), "test-key", "2.0.0-TEST", null); assertNull(service.installId(), "with nowhere to keep it, no installation ID is made up"); @@ -249,7 +249,20 @@ void withoutAHomeDirectoryTheStartupEventIsStillSentButNoNoticeOrInstallationId( service.close(); assertEquals("{\"application\":\"gh-backup\",\"name\":\"startup\",\"tags\":{\"version\":\"2.0.0-TEST\"}}", bodies.get(0)); - assertEquals(0, noticesLogged(), "with nowhere to record it, the notice is not shown"); + assertEquals(1, noticesLogged(), "with nowhere to record it, the notice is still shown"); + + UsageReportingService second = new UsageReportingService("true", endpoint(), "test-key", "2.0.0-TEST", null); + second.start(); + second.close(); + assertEquals(2, noticesLogged(), "with nowhere to record it, the notice is shown again on the next run"); + } + + @Test + void disabledWithoutAHomeDirectoryShowsNoNotice() { + UsageReportingService service = new UsageReportingService("false", endpoint(), "test-key", "2.0.0-TEST", null); + service.start(); + service.close(); + assertEquals(0, noticesLogged()); } private static byte[] readAll(InputStream in) throws java.io.IOException { From 089bf20bb974c6d96af02a7ef79a5c4ac6f9d932 Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Tue, 17 Nov 2026 18:50:42 -0700 Subject: [PATCH 2/2] Drop the stale no-notice claim from the earlier changelog entry Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 256721c..98b981b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,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, no installation ID and no first-run notice, 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 `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. ### Changed