From 07bde9fe5732d9d56567569cd2217e8bc98eaab8 Mon Sep 17 00:00:00 2001 From: Pieter Date: Thu, 17 Dec 2020 14:31:09 +0100 Subject: [PATCH] I would hereby like to contribute a logrotate example. --- Logrotate-example.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Logrotate-example.md diff --git a/Logrotate-example.md b/Logrotate-example.md new file mode 100644 index 0000000..d8f90f6 --- /dev/null +++ b/Logrotate-example.md @@ -0,0 +1,38 @@ +Over time, the Bitwarden_RS log file can grow to a significant size. Using logrotate, we can periodically rotate logs. + +```sh +sudo nano /etc/logrotate.d/bitwarden +``` + +```sh +/var/log/bitwarden/*.log { + # Perform logrotation as the bitwarden user and group + su bitwarden bitwarden + # Rotate daily + daily + # Rotate when the size is bigger than 5MB + size 5M + # Compress old log files + compress + # Keep 4 rotations of log files before removing or mailing to the address specified in a mail directive + rotate 4 + # Truncate the original log file in place after creating a copy + copytruncate + # Don't panic if not found + missingok + # Don't rotate log if file is empty + notifempty + # Add date instaed of number to rotated log file + dateext + # Date format of dateext + dateformat -%Y-%m-%d-%s +} +``` + +To view a compressed log file without manually decompressing: + +```sh +zcat logfile.gz +zless logfile.gz +zgrep -i keyword_search logfile.gz +``` \ No newline at end of file