Scheduling & Automatisierung
Übersicht aller automatisierten Tasks: Cron-Jobs und Systemd Timer.
| Cron-Jobs | 3 (Backup, Certbot, PHP Sessions) |
| Systemd Timer | 14 aktiv |
| Logs | /var/log/backup.log, journalctl |
Cron-Jobs (Anwendungsspezifisch)
Backup
| Datei | /etc/cron.d/backup |
| Zeit | Täglich 03:00 |
| User | root |
| Script | /opt/scripts/backup.sh |
| Log | /var/log/backup.log |
Cron-Eintrag
0 3 * * * root /opt/scripts/backup.sh >> /var/log/backup.log 2>&1
Was wird gesichert
- etc.tar.gz - System-Konfigurationen (/etc)
- www.tar.gz - Web-Dateien (/var/www)
- mariadb_all.sql.gz - Alle Datenbanken
- qdrant.tar.gz - Vektor-Storage
- ollama.tar.gz - LLM Modelle
Retention
Backups älter als 7 Tage werden automatisch gelöscht.
Log prüfen
tail -50 /var/log/backup.log
Mehr Details: Backup-Dokumentation
SSL-Zertifikate (Certbot)
| Datei | /etc/cron.d/certbot |
| Zeit | Alle 12 Stunden (mit Random-Sleep) |
| User | root |
| Hinweis | Wird von Systemd Timer überschrieben |
Cron-Eintrag (Fallback)
0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && certbot -q renew
Aktiver Timer
# Status prüfen
systemctl status certbot.timer
# Nächste Ausführung
systemctl list-timers certbot.timer
Manuelles Renewal
certbot renew --dry-run # Test
certbot renew # Echtes Renewal
Mehr Details: SSL-Dokumentation
PHP Session Cleanup
| Datei | /etc/cron.d/php |
| Zeit | Alle 30 Minuten (:09, :39) |
| User | root |
| Script | /usr/lib/php/sessionclean |
| Hinweis | Wird von Systemd Timer überschrieben |
Aktiver Timer
systemctl status phpsessionclean.timer
Systemd Timer
Übersicht aller Timer
systemctl list-timers --all
Wichtige Timer
| Timer | Service | Intervall | Beschreibung |
| certbot.timer | certbot.service | 2x täglich | SSL-Zertifikat Renewal |
| phpsessionclean.timer | phpsessionclean.service | 30 min | PHP Session Cleanup |
| apt-daily.timer | apt-daily.service | 1x täglich | APT Package Listen Update |
| apt-daily-upgrade.timer | apt-daily-upgrade.service | 1x täglich | Automatische Security Updates |
| logrotate.timer | logrotate.service | 1x täglich | Log-Rotation |
| fstrim.timer | fstrim.service | 1x wöchentlich | SSD TRIM |
| man-db.timer | man-db.service | 1x täglich | Man-Page Index Update |
Timer-Befehle
# Alle Timer anzeigen
systemctl list-timers --all
# Bestimmten Timer prüfen
systemctl status certbot.timer
# Timer manuell triggern
systemctl start certbot.service
# Timer Logs anzeigen
journalctl -u certbot.service --since today
System-Crontab
Die System-Crontab (/etc/crontab) führt periodische Verzeichnisse aus:
| Verzeichnis | Zeit | Inhalt |
| /etc/cron.hourly/ | :17 jede Stunde | (leer) |
| /etc/cron.daily/ | 06:25 | apache2, apt, dpkg, logrotate, man-db |
| /etc/cron.weekly/ | Sonntag 06:47 | man-db |
| /etc/cron.monthly/ | 1. des Monats 06:52 | (leer) |
Scheduling-Zeitplan
Täglicher Ablauf
00:00 dpkg-db-backup (Systemd)
03:00 Backup Script (/opt/scripts/backup.sh)
05:00 apt-daily (Systemd)
06:00 apt-daily-upgrade (Systemd)
06:25 cron.daily (apache2, apt, dpkg, logrotate)
--:09 PHP Session Cleanup (alle 30 min)
--:39 PHP Session Cleanup (alle 30 min)
*/12h Certbot Renewal Check
Wöchentlicher Ablauf
Montag fstrim (SSD TRIM)
Sonntag cron.weekly (man-db)
Eigene Cron-Jobs erstellen
Methode 1: Datei in /etc/cron.d/
# /etc/cron.d/mein-job
# Format: Minute Stunde Tag Monat Wochentag User Befehl
30 4 * * * root /opt/scripts/mein-script.sh >> /var/log/mein-job.log 2>&1
Methode 2: Crontab bearbeiten
crontab -e
Cron-Syntax
# ┌───────────── Minute (0-59)
# │ ┌───────────── Stunde (0-23)
# │ │ ┌───────────── Tag des Monats (1-31)
# │ │ │ ┌───────────── Monat (1-12)
# │ │ │ │ ┌───────────── Wochentag (0-7, 0 und 7 = Sonntag)
# │ │ │ │ │
# * * * * * Befehl
# Beispiele:
0 3 * * * # Täglich um 03:00
*/15 * * * * # Alle 15 Minuten
0 */2 * * * # Alle 2 Stunden
0 9 * * 1-5 # Werktags um 09:00
0 0 1 * * # Am 1. jeden Monats um Mitternacht
Troubleshooting
Cron-Job läuft nicht
# Cron-Daemon Status
systemctl status cron
# Cron Logs prüfen
grep CRON /var/log/syslog | tail -20
# Syntax prüfen
crontab -l
Systemd Timer läuft nicht
# Timer Status
systemctl status timer-name.timer
# Service Logs
journalctl -u service-name.service --since today
# Timer manuell starten
systemctl start service-name.service