README.md aktualisiert

This commit is contained in:
alf
2025-07-11 18:59:45 +00:00
parent a1e81e2501
commit f0cd0b2034

106
README.md
View File

@ -1,35 +1,39 @@
# Logrotate Automation Script Absolut\! Hier ist eine schöne `README.md` auf Deutsch für dein Skript:
This simple Bash script automates the execution of `logrotate` for specific log files, ensuring that your logs are managed effectively to prevent disk space issues and improve system performance.
----- -----
## Features # Logrotate Automatisierungsskript
* **Automated Log Rotation**: Automatically runs `logrotate` with a specified configuration. Dieses einfache Bash-Skript automatisiert die Ausführung von `logrotate` für spezifische Logdateien. Es stellt sicher, dass deine Logs effektiv verwaltet werden, um Problemen mit dem Festplattenspeicher vorzubeugen und die Systemleistung zu verbessern.
* **Status Tracking**: Utilizes a status file to keep track of the last rotation times.
* **Error Handling**: Checks for the existence of the configuration file and logs errors if it's missing.
* **Logging**: Records the execution status and any errors to a dedicated log file.
----- -----
## Getting Started ## Funktionen
These instructions will help you set up and run the script on your system. * **Automatisierte Log-Rotation**: Führt `logrotate` automatisch mit einer spezifischen Konfiguration aus.
* **Statusverfolgung**: Verwendet eine Statusdatei, um die Zeiten der letzten Rotationen zu verfolgen.
* **Fehlerbehandlung**: Prüft das Vorhandensein der Konfigurationsdatei und protokolliert Fehler, falls diese fehlt.
* **Protokollierung**: Zeichnet den Ausführungsstatus und eventuelle Fehler in einer dedizierten Logdatei auf.
### Prerequisites -----
* **`logrotate`**: This utility is typically pre-installed on most Linux distributions. If not, you can install it using your system's package manager (e.g., `sudo apt-get install logrotate` on Debian/Ubuntu, `sudo yum install logrotate` on CentOS/RHEL). ## Erste Schritte
Diese Anweisungen helfen dir, das Skript auf deinem System einzurichten und auszuführen.
### Voraussetzungen
* **`logrotate`**: Dieses Dienstprogramm ist in der Regel auf den meisten Linux-Distributionen vorinstalliert. Falls nicht, kannst du es mit dem Paketmanager deines Systems installieren (z.B. `sudo apt-get install logrotate` unter Debian/Ubuntu, `sudo yum install logrotate` unter CentOS/RHEL).
### Installation ### Installation
1. **Save the Script**: Copy the provided script content into a file (e.g., `run_logrotate.sh`) in your desired directory. 1. **Skript speichern**: Kopiere den Inhalt des bereitgestellten Skripts in eine Datei (z.B. `run_logrotate.sh`) in deinem gewünschten Verzeichnis.
2. **Make Executable**: Grant execute permissions to the script: 2. **Ausführbar machen**: Gib dem Skript Ausführungsberechtigungen:
```bash ```bash
chmod +x run_logrotate.sh chmod +x run_logrotate.sh
``` ```
3. **Create Configuration**: Create a `logrotate.cfg` file in the same directory as the script. This file will contain your `logrotate` rules. 3. **Konfiguration erstellen**: Erstelle eine Datei `logrotate.cfg` im selben Verzeichnis wie das Skript. Diese Datei enthält deine `logrotate`-Regeln.
4. **Create Log and Status Files**: The script will create these if they don't exist, but you can create empty ones manually if you prefer: 4. **Log- und Statusdateien erstellen**: Das Skript erstellt diese, falls sie nicht existieren, aber du kannst auch leere Dateien manuell erstellen, wenn du möchtest:
```bash ```bash
touch logrotate.status touch logrotate.status
touch logrotate.log touch logrotate.log
@ -37,11 +41,11 @@ These instructions will help you set up and run the script on your system.
----- -----
## Usage ## Verwendung
### Configuration (`logrotate.cfg`) ### Konfiguration (`logrotate.cfg`)
The `logrotate.cfg` file defines how your logs should be rotated. Here's a basic example: Die Datei `logrotate.cfg` definiert, wie deine Logs rotiert werden sollen. Hier ist ein einfaches Beispiel:
``` ```
/var/log/my_app/*.log { /var/log/my_app/*.log {
@ -55,54 +59,54 @@ The `logrotate.cfg` file defines how your logs should be rotated. Here's a basic
} }
``` ```
* Replace `/var/log/my_app/*.log` with the actual path to your log files. * Ersetze `/var/log/my_app/*.log` durch den tatsächlichen Pfad zu deinen Logdateien.
* `daily`: Rotate logs daily. * `daily`: Rotiert Logs täglich.
* `rotate 7`: Keep 7 rotated log files. * `rotate 7`: Behält 7 rotierte Logdateien.
* `compress`: Compress old log files. * `compress`: Komprimiert alte Logdateien.
* `missingok`: Don't issue an error if the log file is missing. * `missingok`: Gibt keinen Fehler aus, wenn die Logdatei fehlt.
* `notifempty`: Don't rotate the log if it is empty. * `notifempty`: Rotiert das Log nicht, wenn es leer ist.
* `create 640 root adm`: Create new log files with specified permissions and ownership. * `create 640 root adm`: Erstellt neue Logdateien mit den angegebenen Berechtigungen und Eigentümer.
* `dateext`: Archive rotated logs by adding a date extension. * `dateext`: Archiviert rotierte Logs, indem eine Datums-Erweiterung hinzugefügt wird.
For more details on `logrotate` configuration, refer to the `logrotate` man page (`man logrotate`). Weitere Details zur `logrotate`-Konfiguration findest du in der `logrotate`-Manpage (`man logrotate`).
### Running the Script ### Ausführen des Skripts
You can run the script manually: Du kannst das Skript manuell ausführen:
```bash ```bash
./run_logrotate.sh ./run_logrotate.sh
``` ```
### Automation (Cron Job) ### Automatisierung (Cron-Job)
To automate log rotation, it's recommended to set up a cron job. Um die Log-Rotation zu automatisieren, wird empfohlen, einen Cron-Job einzurichten.
1. Open your crontab for editing: 1. Öffne deine Crontab zur Bearbeitung:
```bash ```bash
crontab -e crontab -e
``` ```
2. Add a line to execute the script at your desired interval. For example, to run it daily at 3:00 AM: 2. Füge eine Zeile hinzu, um das Skript in deinem gewünschten Intervall auszuführen. Zum Beispiel, um es täglich um 3:00 Uhr morgens auszuführen:
```cron ```cron
0 3 * * * /home/oberkoetter/Dokumente/Git/rettedpv/run_logrotate.sh >> /dev/null 2>&1 0 3 * * * /home/oberkoetter/Dokumente/Git/rettedpv/run_logrotate.sh >> /dev/null 2>&1
``` ```
Make sure to replace `/home/oberkoetter/Dokumente/Git/rettedpv/run_logrotate.sh` with the actual full path to your script. The `>> /dev/null 2>&1` part redirects standard output and error to `/dev/null` to prevent unnecessary emails from cron. Stelle sicher, dass du `/home/oberkoetter/Dokumente/Git/rettedpv/run_logrotate.sh` durch den tatsächlichen vollständigen Pfad zu deinem Skript ersetzt. Der Teil `>> /dev/null 2>&1` leitet die Standardausgabe und Fehler nach \`/dev/null um, um unnötige E-Mails von Cron zu verhindern.
----- -----
## Script Details ## Skript-Details
The script performs the following actions: Das Skript führt die folgenden Aktionen aus:
1. **Changes Directory**: Navigates to `/home/oberkoetter/Dokumente/Git/rettedpv`. **Note:** You might want to adjust this path if you move the script. 1. **Verzeichnis wechseln**: Navigiert nach `/home/oberkoetter/Dokumente/Git/rettedpv`. **Hinweis:** Diesen Pfad solltest du anpassen, falls du das Skript verschiebst.
2. **Defines Paths**: Sets variables for the `logrotate.cfg`, `logrotate.status`, and `logrotate.log` files within the current working directory. 2. **Pfade definieren**: Setzt Variablen für die Dateien `logrotate.cfg`, `logrotate.status` und `logrotate.log` innerhalb des aktuellen Arbeitsverzeichnisses.
3. **Checks Configuration**: Verifies if `logrotate.cfg` exists. If not, it logs an error and exits. 3. **Konfiguration prüfen**: Überprüft, ob `logrotate.cfg` existiert. Falls nicht, wird ein Fehler protokolliert und das Skript beendet.
4. **Executes Logrotate**: Runs `logrotate` in forced mode (`-f`) using the specified configuration and status files. 4. **Logrotate ausführen**: Führt `logrotate` im erzwungenen Modus (`-f`) unter Verwendung der angegebenen Konfigurations- und Statusdateien aus.
5. **Logs Success**: Appends a success message to `logrotate.log` after a successful execution. 5. **Erfolg protokollieren**: Fügt eine Erfolgsmeldung zur Datei `logrotate.log` hinzu, nachdem eine erfolgreiche Ausführung stattgefunden hat.
----- -----
## Project Structure ## Projektstruktur
``` ```
. .
@ -112,17 +116,17 @@ The script performs the following actions:
└── logrotate.status └── logrotate.status
``` ```
* `run_logrotate.sh`: The main script to execute logrotate. * `run_logrotate.sh`: Das Hauptskript zur Ausführung von logrotate.
* `logrotate.cfg`: The configuration file for logrotate. * `logrotate.cfg`: Die Konfigurationsdatei für logrotate.
* `logrotate.log`: Logs the execution history of the script. * `logrotate.log`: Protokolliert die Ausführungshistorie des Skripts.
* `logrotate.status`: Logrotate's internal status file. * `logrotate.status`: Logrotates interne Statusdatei.
----- -----
## Troubleshooting ## Fehlerbehebung
* **"Fehler: Konfigurationsdatei './logrotate.cfg' nicht gefunden."**: Ensure `logrotate.cfg` is in the same directory as the script or update the `CONFIG` variable in the script to the correct path. * **"Fehler: Konfigurationsdatei './logrotate.cfg' nicht gefunden."**: Stelle sicher, dass `logrotate.cfg` sich im selben Verzeichnis wie das Skript befindet, oder aktualisiere die Variable `CONFIG` im Skript auf den korrekten Pfad.
* **Script not running via cron**: Double-check the cron job entry for correct paths and permissions. You can test by manually running the script. Also, check your `logrotate.log` for any errors. * **Skript wird nicht über Cron ausgeführt**: Überprüfe den Cron-Job-Eintrag auf korrekte Pfade und Berechtigungen. Du kannst dies testen, indem du das Skript manuell ausführst. Prüfe auch deine `logrotate.log` auf Fehler.
* **Log files not rotating**: Verify your `logrotate.cfg` syntax. You can test your `logrotate` configuration directly using `logrotate -d your_config_file` (debug mode) or `logrotate -f your_config_file` (force mode). * **Logdateien werden nicht rotiert**: Überprüfe die Syntax deiner `logrotate.cfg`. Du kannst deine `logrotate`-Konfiguration direkt testen, indem du `logrotate -d deine_konfigurationsdatei` (Debug-Modus) oder `logrotate -f deine_konfigurationsdatei` (Erzwingungsmodus) verwendest.
----- -----