README.md aktualisiert
This commit is contained in:
@@ -1,30 +1,97 @@
|
||||
## Proxmox Update Script
|
||||
```
|
||||
nano /root/scripte/proxmox-update.py
|
||||
chmod +x /root/scripte/proxmox-update.py
|
||||
```
|
||||
## Testlauf:
|
||||
```
|
||||
sudo /root/scripte/proxmox-update.py
|
||||
```
|
||||
Automatisiert mit Reboot-Option (per cron oder systemd-timer):
|
||||
```
|
||||
REBOOT=YES /root/scripte/proxmox-update.py
|
||||
```
|
||||
## Exit-Codes:
|
||||
```
|
||||
Code Bedeutung
|
||||
0 Erfolg (keine oder erfolgreiche Updates)
|
||||
1 Kernel-Update gefunden → Reboot empfohlen
|
||||
2 Fehler (z. B. apt nicht erreichbar)
|
||||
|
||||
Automatisiertes Update-Skript für Proxmox VE mit Kernel-Erkennung, ZFS-Snapshots vor jedem Update, automatischer Bereinigung alter Kernel-Reste und optionalem Reboot.
|
||||
|
||||
### Installation
|
||||
|
||||
```
|
||||
## Cronjob (z. B. täglich 5 Uhr):
|
||||
nano /root/scripte/pve-update.py
|
||||
chmod +x /root/scripte/pve-update.py
|
||||
```
|
||||
0 5 * * * /root/scripte/proxmox-update.py
|
||||
|
||||
### Testlauf
|
||||
|
||||
```
|
||||
Ergibt z. B.:
|
||||
sudo /root/scripte/pve-update.py
|
||||
```
|
||||
|
||||
### Automatisiert mit Reboot-Option (per cron oder systemd-timer)
|
||||
|
||||
```
|
||||
REBOOT=YES /root/scripte/pve-update.py
|
||||
```
|
||||
|
||||
> Wichtig: `REBOOT=YES` muss als **Umgebungsvariable** gesetzt werden, nicht als Kommandozeilenargument. In einer Cron-Zeile wird das automatisch korrekt übernommen (siehe Beispiel unten). Bei manuellem Aufruf in der Shell z. B. mit:
|
||||
> ```
|
||||
> sudo REBOOT=YES /root/scripte/pve-update.py
|
||||
> ```
|
||||
|
||||
### Funktionsweise
|
||||
|
||||
1. Prüft per `apt-get update` / `apt-get -s dist-upgrade`, ob Updates verfügbar sind.
|
||||
2. Falls ja: Erstellt vorher ZFS-Snapshots der konfigurierten Datasets, führt `apt-get dist-upgrade -y` und `apt-get autoremove --purge -y` aus und aktualisiert den Bootloader (`proxmox-boot-tool refresh`).
|
||||
3. Entfernt anschließend (bzw. auch wenn keine Updates verfügbar waren) übrig gebliebene Konfigurationsreste alter, bereits deinstallierter Kernel-Pakete (dpkg-Status `rc`) einzeln nacheinander – mit Fortschrittsanzeige im Log, z. B.:
|
||||
```
|
||||
(3/13) Loesche Reste von: proxmox-kernel-7.0.2-4-pve-signed
|
||||
(3/13) Erledigt: proxmox-kernel-7.0.2-4-pve-signed
|
||||
```
|
||||
4. Vergleicht den aktiv laufenden Kernel (`uname -r`) mit dem tatsächlich **installierten** Kernel (nur `dpkg`-Status `ii`, nicht installierte oder entfernte Pakete werden ignoriert).
|
||||
5. Ist ein neuerer Kernel installiert als aktiv geladen, wird ein Reboot als erforderlich markiert.
|
||||
6. Bei `REBOOT=YES` wird vor dem Neustart zusätzlich `proxmox-boot-tool status` geprüft. Nur wenn der Bootloader-Status OK ist, wird der Reboot per `shutdown -r +1` ausgelöst. Schlägt die Prüfung fehl (oder ist `proxmox-boot-tool` z. B. wegen eines PATH-Problems nicht auffindbar), wird der Neustart abgebrochen und ein Fehler geloggt.
|
||||
|
||||
### Konfiguration
|
||||
|
||||
Am Anfang des Skripts anpassbar:
|
||||
|
||||
```python
|
||||
ZFS_DATASETS = [
|
||||
"rpool/ROOT/pve-1",
|
||||
"rpool/pveconf"
|
||||
]
|
||||
|
||||
SNAPSHOT_TAG = "pve-update-via-cron"
|
||||
MAX_SNAPSHOTS = 5
|
||||
|
||||
LOGFILE = "/var/log/proxmox_update.log"
|
||||
```
|
||||
|
||||
- `ZFS_DATASETS`: Liste der Datasets, von denen vor jedem Update ein Snapshot erstellt wird.
|
||||
- `MAX_SNAPSHOTS`: Anzahl der Snapshots pro Dataset, die aufbewahrt werden (ältere werden automatisch gelöscht).
|
||||
- `LOGFILE`: Pfad zur Logdatei, in die zusätzlich zur Konsolenausgabe alles protokolliert wird.
|
||||
|
||||
### Exit-Codes
|
||||
|
||||
| Code | Bedeutung |
|
||||
|------|---------------------------------------------------------|
|
||||
| 0 | Erfolg (keine oder erfolgreiche Updates, kein Reboot nötig) |
|
||||
| 1 | Neuer Kernel installiert → Reboot empfohlen/erforderlich |
|
||||
| 2 | Fehler (Skript nicht als root ausgeführt) |
|
||||
|
||||
### Cronjob (z. B. täglich 4 Uhr, mit automatischem Reboot bei neuem Kernel)
|
||||
|
||||
```
|
||||
0 4 * * * REBOOT=YES /root/scripte/pve-update.py
|
||||
```
|
||||
|
||||
Nur prüfen/updaten, ohne automatischen Reboot:
|
||||
|
||||
```
|
||||
0 4 * * * /root/scripte/pve-update.py
|
||||
```
|
||||
|
||||
### Snapshots
|
||||
|
||||
Vor jedem Update werden automatisch ZFS-Snapshots der konfigurierten Datasets erstellt, z. B.:
|
||||
|
||||
```
|
||||
rpool/ROOT/pve-1@pve-update-via-cron-2025-08-15_05-00-00
|
||||
rpool/pveconf@pve-update-via-cron-2025-08-15_05-00-00
|
||||
```
|
||||
```
|
||||
|
||||
Es werden jeweils maximal `MAX_SNAPSHOTS` Snapshots pro Dataset aufbewahrt, ältere werden automatisch entfernt.
|
||||
|
||||
### Voraussetzungen
|
||||
|
||||
- Proxmox VE mit ZFS-Root (`zfs`, `proxmox-boot-tool` müssen vorhanden sein).
|
||||
- Skript muss als `root` ausgeführt werden.
|
||||
- Python 3 (ohne zusätzliche Abhängigkeiten, nur Standardbibliothek).
|
||||
Reference in New Issue
Block a user