Vhtforums
AI Assistant
Log2RAM Filling Up?...
 
Notifications
Clear all

Log2RAM Filling Up? Here’s a Simple Cleanup Script

1 Posts
1 Users
0 Reactions
728 Views
Brandon Lee
Posts: 696
Admin
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@brandon-lee)
Member
Joined: 16 years ago
[#513]

I have been using the Log2RAM tool in the home lab on my Proxmox VE Server hosts to help keep from wearing out SSDs due to constant log writing. This is a really great tool that you can read more about here: azlux/log2ram: ramlog like for systemd (Put log into a ram folder).

But, I have learned you need to still keep an eye on your disk space usage as whatever size you allocate for the /var/log directory can become filled with logs and the process to dump these to disk may not happen often enough. Still more tweaks and understand needed on my part for that. However, check out this script that cleans jouranl, Ceph, pveproxy, and Veeam logs on Proxmox VE Server hosts you may be running.

#!/bin/bash

set -euo pipefail

JOURNAL_MAX_SIZE="50M"

hr() { echo "========================================"; }

hr
echo "Host: $(hostname)"
echo ""
echo "=== /var/log before cleanup ==="
df -h /var/log
hr

# --- 1. systemd journal ---
echo ""
echo "=== Vacuuming journal to ${JOURNAL_MAX_SIZE} ==="
journalctl --vacuum-size="${JOURNAL_MAX_SIZE}"

# --- 2. Ceph logs ---
echo ""
echo "=== Cleaning Ceph logs ==="
if [[ -d /var/log/ceph ]]; then
    find /var/log/ceph -name "*.log.*" -delete 2>/dev/null && echo "Rotated logs deleted" || echo "No rotated logs found"
    # Truncate live logs - daemons hold fds open so we can't delete
    while IFS= read -r f; do
        size=$(du -sh "$f" 2>/dev/null | cut -f1)
        truncate -s 0 "$f"
        echo "Truncated: $f (was ${size})"
    done < <(find /var/log/ceph -maxdepth 2 -name "*.log" -type f)
else
    echo "No Ceph log directory found, skipping"
fi

# --- 3. pveproxy logs ---
echo ""
echo "=== Cleaning pveproxy logs ==="
if [[ -d /var/log/pveproxy ]]; then
    find /var/log/pveproxy -name "*.log.*" -delete 2>/dev/null && echo "Rotated logs deleted" || echo "No rotated logs found"
    for f in access.log api2.log; do
        if [[ -f "/var/log/pveproxy/$f" ]]; then
            size=$(du -sh "/var/log/pveproxy/$f" | cut -f1)
            truncate -s 0 "/var/log/pveproxy/$f"
            echo "Truncated: $f (was ${size})"
        fi
    done
else
    echo "No pveproxy log directory found, skipping"
fi

# --- 4. Veeam logs ---
echo ""
echo "=== Cleaning Veeam logs ==="
veeam_found=false
for veeam_dir in /var/log/VeeamBackup /var/log/veeam; do
    if [[ -d "$veeam_dir" ]]; then
        veeam_found=true
        find "$veeam_dir" -name "*.log.*" -delete 2>/dev/null && echo "Rotated logs deleted in $veeam_dir" || echo "No rotated logs found in $veeam_dir"
    fi
done
$veeam_found || echo "No Veeam log directories found, skipping"

# --- 5. Flush log2ram to disk ---
echo ""
echo "=== Flushing log2ram to disk ==="
if systemctl is-active --quiet log2ram; then
    if [[ -x /usr/local/bin/log2ram ]]; then
        /usr/local/bin/log2ram write
        echo "log2ram flushed to disk"
    else
        systemctl restart log2ram
        echo "log2ram restarted (write command not available)"
    fi
else
    echo "log2ram not active, skipping"
fi

# --- Summary ---
hr
echo ""
echo "=== /var/log after cleanup ==="
df -h /var/log
echo ""
echo "=== Top 10 remaining log consumers ==="
du -sh /var/log/* 2>/dev/null | sort -rh | head -10
hr