aboutsummaryrefslogtreecommitdiffstats
path: root/system/usr/system-maintenance
blob: f7a70518a1a35de9513e887619641012edc2a0c3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
# /usr/local/bin/system-maintenance

# Configuration
MARKER_FILE="/var/log/last_maintenance_timestamp"
LOG_OUT="/var/log/maintenance.log"
# 604800 seconds = 7 days
INTERVAL=604800

# Get last run time or 0 if file doesn't exist
LAST_RUN=$(stat -c %Y "$MARKER_FILE" 2>/dev/null || echo 0)
CURRENT_TIME=$(date +%s)

if [ $((CURRENT_TIME - LAST_RUN)) -ge $INTERVAL ]; then
    {
        echo "-------------------------------------------"
        echo "[$(date)] Starting weekly maintenance..."

        # 1. Trim SSD
        /usr/sbin/fstrim -v /

        # 2. Run Backup (Example)
        # /usr/local/bin/backup.sh 2>&1

        # Update timestamp marker
        touch "$MARKER_FILE"

        echo "[$(date)] Maintenance complete."
    } >> "$LOG_OUT" 2>&1
fi