56 lines
1.7 KiB
Plaintext
56 lines
1.7 KiB
Plaintext
##Log rotate
|
|
|
|
```bash
|
|
# /etc/logrotate.d/azure_logs
|
|
|
|
/opt/AZURE/*.txt {
|
|
weekly
|
|
missingok
|
|
rotate 4
|
|
compress
|
|
delaycompress
|
|
notifempty
|
|
create 0644 root root
|
|
}
|
|
|
|
~/.azcopy/*.log {
|
|
weekly
|
|
missingok
|
|
rotate 4
|
|
compress
|
|
delaycompress
|
|
notifempty
|
|
create 0644 root root
|
|
}
|
|
```
|
|
|
|
### Explanation:
|
|
- **weekly**: Rotate the logs on a weekly basis.
|
|
- **missingok**: If the log file is missing, go on to the next one without issuing an error message.
|
|
- **rotate 4**: Keep only the last 4 weeks of logs.
|
|
- **compress**: Compress the rotated logs using gzip.
|
|
- **delaycompress**: Delay compression until the next rotation cycle. This means the current log file will not be compressed immediately after rotation, but the previous log files will be.
|
|
- **notifempty**: Do not rotate the log if it is empty.
|
|
- **create 0644 root root**: Create new log files with owner `root` and group `root`, and permissions `0644`.
|
|
|
|
### Steps to Apply the Configuration:
|
|
1. Save the above configuration in `/etc/logrotate.d/azure_logs`.
|
|
2. Ensure that the `logrotate` service is enabled and running on your system.
|
|
3. Test the logrotate configuration with the following command to ensure there are no syntax errors:
|
|
|
|
```bash
|
|
sudo logrotate -d /etc/logrotate.d/azure_logs
|
|
```
|
|
|
|
The `-d` option runs logrotate in debug mode, which will show you what actions would be taken without actually performing them.
|
|
|
|
4. If everything looks good, you can force a rotation to test it:
|
|
|
|
```bash
|
|
sudo logrotate -f /etc/logrotate.d/azure_logs
|
|
```
|
|
|
|
This will rotate the logs immediately according to the specified configuration.
|
|
|
|
By following these steps, your logs in `/opt/AZURE` and `~/.azcopy` should be rotated weekly, compressed, and kept for only the last 4 weeks.
|