- Python 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .datalad | ||
| .forgejo/workflows | ||
| gamo | ||
| .gitattributes | ||
| .gitignore | ||
| .noannex | ||
| action.yml | ||
| pyproject.toml | ||
| README.md | ||
git-annex-mirror-orchestrator
A lightweight Python orchestrator for mirroring many git-annex repositories. It stores per‑dataset specifications as JSON files and provides console scripts that can be chained together to keep repositories in sync.
Installation
pip install .
# or using hatch
hatch env create
hatch run pip install -e .
Usage
The package ships five command‑line tools defined in pyproject.toml:
git-gamo-next-task– selects the next dataset (JSON spec) that is due for an update.git-gamo-update-refs– reads a JSON record from STDIN, mirrors the source repository (branches and tags) to the target, and writes the updated record to STDOUT.git-gamo-store-task– writes a JSON record from STDIN back to the mirror directory.git-gamo-report– reads all mirror state records and prints a markdown table with one row per repository (last mirrored date, last source modification date, tag count, key totals), suitable for the README of a Forgejo organization.profilerepository.git-gamo-annex-ref-mirror– low‑level helper that syncs branch refs and git‑annex metadata from a configured remote into an existing local bare git‑annex repository (no content is transferred); used internally bygamo-update-refs.
These tools are intended to be piped together, for example:
# from within the tracking repository that holds the mirror specs,
# run the full mirror pipeline for the next due dataset
git gamo-next-task \
| git gamo-update-refs \
| git gamo-store-task
The pipeline works as follows:
gamo-next-taskscans the mirror directory for JSON specs, determines which one is due based on scheduling configuration, and prints the chosen record as a single JSON line.gamo-update-refsreads that JSON, performs the mirroring operation, updates timestamps and status, and emits the modified JSON.gamo-store-taskwrites the updated JSON back to the appropriate file, ready for the next run.
You can schedule this command with cron, a systemd timer, or any other scheduler to keep all configured datasets continuously synchronized.
Mirror status report
git-gamo-report reads all mirror state records (including disabled and auto‑disabled ones) and prints a markdown table reporting, for each repository, when it was last mirrored, the date of the last modification of the source repository, the number of tagged versions (linked to the repository's tags page), and the number and size of the git‑annex keys the target holds and is still missing:
| Repository | Last mirrored | Last modified | Versions | Keys | Missing |
| --- | --- | --- | --- | --- | --- |
| [my-dataset](https://example.com/target/my-dataset) | 2026-11-06 | 2026-11-06 | [7](https://example.com/target/my-dataset/tags) | 1234@10.7 GB | 12@65.5 kB |
Repositories that have never been mirrored (or whose state lacks the respective fields) show a dash in the corresponding columns; key sizes render as ? when any key has an unknown size.
Rows are sorted by most recently mirrored first; repositories that were never mirrored are listed last. The command only reads the JSON state records from the mirror directory and performs no network queries, so it scales to mirrors with more than 1000 repositories. The table is meant to be dropped into the README of a Forgejo organization .profile repository, conceptually replacing the regular repository listing.
# regenerate the listing for the organization's .profile repository
git gamo-report --mirror mirror > table.md
A CI step for regenerating the listing:
- name: Regenerate mirror listing
run: |
git gamo-report --mirror mirror > .profile/table.md
Example action workflow
name: Mirror git-annex Repositories
on:
schedule:
# run every hour
- cron: "0 * * * *"
workflow_dispatch:
jobs:
mirror:
runs-on: debian-13
steps:
- name: Checkout repository
uses: actions/checkout@v4
# set up a credential that enabled fetch/push for the mirror repos
# (possibly needs more than one)
- name: Cache Git credential
uses: https://hub.psychoinformatics.de/actions/cache-git-credential@v1
with:
password: ${{ secrets.BOT_PAT }}
- name: Run gamo mirror pipeline
uses: https://hub.datalad.org/git-annex/git-annex-mirror-orchestrator@main
- name: Deposit mirror state
run: |
git push
Record format
The mirror directory (default mirror/) stores one JSON file per dataset, named <id>.json. gamo-next-task reads them to pick the next dataset, gamo-update-refs consumes the chosen record on STDIN, and gamo-store-task writes the updated record back after each run.
A typical record looks like:
{
"id": "my-dataset",
"enabled": true,
"source": { "url": "https://example.com/source.git" },
"target": { "url": "https://example.com/target.git" },
"state": {
"last_attempt": "2026-11-06T11:00:05Z",
"last_success": "2026-11-06T11:00:05Z",
"last30days_ncommits": 42,
"source_last_modified": "2026-11-06T09:41:00Z",
"n_tags": 7,
"keys_total_n": 1234,
"keys_total_bytesize": 10737418240,
"keys_total_unsized_present": false,
"keys_missing_n": 12,
"keys_missing_bytesize": 65536,
"keys_missing_unsized_present": false
}
}
Fields:
-
id— required. Stable, unique identifier for the dataset.gamo-store-taskwrites the record tomirror/<id>.json, so it must be a valid file name. -
source/target— required. Each is an object with aurlkey pointing at the source and targetgit-annexrepositories. Thetargetobject additionally accepts two optional boolean keys that control the ref mirroring:prune— defaultfalse. Whentrue, branches that no longer exist in the source are deleted from the target.force_tags— defaulttrue. Whentrue, the source's tags are force-updated on the target (local-only tags are retained); whenfalse, tags are not mirrored at all.
-
enabled— optional boolean switch. Whenfalse,gamo-next-taskignores the record completely (it is neither scheduled nor emitted). When missing ortrue, the record is scheduled as usual. -
schedule— optional object with per-dataset scheduling state:auto_disabled— set totruebygamo-update-refsonce the dataset has accumulated enough consecutive errors to be disabled.auto-disable-after-nerrors,minimum-interval,maximum-interval— optional per-dataset overrides of the matchinggamo.schedule.*configuration keys (see the Configuration section).
-
state— optional object with run status:last_attempt— ISO 8601 timestamp of the most recent run (set on every run).last_success— ISO 8601 timestamp of the most recent successful mirror (set only on success).last30days_ncommits— number of commits the source gained across all of its branches in the last 30 days (by committer date); used to compute the next due time. Set only on success.source_last_modified— the newest committer date across all source branches, in ISO 8601 with a trailingZ. Set only on success.n_tags— number of tags on the source (counted after the tag mirror; equals what is pushed to the target). Set only on success.keys_total_n,keys_total_bytesize,keys_total_unsized_present— number of git‑annex keys whose content the target holds, their total size in bytes, and whether any of them has an unknown size. Set only on success.keys_missing_n,keys_missing_bytesize,keys_missing_unsized_present— the same, for the keys whose content is still missing from the target. Set only on success.errors— messages appended on each failed run and removed on the next success. When this list reachesauto-disable-after-nerrors,gamo-update-refssetsschedule.auto_disabledtotrue.
The next due time is not stored in the record; gamo-next-task computes it on the fly as last_success plus an interval, where the interval is minimum-interval while the target still misses keys (keys_missing_n greater than 0), maximum-interval when last30days_ncommits is 0, and otherwise max(minimum-interval, min(maximum-interval, 30 days / last30days_ncommits)). Records without a last_success are always due. gamo-next-task orders records without a computed due time first, then records that still miss keys, then by the earliest computed due time, then by the highest last30days_ncommits, and emits the first record that is due, i.e. without a due time or with a due time in the past (otherwise it emits nothing).
By default, gamo-update-refs mirrors the source's tags to the target (in addition to the branches), so the Forgejo mirror shows the same tags as the source and the n_tags count matches the repository's tags page; set target.force_tags to false to disable the tag mirror.
Timestamps are stored in ISO 8601 with a trailing Z (UTC).
Configuration
Parameters are configurable via the gamo configuration system, which resolves values Git‑style from, in decreasing precedence, the GIT_CONFIG_* environment variables, the repository's own Git configuration, Git's global and system configuration, and built‑in defaults. For example, git config gamo.schedule.minimum-interval 14400 in the tracking repository sets the minimum interval to four hours for that mirror. Relevant keys include:
gamo.schedule.minimum-interval– Minimum seconds between successive runs for a dataset (default: 28 800 s = 8 h).gamo.schedule.maximum-interval– Maximum seconds allowed between runs (default: 2 592 000 s ≈ 30 days).gamo.schedule.auto-disable-after-nerrors– Number of consecutive failed runs after whichgamo-update-refsmarks a datasetauto_disabled(default: unset, i.e. never auto‑disable).gamo.transfer.maximum-duration-secs– Maximum number of seconds thatgamo-update-refsspends transferring git-annex keys to the target in a single run (passed togit-annex copy --time-limit; default: 900 s = 15 min). If the limit is reached, the key transfer is stopped gracefully and resumed on the next run.
Development
Run tests and linting with Hatch:
hatch test # run all tests
hatch check code # lint
hatch run types:check # type checking
For more details, see pyproject.toml and the source code under the gamo/ package.