TrashNotes

2025-03-11 21:19:35
подрезка логов mysql

---
- hosts: all
  become: true
  tasks:
    - name: Create maria-log-truncate script
      copy:
        content: |
          #!/bin/bash

          rm -f /var/log/mysql/*.zst

          for file in /var/log/mysql/*; do
            if [ -f "$file" ] && [ $(stat -c%s "$file") -gt 1048576 ]; then
              zstd "$file"
              truncate -s 0 "$file"
            fi
          done
        dest: /usr/local/bin/maria-log-truncate
        mode: 0755

    - name: Ensure cron is installed
      package:
        name: cron
        state: present

    - name: Add cron job for maria-log-truncate
      cron:
        name: "Weekly MySQL log truncation"
        minute: "40"
        hour: "03"
        day: "*"
        weekday: "3"  # 3 соответствует среде
        user: root
        job: "/usr/local/bin/maria-log-truncate"
← Previous Next →
Back to list