Skip to content

Commit ccd4839

Browse files
committed
Modyfing openVPN logrotate configuration to keep the logs for a year.
The daily rotation was configured to keep daily logs for a week. A new script to manage weekly rotation and keep those logs for a year was generated to be put into /etc/cron.weekly Fixes: https://ibm.monday.com/boards/5591222586/pulses/8354436354 Signed-off-by: Fernando <fernando.alcocer.ochoa@ibm.com>
1 parent 2148524 commit ccd4839

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

roles/gateway/files/openvpn.logrotate

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/var/log/openvpn/*.log {
22
daily
3-
rotate 90
3+
rotate 7
44
compress
55
missingok
66
copytruncate
77
notifempty
8-
create 644 nobody nobody
8+
dateext
9+
dateformat -%Y-%m-%d-daily
910
}
11+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
LOG_DIR="/var/log/openvpn"
4+
LOG_FILE="openvpn.log"
5+
ARCHIVE_DIR="/var/log/openvpn/weekly-logs"
6+
WEEKLY_ARCHIVE_NAME="openvpn-$(date +\%Y-\%m-\%d)_weekly_logs.tar.gz"
7+
RETENTION_DAYS=365 # Keep weekly archives for a year
8+
9+
# Create archive directory if it doesn't exist
10+
mkdir -p "$ARCHIVE_DIR"
11+
12+
# Temporary folder for decompressed logs
13+
TEMP_DIR=$(mktemp -d)
14+
15+
# Decompress all rotated daily logs (mylogfile.log.1.gz, mylogfile.log.2.gz, etc.)
16+
for file in $(find "$LOG_DIR" -name "$LOG_FILE-*");
17+
do gzip -d -c $file > "$TEMP_DIR/$(basename $file .gz)";
18+
done
19+
20+
# Create a compressed archive with all daily logs from the past week
21+
tar -czf "$ARCHIVE_DIR/$WEEKLY_ARCHIVE_NAME" -C "$TEMP_DIR" .
22+
23+
# Cleanup temporary files
24+
rm -rf "$TEMP_DIR"
25+
26+
# Delete archives older than a year
27+
find "$ARCHIVE_DIR" -name "*.tar.gz" -mtime +$RETENTION_DAYS -delete

roles/gateway/tasks/logging.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
dest: /etc/logrotate.d/openvpn
1414
notify: restart rsyslog
1515

16+
- name: Write weekly rotation script on anacron
17+
copy:
18+
src: files/openvpn_weekly_rotation
19+
dest: /etc/cron.weekly/openvpn_weekly_rotation
20+
mode: '0755'
21+
owner: root
22+
group: root
23+
1624
- name: Write rsyslog conf file
1725
copy:
1826
src: files/openvpn.rsyslog

0 commit comments

Comments
 (0)