[SOLVED] Task log retention

jlsol1

New Member
Sep 18, 2023
1
0
1
Hi, is there any way of increasing the length of time that logs are stored in /var/log/pve/tasks? It doesn't look like they are cleanup up by logrotate.
 
  • Like
Reactions: jlsol1
Hi, no there is no option to configure this. The size of the archived tasks is hard coded to about 1000 entries, as you can see here https://git.proxmox.com/?p=pve-comm...6f62250b47c7b4aee163d2adeb847685;hb=HEAD#l354

The tasks are cleaned up once they are not referenced by index.1 anymore, which happens here https://git.proxmox.com/?p=pve-mana...4e01931b2f6b9577c49b0514745ba9eb;hb=HEAD#l129
I made a script that changes the number of 20,000 entries (around 1 year task history) by cron.

How the Script Works
This script automatically increases the number of Proxmox VE Task History entries by modifying the $maxsize parameter in the /usr/share/perl5/PVE/RESTEnvironment.pm file. By default, this parameter limits the task history to about 1000 entries ($maxsize = 50000). The script changes it to allow for 20,000 entries ($maxsize = 1000000).

Key Features:

  1. Checks for the existence of the target file.
  2. Searches for the specific $maxsize line.
  3. If found:
    • Creates a timestamped backup of the original file.
    • Replaces the line with the updated $maxsize value.
    • Logs the action in journald.
    • Restarts necessary Proxmox services (pvedaemon and pveproxy).
  4. Automatically runs at system boot and every hour using a cron job.

Create the script at /etc/cronscripts/change_pve_task_history_size/update_pve_max_task_history_size.sh:
Bash:
#!/bin/bash

# /etc/cronscripts/change_pve_task_history_size/update_pve_max_task_history_size.sh

# Path to the RESTEnvironment.pm file
FILE="/usr/share/perl5/PVE/RESTEnvironment.pm"

# Search and replacement strings
SEARCH="my \$maxsize = 50000; # about 1000 entries"
REPLACE="my \$maxsize = 1000000; # about 20000 entries, around 1 year task history"

# Check if the file exists
if [[ -f "$FILE" ]]; then
    # Check if the target string exists in the file
    if grep -qF "$SEARCH" "$FILE"; then
        logger -t change_pve_task_history_size "String found in $FILE. Replacing '$SEARCH' with '$REPLACE'."
       
        # Create a backup of the file
        BACKUP_FILE="$FILE.$(date +%Y%m%d_%H%M%S)"
        cp "$FILE" "$BACKUP_FILE"
        logger -t change_pve_task_history_size "Backup created: $BACKUP_FILE"
       
        # Replace the target string in the file
        sed -i "s|$SEARCH|$REPLACE|" "$FILE"
        logger -t change_pve_task_history_size "String replaced successfully in $FILE."
       
        # Restart Proxmox services
        systemctl restart pvedaemon.service pveproxy.service
        logger -t change_pve_task_history_size "Services restarted."
    else
        logger -t change_pve_task_history_size "Search string not found in $FILE. No changes made."
    fi
else
    logger -t change_pve_task_history_size "File $FILE does not exist!"
fi


Create a cron job file at /etc/cron.d/change_pve_task_history_size:
Bash:
# Cron job for updating Proxmox task history size

# /etc/cron.d/change_pve_task_history_size

@reboot root /etc/cronscripts/change_pve_task_history_size/update_pve_max_task_history_size.sh
0 * * * * root /etc/cronscripts/change_pve_task_history_size/update_pve_max_task_history_size.sh


Test the Script:Run the script manually to ensure it works as expected:

/etc/cronscripts/change_pve_task_history_size/update_pve_max_task_history_size.sh

Verify Logs:Check the logs in journald:


journalctl -t change_pve_task_history_size

Example Log Output
Bash:
Jan 06 12:00:00 hostname change_pve_task_history_size[1234]: String found in /usr/share/perl5/PVE/RESTEnvironment.pm. Replacing 'my $maxsize = 50000; # about 1000 entries' with 'my $maxsize = 1000000; # about 20000 entries, around 1 year task history'.
Jan 06 12:00:00 hostname change_pve_task_history_size[1234]: Backup created: /usr/share/perl5/PVE/RESTEnvironment.pm.20250106_120000
Jan 06 12:00:00 hostname change_pve_task_history_size[1234]: String replaced successfully in /usr/share/perl5/PVE/RESTEnvironment.pm.
Jan 06 12:00:01 hostname change_pve_task_history_size[1234]: Services restarted.