Skip to content

Commit

Permalink
Log Rotate
Browse files Browse the repository at this point in the history
  • Loading branch information
fdevans committed Nov 25, 2024
1 parent 548fcf1 commit 2557058
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/.vuepress/sidebar-menus/learning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export default [{
children: [
{ link: '/learning/solutions/storage-management/index.md', text: 'Solution Summary' },
{ link: '/learning/solutions/storage-management/storage-list-largest-files.md', text: 'List Largest Files' },
{ link: '/learning/solutions/storage-management/storage-log-rotation.md', text: 'Log Rotation & Cleanup' },
]
}
]
Expand Down
51 changes: 51 additions & 0 deletions docs/learning/solutions/storage-management/storage-log-rotation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Log Rotation and Cleanup

This documentation provides details on how to use a Rundeck job to manually rotate, compress, and clean up log files in a specified directory. This job is useful for managing log files to prevent them from consuming excessive disk space.

::: note
This is just one example of how to implement a log rotation job. Other opportunities exist leveraging `logrotate` or other methods.
:::

## Job Description

This job will:
- Rotate log files by renaming them with a timestamp.
- Compress the rotated log files to save disk space.
- Delete old log files that exceed a specified retention period.

### Assumptions

- The job assumes the node is a Linux endpoint with `bash` and `gzip` installed.
- The default log directory is `/var/log/myapp`, and should be customized.

### Notes

- No nodes are selected by default. Change Target Nodes and select the endpoint to run against. If multiple nodes are selected the same script will be run on each node.

## Configuration

### Job Options

- **Log Directory:** The path where the log files are located. The default is `/var/log/myapp`.
- **Retention Days:** The number of days to retain old log files. The default is `30` days.

![job-options](/assets/img/log-rotation-job-options.png)<br>

## Successful Execution

Upon successful execution, the job will:
- Rename current log files by appending a timestamp.
- Compress the renamed log files.
- Remove compressed log files older than the specified retention period.

![success-output](/assets/img/log-rotation-success-output.png)<br>

## Troubleshooting

- **Log Rotation Issues**: Ensure the log directory and file permissions are correctly set.
- **Compression Issues**: Verify that `gzip` is installed and accessible on the system.
- **Cleanup Issues**: Check the retention period and ensure the `find` command syntax is correct.

## Conclusion

This custom log rotation and cleanup job helps manage log files efficiently by rotating, compressing, and deleting old logs. Adjust the script and configuration parameters as needed to fit your specific requirements.

0 comments on commit 2557058

Please sign in to comment.