Automation

Essential Cron Jobs for Proxmox VE Maintenance

Automate Proxmox VE maintenance with cron jobs for ZFS scrubs, backup cleanup, certificate renewal, snapshot cleanup, SMART checks, and kernel update reboots.

ProxmoxR app icon

Managing Proxmox? Try ProxmoxR

Monitor and control your VMs & containers from your phone.

Try Free

Why Automate Maintenance?

A Proxmox VE server requires regular maintenance: ZFS pools need scrubbing, old backups consume storage, snapshots accumulate, and disks need health monitoring. Instead of remembering to perform these tasks manually, schedule them with cron jobs. This ensures consistent maintenance and prevents issues like full storage or undetected disk failures from surprising you.

ZFS Scrub Schedule

ZFS scrubs verify data integrity by reading every block and checking it against its checksum. Proxmox includes a default monthly scrub, but you can customize the schedule:

# Check the existing ZFS scrub timer:
systemctl list-timers | grep zfs

# Proxmox uses systemd timers for ZFS scrubs by default:
cat /etc/systemd/system/zfs-scrub@.timer

# To customize, create a cron job instead:
crontab -e

# Run ZFS scrub on the first Sunday of each month at 2 AM:
0 2 1-7 * 0 /sbin/zpool scrub rpool

# For multiple pools:
0 2 1-7 * 0 /sbin/zpool scrub rpool && /sbin/zpool scrub datapool

# Check scrub status:
zpool status rpool | grep scan

Backup Cleanup

Even with retention policies configured in Proxmox backup jobs, you may want additional cleanup scripts to catch edge cases or manage backups across multiple storage targets:

# Remove backups older than 30 days from a directory storage:
cat > /usr/local/bin/cleanup-backups.sh << 'SCRIPT'
#!/bin/bash
BACKUP_DIR="/var/lib/vz/dump"
DAYS=30

find "$BACKUP_DIR" -name "vzdump-*" -type f -mtime +$DAYS -delete
echo "$(date): Cleaned backups older than $DAYS days from $BACKUP_DIR" >> /var/log/backup-cleanup.log
SCRIPT

chmod +x /usr/local/bin/cleanup-backups.sh

# Schedule weekly cleanup on Sunday at 4 AM:
# Add to crontab:
0 4 * * 0 /usr/local/bin/cleanup-backups.sh

SSL Certificate Renewal

If you use Let's Encrypt certificates with Proxmox (via ACME), the renewal is handled automatically. For custom certificates or additional renewal hooks:

# Check if ACME is configured:
pvenode acme account list

# Force a renewal check (Proxmox handles this, but you can add a safety net):
# Add to crontab - attempt renewal daily at 3 AM:
0 3 * * * /usr/bin/pvenode acme cert renew 2>&1 | logger -t acme-renew

# Restart pveproxy after renewal to load new certs:
0 3 * * * /usr/bin/pvenode acme cert renew && /bin/systemctl restart pveproxy 2>&1 | logger -t acme-renew

Snapshot Cleanup

Snapshots that are never cleaned up consume increasing amounts of storage and degrade performance. Automate snapshot cleanup for development VMs:

# Create a snapshot cleanup script:
cat > /usr/local/bin/cleanup-snapshots.sh << 'SCRIPT'
#!/bin/bash
# Remove snapshots older than 7 days for specified VMs
MAX_AGE_DAYS=7
VMS="101 102 103"  # VM IDs to clean

for VMID in $VMS; do
    for SNAP in $(qm listsnapshot $VMID | grep -v current | awk '{print $2}' | grep -v "^$"); do
        # Get snapshot creation time from config
        SNAP_TIME=$(qm config $VMID --snapshot "$SNAP" 2>/dev/null | grep snaptime | awk '{print $2}')
        if [ -n "$SNAP_TIME" ]; then
            AGE=$(( ($(date +%s) - SNAP_TIME) / 86400 ))
            if [ "$AGE" -gt "$MAX_AGE_DAYS" ]; then
                echo "Deleting snapshot '$SNAP' from VM $VMID (${AGE} days old)"
                qm delsnapshot $VMID "$SNAP"
            fi
        fi
    done
done
SCRIPT

chmod +x /usr/local/bin/cleanup-snapshots.sh

# Schedule daily at 5 AM:
0 5 * * * /usr/local/bin/cleanup-snapshots.sh >> /var/log/snapshot-cleanup.log 2>&1

Disk SMART Health Checks

Monitor disk health proactively with scheduled SMART checks. Catch failing drives before they cause data loss:

# Create a SMART check script:
cat > /usr/local/bin/smart-check.sh << 'SCRIPT'
#!/bin/bash
# Check SMART status of all disks and alert on failures
ALERT_EMAIL="admin@example.com"

for DISK in $(lsblk -d -n -o NAME | grep -E '^sd|^nvme'); do
    HEALTH=$(smartctl -H /dev/$DISK 2>/dev/null | grep -i "result\|status" | head -1)
    if echo "$HEALTH" | grep -qi "failed\|failing"; then
        echo "SMART FAILURE on /dev/$DISK: $HEALTH" | mail -s "DISK ALERT: /dev/$DISK failing on $(hostname)" "$ALERT_EMAIL"
    fi
done

# Also check for reallocated sectors:
for DISK in $(lsblk -d -n -o NAME | grep -E '^sd'); do
    REALLOC=$(smartctl -A /dev/$DISK 2>/dev/null | grep "Reallocated_Sector" | awk '{print $10}')
    if [ -n "$REALLOC" ] && [ "$REALLOC" -gt 0 ]; then
        echo "WARNING: /dev/$DISK has $REALLOC reallocated sectors" | mail -s "DISK WARNING on $(hostname)" "$ALERT_EMAIL"
    fi
done
SCRIPT

chmod +x /usr/local/bin/smart-check.sh

# Schedule daily at 6 AM:
0 6 * * * /usr/local/bin/smart-check.sh

Reboot on Kernel Update

Proxmox kernel updates require a reboot to take effect. You can automate a reboot check after updates, though this should be used carefully in production:

# Create a kernel reboot check script:
cat > /usr/local/bin/check-kernel-reboot.sh << 'SCRIPT'
#!/bin/bash
# Check if a reboot is needed after kernel update
RUNNING=$(uname -r)
INSTALLED=$(dpkg -l | grep "proxmox-kernel-.*-pve" | awk '{print $3}' | sort -V | tail -1)

if [ "$RUNNING" != "$INSTALLED" ] 2>/dev/null; then
    echo "Kernel update detected. Running: $RUNNING" | logger -t kernel-check
    # Option 1: Send notification (safer):
    echo "Proxmox host $(hostname) needs a reboot for kernel $INSTALLED" | mail -s "Reboot needed: $(hostname)" admin@example.com
    # Option 2: Schedule reboot at next maintenance window (uncomment if desired):
    # shutdown -r 02:00 "Scheduled reboot for kernel update"
fi
SCRIPT

chmod +x /usr/local/bin/check-kernel-reboot.sh

# Check daily at 7 AM:
0 7 * * * /usr/local/bin/check-kernel-reboot.sh

Keeping track of scheduled maintenance tasks and their results is simpler when you have quick access to your Proxmox node status. ProxmoxR lets you check at a glance whether your server successfully completed a scheduled reboot or if VMs came back online after maintenance — all from your phone.

Summary

Cron jobs are the backbone of Proxmox maintenance automation. Schedule ZFS scrubs to verify data integrity, clean up old backups and snapshots to reclaim storage, monitor disk health with SMART checks, automate certificate renewal, and track kernel updates that need reboots. Start with the most critical jobs (SMART checks and ZFS scrubs) and gradually add more as your environment grows. Always test scripts manually before scheduling them, and log their output so you can troubleshoot failures.

Take Proxmox management mobile

All the features discussed in this guide — accessible from your phone with ProxmoxR. Real-time monitoring, power control, firewall management, and more.

ProxmoxR

Manage Proxmox from your phone

Monitor, control, and manage your clusters on the go.

Free 7-day trial · No credit card required