This document analyzes all crontab entries and scheduled jobs on the Proxmox server.
The system-wide crontab (/etc/crontab) contains standard entries for running hourly, daily, weekly, and monthly scripts:
# /etc/crontab: system-wide crontab
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.daily; }
47 6 * * 7 root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.weekly; }
52 6 1 * * root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.monthly; }
Time | Job | Description |
---|---|---|
17 minutes past every hour | run-parts --report /etc/cron.hourly |
Executes all scripts in the /etc/cron.hourly directory |
6:25 AM daily | run-parts --report /etc/cron.daily |
Executes all scripts in the /etc/cron.daily directory (if anacron is not installed) |
6:47 AM on Sundays | run-parts --report /etc/cron.weekly |
Executes all scripts in the /etc/cron.weekly directory (if anacron is not installed) |
6:52 AM on the 1st day of each month | run-parts --report /etc/cron.monthly |
Executes all scripts in the /etc/cron.monthly directory (if anacron is not installed) |
The root user has a personal crontab with the following entry:
47 3 * * * /bin/bash /scripts/trim_and_scrub.sh >> /var/log/trim_and_scrub_cron.log 2>&1
Time | Job | Description |
---|---|---|
3:47 AM daily | /bin/bash /scripts/trim_and_scrub.sh |
Runs the trim and scrub maintenance script for ZFS pools and file systems |
This script performs three main storage maintenance operations:
#!/bin/bash
#
# trim_and_scrub.sh - Scrub NVME pool, trim all ZFS pools, and run fstrim on all mount points.
#
LOGFILE="/scripts/trim_all.log"
echo "Starting maintenance: $(date)" >> "$LOGFILE"
# 1) Run ZFS scrub on NVME pool
echo "Starting ZFS scrub on NVME pool..." >> "$LOGFILE"
/sbin/zpool scrub NVME >> "$LOGFILE" 2>&1
echo "ZFS scrub command issued for NVME." >> "$LOGFILE"
# Note: The scrub process runs in the background and may take a while to complete.
# 2) Trim all ZFS pools
for pool in $(/sbin/zpool list -H -o name); do
echo "Trimming ZFS pool: $pool" >> "$LOGFILE"
/sbin/zpool trim "$pool" >> "$LOGFILE" 2>&1
done
# 3) Run fstrim on all mounted file systems
echo "Running fstrim on all mount points" >> "$LOGFILE"
/sbin/fstrim -av >> "$LOGFILE" 2>&1
echo "Completed maintenance: $(date)" >> "$LOGFILE"
Operations performed:
Purpose: Regular maintenance to ensure data integrity, optimal SSD performance, and prevent degradation of storage systems.
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# TRIM the first Sunday of every month.
24 0 1-7 * * root if [ $(date +\%w) -eq 0 ] && [ -x /usr/lib/zfs-linux/trim ]; then /usr/lib/zfs-linux/trim; fi
# Scrub the second Sunday of every month.
24 0 8-14 * * root if [ $(date +\%w) -eq 0 ] && [ -x /usr/lib/zfs-linux/scrub ]; then /usr/lib/zfs-linux/scrub; fi
Time | Job | Description |
---|---|---|
00:24 AM on the first Sunday of each month | /usr/lib/zfs-linux/trim |
Runs TRIM operations on ZFS pools |
00:24 AM on the second Sunday of each month | /usr/lib/zfs-linux/scrub |
Runs scrub operations on ZFS pools |
Purpose: These are automated maintenance tasks for ZFS file systems that help maintain data integrity and performance.
30 3 * * 0 root test -e /run/systemd/system || SERVICE_MODE=1 /usr/lib/x86_64-linux-gnu/e2fsprogs/e2scrub_all_cron
10 3 * * * root test -e /run/systemd/system || SERVICE_MODE=1 /sbin/e2scrub_all -A -r
Time | Job | Description |
---|---|---|
3:30 AM every Sunday | /usr/lib/x86_64-linux-gnu/e2fsprogs/e2scrub_all_cron |
Weekly full disk scrubbing for ext4 filesystems |
3:10 AM daily | /sbin/e2scrub_all -A -r |
Daily check for ext4 filesystems with the -A (all) and -r (repair) flags |
Purpose: Filesystem maintenance for ext4 filesystems to ensure integrity and repair any issues detected.
File: /scripts/snapshot.sh
This script creates and manages VM snapshots with retention policies:
#!/bin/bash
# Configuration
VM_ID="100" # Proxmox VM ID
STORAGE_POOL_NVME="NVME" # ZFS pool name
MIN_FREE_GB=30 # Minimum required free space in GB
SNAPSHOT_RETENTION=3 # Number of snapshots to keep (changed from 7 to 3)
SNAPSHOT_NAME="autosnap-$(date +'%Y-%m-%d')" # NZ Date format (1 snapshot per day)
LOG_FILE="/scripts/snapshot.log" # Log file path
# Function to check free space on the NVME ZFS pool
check_free_space() {
local pool="$1"
local available=$(zfs list -Ho avail "$pool")
# Convert available space to GB, handling different units
case "$available" in
*G) echo "${available%G}" ;;
*M) echo "$(bc <<< "scale=2; ${available%M} / 1024")" ;;
*K) echo "$(bc <<< "scale=2; ${available%K} / 1048576")" ;;
*) echo "0" ;; # Default to 0 if parsing fails
esac
}
# Check free space on NVME pool
FREE_SPACE_NVME=$(check_free_space "$STORAGE_POOL_NVME")
echo "Available space - NVME: ${FREE_SPACE_NVME}GB" | tee -a "$LOG_FILE"
# Ensure NVME has enough free space
if (( $(echo "$FREE_SPACE_NVME < $MIN_FREE_GB" | bc -l) )); then
echo "Not enough free space available (NVME: ${FREE_SPACE_NVME}GB). Deleting old snapshots..." | tee -a "$LOG_FILE"
# List and delete the oldest snapshot if retention is exceeded
SNAPSHOTS=$(/usr/sbin/qm listsnapshot $VM_ID | tail -n +2 | awk '{print $2}' | grep autosnap | sort | head -n 1)
if [[ ! -z "$SNAPSHOTS" ]]; then
echo "Deleting snapshot: $SNAPSHOTS" | tee -a "$LOG_FILE"
/usr/sbin/qm delsnapshot $VM_ID "$SNAPSHOTS"
else
echo "No old snapshots found to delete." | tee -a "$LOG_FILE"
exit 1
fi
fi
# Create a new snapshot without RAM
echo "Creating new snapshot: $SNAPSHOT_NAME for VM $VM_ID" | tee -a "$LOG_FILE"
/usr/sbin/qm snapshot $VM_ID "$SNAPSHOT_NAME" --vmstate 0
# Enforce snapshot retention limit
echo "Checking snapshot retention..." | tee -a "$LOG_FILE"
SNAPSHOT_COUNT=$(/usr/sbin/qm listsnapshot $VM_ID | tail -n +2 | awk '{print $2}' | grep autosnap | wc -l)
if [[ "$SNAPSHOT_COUNT" -gt "$SNAPSHOT_RETENTION" ]]; then
OLD_SNAPSHOTS=$(/usr/sbin/qm listsnapshot $VM_ID | tail -n +2 | awk '{print $2}' | grep autosnap | sort | head -n $(($SNAPSHOT_COUNT - $SNAPSHOT_RETENTION)))
echo "Deleting old snapshots beyond retention limit..." | tee -a "$LOG_FILE"
while read snapshot; do
/usr/sbin/qm delsnapshot $VM_ID "$snapshot"
echo "Deleted: $snapshot" | tee -a "$LOG_FILE"
done <<< "$OLD_SNAPSHOTS"
fi
echo "Snapshot process completed successfully!" | tee -a "$LOG_FILE"
Purpose: Creates and manages automatic snapshots for VM 100, maintaining a retention policy of 3 snapshots, and ensuring adequate free space on the NVME pool.
/scripts/oldbacks.sh
#!/bin/bash
# Correct backup directory for proxback
BACKUP_DIR="/mnt/proxback"
# Retention period (number of days to keep backups)
RETENTION_DAYS=3
# Ensure backup directory exists
if [ -d "$BACKUP_DIR" ]; then
echo "Deleting backups older than $RETENTION_DAYS days in $BACKUP_DIR"
# Find and delete backups older than retention period
find "$BACKUP_DIR" -type f -name "*.vma.zst" -mtime +$RETENTION_DAYS -exec rm -f {} \;
find "$BACKUP_DIR" -type f -name "*.log" -mtime +$RETENTION_DAYS -exec rm -f {} \;
echo "Old backups removed."
else
echo "Backup directory $BACKUP_DIR does not exist."
exit 1
fi
Purpose: Manages the retention of VM backups by removing backup files older than 3 days from the proxback storage.
/scripts/oldbacks_backup.sh
#!/bin/bash
BACKUP_DIR="/var/lib/vz/dump" # Updated to default backup directory
# Check if the backup directory exists
if [ -d "$BACKUP_DIR" ]; then
# Find and delete the oldest backup file
OLDEST_BACKUP=$(ls -1t "$BACKUP_DIR"/*.vma* 2>/dev/null | tail -n 1)
if [ -n "$OLDEST_BACKUP" ]; then
echo "Deleting oldest backup: $OLDEST_BACKUP"
rm -f "$OLDEST_BACKUP"
else
echo "No backup files found in $BACKUP_DIR."
}
else
echo "Backup directory $BACKUP_DIR does not exist."
exit 1
fi
Purpose: Alternate backup cleanup script that removes only the oldest backup file from the default Proxmox backup location.
The system has standard maintenance jobs in the following directories:
/etc/cron.daily/logrotate
: Rotates log files to prevent disk space issues/etc/cron.daily/apt-compat
: Handles automatic updates for Debian packages/etc/cron.daily/man-db
: Updates the manual page database/etc/cron.daily/dpkg
: Cleans up the package management system/etc/cron.weekly/man-db
: Weekly more comprehensive manual page database updateStorage Maintenance Chain:
Backup and Retention Chain:
Filesystem Health Chain: