Table of Contents

Nginx Log Rotation Script

Overview

This Bash script is designed to manage and rotate Nginx log files. It ensures that logs are periodically backed up, cleared, and maintained efficiently by keeping only the latest backups.

Script Functionality

1. Define Log File Paths:

2. Verify Log File Existence:

3. Backup Logs :

4. Verify Backup Success:

5. Clear Log Files:

6. Backup Retention Management:

Usage Instructions

  1. Clone the Scrlipt via the git link
$ git clone git@git.elosys.net:sys/bin.git 
  1. Make it executable
sudo chmod +x nginx_rotation.sh
  1. Automate it with a cron job to run periodically
sudo cronjob -e
40 1 */3 * * /home/admin/bin/gitlab_log_rotation.sh

Conclusion

This script automates the log rotation process for Nginx logs by ensuring efficient backup and cleanup. By maintaining only the last 7 backups, it helps manage disk space while ensuring log history is available when needed.


Nadir Habib 2025/02/28 20:57