Fehler in der Oberflaeche abfangen, Backups planbar machen
Der Anlass: "Backup erstellen" bei fehlendem Container beendete die
ganze TUI mit einer Fehlerzeile in der Shell.
Ursachen waren zwei, beide behoben:
1. die() in GUI-Pfaden. Neue Helfer gui_need_container/gui_need_sites
melden das Problem im Dialog und kehren zurueck. Interaktives wie
Shell und Terminal-Browser laeuft jetzt ueber gui_run_interactive
in einer Subshell mit Weiter-mit-ENTER.
2. "set -e". Schon ein Rueckgabewert != 0 aus einer Menuefunktion
beendete das Skript, weil Menuezweige keine Bedingung sind. 47
"|| return" auf "|| return 0" gestellt und 37 Menuezweige mit
"|| true" abgesichert. Ausserdem schlug ein "clear" ohne TERM fehl
und riss alles mit - drei Aufrufe abgesichert.
Jeder Hauptmenuepunkt wurde einzeln durchlaufen und kehrt sauber zurueck.
Neu: Backup-Jobs
Der Menuepunkt heisst jetzt "Backup erstellen / planen" mit Untermenue
(manuell erstellen, Jobs verwalten, Automatik ein/aus, Zeitplan
anzeigen, Job sofort ausfuehren). Dieselben Jobs liegen auch in den
Einstellungen unter "Backup-Jobs".
Manuelle Backups nehmen weiterhin immer BACKUP_DIR aus der .env.
Jeder Job hat dagegen sein eigenes Zielverzeichnis, seinen eigenen
Zeitplan, eigene Optionen und eine eigene Aufbewahrung, nach der er
sein Zielverzeichnis selbst aufraeumt.
Vollstaendig auch per Parameter:
job list | status | add | set | del | enable | disable
| run | run-all | auto [on|off]
mit --name --sites --cron --dir --keep --no-rrds --no-logs --stop
--disabled.
"job auto on" erzeugt aus den aktiven Jobs /etc/cron.d/checkmk-backup,
eine Zeile je Job mit dessen eigenem Zeitplan. Ohne root werden die
Zeilen ausgegeben statt kommentarlos zu scheitern. Der Schalter steht
als BACKUP_AUTO in der .env, die Jobs in backup-jobs.conf.
Nebenbei behoben: "local f; f=... tmp" fuehrte tmp als Kommando aus,
wodurch job_put und job_remove nichts schrieben.
Dokumentiert als Abschnitt 15.1 in beiden Sprachfassungen.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+105
-6
@@ -556,7 +556,8 @@ The most important settings:
|
||||
| `NPM_ENABLED` | `on`/`off` – should the Proxy Manager container run at all? See [12.4](#124-turning-the-proxy-manager-off-entirely-external-nginx) |
|
||||
| `NPM_ADMIN_PORT` | port of the Proxy Manager interface (default 81) – change only via `npm-port` or the menu |
|
||||
| `NPM_ADMIN_URL` | start page of the terminal browser; empty = derived from `NPM_ADMIN_PORT` |
|
||||
| `BACKUP_DIR` | location for backups/bundles (default `./backups`) |
|
||||
| `BACKUP_DIR` | location for **manual** backups (default `./backups`); scheduled jobs have their own paths |
|
||||
| `BACKUP_AUTO` | `on`/`off` – should the backup jobs run via cron? |
|
||||
| `CERT_DOMAIN`, `CERT_DAYS` | defaults for self-signed certificates |
|
||||
|
||||
### 7.1 Who reads `.env` – and why does it exist alongside the script?
|
||||
@@ -1331,6 +1332,7 @@ A file chooser with directory navigation is built in.
|
||||
| `start-all-sites` | start all sites (invoked by systemd) |
|
||||
| `backup …` | backup as a `.tar.gz` bundle |
|
||||
| `list` / `verify` / `prune --keep N` | manage backups |
|
||||
| `job list\|add\|set\|del\|run\|auto` | scheduled backups (own target path per job) |
|
||||
| `restore …` | restore a backup |
|
||||
| `import …` | import a migration bundle |
|
||||
| `image status\|list\|pull\|download\|load\|use` | obtain and select the Checkmk image |
|
||||
@@ -1445,17 +1447,112 @@ Listing and verifying:
|
||||
./scripts/cmk-manage.sh prune --keep 7
|
||||
```
|
||||
|
||||
### Nightly backup via cron
|
||||
### 15.1 Scheduled backups (backup jobs)
|
||||
|
||||
Manual backups always go to `BACKUP_DIR` from `.env`. Scheduled jobs, by
|
||||
contrast, bring **their own target directory** – so you can back up to a NAS
|
||||
share daily and somewhere else weekly.
|
||||
|
||||
In the menu: **backup → "Backup erstellen / planen"** (create / schedule)
|
||||
|
||||
```
|
||||
┌──────────── Backup erstellen / planen ─────────────────┐
|
||||
│ Manuelle Backups gehen immer nach: │
|
||||
│ /opt/checkmk-stack/backups (Einstellung BACKUP_DIR)│
|
||||
│ │
|
||||
│ Geplante Jobs haben ihr eigenes Zielverzeichnis. │
|
||||
│ Automatische Ausfuehrung: aus │
|
||||
│ │
|
||||
│ manuell Backup jetzt erstellen │
|
||||
│ jobs Backup-Jobs verwalten │
|
||||
│ auto Automatische Ausfuehrung ein/aus │
|
||||
│ status Zeitplan und Jobs anzeigen │
|
||||
│ jetzt Einen Job sofort ausfuehren │
|
||||
│ back zurueck │
|
||||
└────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
(create now / manage jobs / automatic execution on-off / show schedule / run a
|
||||
job now / back.) The same jobs are also reachable from
|
||||
**Einstellungen → "Backup-Jobs"**.
|
||||
|
||||
#### Creating a job
|
||||
|
||||
In the menu a dialog walks through sites, schedule (daily / weekly / monthly /
|
||||
free cron expression), target directory, retention and options. The same with
|
||||
parameters:
|
||||
|
||||
```bash
|
||||
sudo crontab -e
|
||||
# daily at 02:15, all sites, without logs, keep 14 backups
|
||||
sudo ./scripts/cmk-manage.sh job add --name nachts \
|
||||
--cron "15 2 * * *" --no-logs --keep 14
|
||||
|
||||
# Sundays at 03:30, two sites only, to the NAS, without RRDs, keep 8
|
||||
sudo ./scripts/cmk-manage.sh job add --name nas-woche \
|
||||
--cron "30 3 * * 0" --sites prod,test \
|
||||
--dir /mnt/nas/checkmk --no-rrds --no-logs --keep 8
|
||||
```
|
||||
|
||||
```cron
|
||||
15 2 * * * /opt/checkmk-stack/scripts/cmk-manage.sh -y backup --all --no-logs >>/var/log/cmk-backup.log 2>&1
|
||||
30 3 * * 0 /opt/checkmk-stack/scripts/cmk-manage.sh -y prune --keep 14 >>/var/log/cmk-backup.log 2>&1
|
||||
All commands:
|
||||
|
||||
| Command | Effect |
|
||||
|---|---|
|
||||
| `job list` | show the configured jobs |
|
||||
| `job status` | schedule, cron file and switch |
|
||||
| `job add --name N --cron "…"` | create a job |
|
||||
| `job set NAME …` | modify a job (fields not given stay as they are) |
|
||||
| `job del NAME` | delete a job (the backups remain) |
|
||||
| `job enable\|disable NAME` | turn a job on/off |
|
||||
| `job run NAME` | run a job right now |
|
||||
| `job run-all` | run every active job |
|
||||
| `job auto on\|off` | turn automatic execution on/off |
|
||||
|
||||
Options for `job add` / `job set`:
|
||||
|
||||
| Option | Meaning |
|
||||
|---|---|
|
||||
| `--sites ALL\|a,b` | sites to back up (default `ALL`) |
|
||||
| `--cron "15 2 * * *"` | schedule, five cron fields |
|
||||
| `--dir DIR` | this job's target directory (default `BACKUP_DIR`) |
|
||||
| `--keep N` | how many backups stay in the target (`0` = all) |
|
||||
| `--no-rrds`, `--no-logs`, `--stop` | as for `backup` |
|
||||
| `--disabled` | create it but do not schedule it yet |
|
||||
|
||||
#### Turning automation on and off
|
||||
|
||||
```bash
|
||||
sudo ./scripts/cmk-manage.sh job auto on # schedule
|
||||
sudo ./scripts/cmk-manage.sh job auto off # remove the schedule
|
||||
```
|
||||
|
||||
`on` writes `/etc/cron.d/checkmk-backup` from all **active** jobs – one line
|
||||
per job with its own schedule:
|
||||
|
||||
```cron
|
||||
15 2 * * * root /opt/checkmk-stack/scripts/cmk-manage.sh -y job run nachts >>/var/log/cmk-backup.log 2>&1
|
||||
30 3 * * 0 root /opt/checkmk-stack/scripts/cmk-manage.sh -y job run nas-woche >>/var/log/cmk-backup.log 2>&1
|
||||
```
|
||||
|
||||
This needs root. Without root the command prints the lines so you can add them
|
||||
yourself. `off` removes the file again; the jobs themselves are kept. The
|
||||
switch is stored as `BACKUP_AUTO` in `.env`.
|
||||
|
||||
After each run a job prunes its own target directory down to `--keep` – a
|
||||
separate `prune` entry is not needed.
|
||||
|
||||
#### Where the jobs live
|
||||
|
||||
In `backup-jobs.conf` in the project directory, one line per job:
|
||||
|
||||
```
|
||||
name|sites|cron|directory|options|keep|enabled
|
||||
nachts|ALL|15 2 * * *|/opt/checkmk-stack/backups|--no-logs|14|on
|
||||
nas-woche|prod,test|30 3 * * 0|/mnt/nas/checkmk|--no-rrds --no-logs|8|on
|
||||
```
|
||||
|
||||
The file is deliberately readable and diffable, but does not belong in the
|
||||
repository (it is in `.gitignore` because it contains system-specific paths).
|
||||
|
||||
---
|
||||
|
||||
## 16. Restore
|
||||
@@ -1749,6 +1846,8 @@ release notes beforehand.
|
||||
| Proxy Manager interface blank / only text fragments | a text browser without JavaScript was used. Use `cmk-manage.sh browser --engine browsh` (or `carbonyl`) |
|
||||
| Self-signed certificate cannot be uploaded in the terminal browser | there are no file dialogs there – upload via the API, see [chapter 11.3](#113-limitation-file-upload) |
|
||||
| `browser` reports "braucht ein echtes Terminal" (needs a real terminal) | called from a pipe/script. Call it on the console or over SSH; only the build runs headless, with `--build-only` |
|
||||
| A menu entry drops out to the shell with an error | fixed: missing containers, sites or backups are now reported in a dialog and the interface stays open |
|
||||
| `job auto on` reports missing permissions | `/etc/cron.d/` needs root: call it with `sudo`, or add the printed lines yourself |
|
||||
| The TUI does not start | install `dialog`: `apt-get install -y dialog` or `dnf install -y dialog` |
|
||||
| Site does not start, `tmp` errors | `./scripts/cmk-manage.sh omd config <site> set TMPFS off`, then start the site |
|
||||
|
||||
|
||||
Reference in New Issue
Block a user