You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support for copytruncate method when rotating input logs with an external tool in filestream input (#23457)
## What does this PR do?
The PR makes the `filestream` log rotation aware to make sure Filebeat can cooperate better with external log rotation tools. The first supported strategy is `copytruncate`.
When `logrotate` rotates e.g. `boot.log` with `copytruncate` the following things happen:
1. all archived files are renamed e.g. `boot.log.2` is renamed `boot.log.3` until `boot.log.1` no longer exists
2. `boot.log` is copied to `boot.log.1`
3. `boot.log` is truncated
You can see my tests on my machine:
Before rotation:
```
root@sleipnir:/home/n# ls -lisaht /var/log/boot.log*
130476 30K -rw------- 1 root root 28K Jan 29 08:59 /var/log/boot.log
130577 36K -rw------- 1 root root 34K Jan 29 08:59 /var/log/boot.log.1
130657 60K -rw------- 1 root root 57K Jan 7 09:51 /var/log/boot.log.2
```
After rotation:
```
root@sleipnir:/home/n# ls -lisaht /var/log/boot.log*
130476 0 -rw------- 1 root root 0 May 25 12:41 /var/log/boot.log
130430 30K -rw------- 1 root root 28K May 25 12:41 /var/log/boot.log.1
130577 36K -rw------- 1 root root 34K Jan 29 08:59 /var/log/boot.log.2
130657 60K -rw------- 1 root root 57K Jan 7 09:51 /var/log/boot.log.3
```
On rotation, the active file is continued and archived files are kept open until EOF is reached.
### Configuration
```yaml
rotation.external.strategy.copytruncate:
suffix_regex: \.\d$
count: 10
```
Note: when Filebeat will be able to rotate input logs, its configuration will be under `rotation.internal.*`.
## Why is it important?
Previously, Filebeat was not able to cooperate with external log rotation tools that used `copytruncate` method.
(cherry picked from commit 1f5198e)
0 commit comments