1c83314f235a54a255db2f8a0a7cb8d685a405f2
This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
💡 Was macht das?
Wenn kein Argument übergeben wird, läuft das Skript wie gewohnt durch (main).
Wenn ein Funktionsname übergeben wird, wird nur diese Funktion mit optionalen Argumenten ausgeführt.
🔄 Beispielaufrufe
# Führt das ganze Skript aus (wie bisher)
./miyagi_backup.sh -c /etc/miyagi.conf
# Führt nur Updates aus
./miyagi_backup.sh run_updates
# Nur das Backup starten
./miyagi_backup.sh run_pbs_backup
# Nur Konfiguration schreiben
./miyagi_backup.sh write_zsync_config
🧱 Optional: Hilfe-Befehl
Füge am Anfang noch das hinzu:
if [[ "${1:-}" == "help" ]]; then
echo "Verfügbare Funktionen:"
declare -F | awk '{print " - " $3}'
exit 0
fi
Dann kannst du z. B. aufrufen:
./miyagi_backup.sh help
Und bekommst alle verfügbaren Funktionsnamen.
📌 Hinweis
Funktionen wie run_pbs_backup brauchen Variablen aus der Config. Du kannst sicherstellen, dass source "$CONFIG_FILE" immer ausgeführt wird, indem du das nicht in main, sondern außerhalb (oben) stehen lässt – so wie im überarbeiteten Skript oben.
✅ Fazit
Durch den Wechsel auf ein solches „Funktions-Router“-Muster kannst du dein Skript:
modular testen
gezielt einsetzen (z. B. nur Snapshot, nur Update)
einfacher debuggen
cron- oder CI-kompatibel machen
Description