solrctl
CLI-Tool und Python-Library zur Verwaltung von Apache Solr 9.x – Cores tauschen, Snapshots erstellen, Status abfragen, Konfiguration einsehen.
Installation
uv tool install solrctl
Oder aus dem Checkout:
uv pip install -e .
Nutzung als CLI
# Solr erreichbar?
solrctl ping
# Cores anzeigen
solrctl core list
# Core-Infos (Pfade, Dokumentanzahl, Größe)
solrctl core info <name>
# solrconfig.xml abrufen
solrctl core config <name>
# Schema als XML abrufen
solrctl core schema <name>
# Core-Swap (unterbrechungsfrei)
solrctl core swap --source <neuer_core> --target <aktiver_core>
# Core erstellen
solrctl core create <name> [--config-set CONFIG_SET]
# Core löschen
solrctl core delete <name> [--delete-index]
# Snapshots (Backup/Restore via Replication Handler)
solrctl core snapshot create <core>
solrctl core snapshot list <core>
solrctl core snapshot restore <core> --name <snapshot_name>
solrctl core snapshot delete <core> --name <snapshot_name>
# Alias-Operationen (SolrCloud ⚠️ nicht getestet)
solrctl alias list
solrctl alias swap --alias <name> --collection <ziel>
solrctl alias delete <name>
Alle Befehle akzeptieren globale Optionen:
--solr-url Basis-URL der Solr-Instanz (Default: http://localhost:8983, Env: SOLR_URL)
--user Basic-Auth Benutzername (Env: SOLR_USER)
--password Basic-Auth Passwort (Env: SOLR_PASSWORD)
-v, --verbose Ausführliche Debug-Ausgabe aktivieren (Default: INFO)
Nutzung als Python-Library
solrctl kann direkt im Python-Code verwendet werden – ohne CLI.
Einfache Funktionen (auto-Client)
Jede Funktion erstellt automatisch einen SolrClient und schließt ihn nach dem Aufruf:
from solrctl import swap, list_cores, ping, get_core_info
# Solr erreichbar?
if ping("http://localhost:8983"):
print("Solr ist da!")
# Alle Cores auflisten
cores = list_cores("http://localhost:8983")
# Core-Swap (unterbrechungsfrei)
swap("http://localhost:8983", source="core_new", target="core_active")
# Core-Infos abfragen
info = get_core_info("core1", solr_url="http://localhost:8983")
print(info["index"]["numDocs"])
SolrClient für mehrere Operationen
Für mehrere Operationen in einer Session eigenen SolrClient als Kontext-Manager verwenden:
from solrctl import SolrClient
with SolrClient("http://localhost:8983", auth=("user", "pass")) as client:
if client.ping():
cores = client.list_cores()
for core_name in cores:
info = client.get_core_info(core_name)
print(f"{core_name}: {info['index']['numDocs']} docs")
client.swap_cores("core_active", "core_new")
config_xml = client.get_core_config("core_active")
schema_xml = client.get_core_schema("core_active")
Verfügbare Funktionen
| Funktion | Beschreibung |
|---|---|
ping(solr_url) |
Erreichbarkeit prüfen |
list_cores(solr_url) |
Alle Cores auflisten |
get_core_info(core, solr_url) |
Core-Details abfragen |
swap(source, target, solr_url) |
Zwei Cores tauschen |
delete_core(core, delete_index, solr_url) |
Core löschen |
create_core(core, config_set, solr_url) |
Neuen Core erstellen |
get_core_config(core, solr_url) |
solrconfig.xml abrufen |
get_core_schema(core, solr_url) |
Schema als XML abrufen |
create_snapshot(core, solr_url) |
Snapshot erstellen (Name + Location auto-generiert) |
restore_snapshot(core, name, solr_url) |
Snapshot wiederherstellen |
list_snapshots(core, solr_url) |
Snapshots auflisten |
delete_snapshot(core, name, solr_url) |
Snapshot löschen |
list_aliases(solr_url) |
Alle Aliases auflisten ⚠️ |
swap_alias(alias, collection, solr_url) |
Alias umsetzen ⚠️ |
delete_alias(alias, solr_url) |
Alias löschen ⚠️ |
⚠️ = SolrCloud-Funktionen – Code vorhanden, aber nicht gegen SolrCloud getestet.
Alle Core-Funktionen akzeptieren solr_url (default: http://localhost:8983) und auth (optional: (user, password)-Tupel).
Voraussetzungen
- Python 3.11+
- Zugriff auf eine Solr 9.x Instanz (Standalone für Core-Befehle, SolrCloud für Alias-Befehle)
Lokale Entwicklung
# Abhängigkeiten inkl. Dev- und Prefect-Extras installieren
uv sync --all-extras
# Tests ausführen
uv run pytest
# CLI lokal ausführen
uv run solrctl --help
Docker-basiertes Test-Setup
docker compose up -d
solrctl --solr-url http://localhost:8983 ping
Prefect-Integration
solrctl enthält optionale Prefect-Tasks und -Flows. Diese befinden sich im Verzeichnis prefect_flows/ und sind nicht Teil des PyPI-Pakets – sie werden beim Build ausgeschlossen.
Um sie zu nutzen, müssen solrctl und prefect installiert sein:
uv pip install -e ".[prefect]"
Verfügbare Tasks und Flows (in prefect_flows/):
| Modul | Beschreibung |
|---|---|
prefect_flows.tasks.core_swap |
Task: Core-Swap mit Retries |
prefect_flows.tasks.alias_swap |
Task: Alias-Swap mit Retries ⚠️ |
prefect_flows.tasks.cleanup |
Task: Optionales Löschen alter Cores/Collections |
prefect_flows.flows.swap_flow |
Flow: Kompletter Swap inkl. optionalem Cleanup |
⚠️ Alias-Swap-Task ist für SolrCloud und nicht getestet.
Lokaler Testlauf:
uv run python -m prefect_flows.flows.swap_flow
Projektstruktur
src/
solrctl/
__init__.py # Public API (Funktionen + SolrClient)
api.py # High-Level-Komfort-Funktionen
cli.py # Click-CLI
client.py # SolrClient (HTTP-API-Wrapper)
prefect_flows/ # Prefect-Integration (nicht im PyPI-Paket)
tasks/
core_swap.py
alias_swap.py # ⚠️ SolrCloud – nicht getestet
cleanup.py
flows/
swap_flow.py
tests/
docs/
idea.md
plan.md
technical.md
Weitere Dokumentation
docs/plan.md– Ausführungsplan und aktueller Statusdocs/technical.md– Architekturentscheidungendocs/usage.md– Deployment-Nutzung und Flow-Integration
KI-Unterstützung
Dieses Projekt wurde mit Unterstützung von KI-Tools (Large Language Models) entwickelt. Code-Struktur, Implementierung und Dokumentation wurden dabei unterstützt durch automatiserte Vorschläge. Alle Entscheidungen wurden vom Entwickler geprüft und bestätigt. Transparenz über den Entwicklungsprozess ist uns wichtig.
English
solrctl is a CLI tool and Python library for managing Apache Solr 9.x – swap cores without downtime, create snapshots, query status, inspect configuration.
CLI Usage
solrctl ping # Check if Solr is reachable
solrctl core list # List all cores
solrctl core info <name> # Show core details
solrctl core config <name> # Get solrconfig.xml
solrctl core schema <name> # Get schema as XML
solrctl core swap --source NEW --target ACTIVE # Zero-downtime core swap
solrctl core create <name> # Create a new core
solrctl core delete <name> # Delete a core
# Snapshots (backup/restore via Replication Handler)
solrctl core snapshot create <core> # Create a snapshot
solrctl core snapshot list <core> # List snapshots
solrctl core snapshot restore <core> --name <name> # Restore a snapshot
solrctl core snapshot delete <core> --name <name> # Delete a snapshot
Solr 9.10 Quirks (geprüft 2026-09-11)
restore-Name ohnesnapshot.-Präfix angeben — wird der volle Name übergeben, antwortet der Replication Handler mitstatus:OK, QTime:0, ohne tatsächlich zu restoren (silent no-op).solrctlstrippt den Präfix automatisch, analog zudelete_snapshot.- **
deletebackup-Name ebenfalls ohnesnapshot.-Präfix** — gleiche Eigenheit,solrctl` handhabt das ebenfalls automatisch.- Cross-Core-Restore ist in Solr 9.10.1 kaputt — auch mit korrektem
--locationschlägt der Wechsel auf den restored Index mitIndexNotFoundException: no segments* file foundfehl. Workaround: Snapshot-Dateien manuell indata/index/des Ziel-Cores kopieren und Core neu laden.
```bash
# SolrCloud (⚠️ untested – code exists but not verified against SolrCloud)
solrctl alias list # List all aliases
solrctl alias swap --alias NAME --collection TARGET
Python Library
from solrctl import swap, list_cores, SolrClient
# Quick one-shot calls (auto-creates and closes client)
swap("http://localhost:8983", source="new", target="active")
cores = list_cores("http://localhost:8983")
# Session with multiple operations
with SolrClient("http://localhost:8983") as client:
client.swap_cores("active", "new")
info = client.get_core_info("active")
Install
uv tool install solrctl
Requires Python 3.11+, Apache Solr 9.x. MIT License.
Metadata
Release files for solrctl 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| solrctl-1.2.0.tar.gz | 25.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| solrctl-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 44.7 kB
Release files / solrctl-1.2.0.tar.gz
| Download URL | solrctl-1.2.0.tar.gz |
|---|---|
| Size | 25.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ebc8a9d5af622df5a5c7674a55029202461093fda8dbde2b82a387072d8f0bd2
|
|
BLAKE2b-256 checksum How to use checksums |
3f654e730c275d0c1993424315e47305b98581168098a2824cd3ce43948a5ed3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"KDE neon","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / solrctl-1.2.0-py3-none-any.whl
| Download URL | solrctl-1.2.0-py3-none-any.whl |
|---|---|
| Size | 19.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f8dd9617908029728a5d6885c8ce070f94b53eaefcd48d227611002e9e9fcf2d
|
|
BLAKE2b-256 checksum How to use checksums |
6be26240953436198b31af00eca43e5cd1940470cbafd396b15f55ba8c8b3660
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"KDE neon","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|