Bot & Automation
vps-monitor-bot
/root/hermes-projects/vps-monitor-bot
clean.sh
text
#!/bin/bash
# clean.sh - System-wide VPS cleanup script for VPS Monitor Bot
# Cleans logs, docker cache, package cache, python cache, and SQLite databases.
# Set working directory to the script's directory
cd "$(dirname "$0")"
echo "๐งน [VPS Cleanup] Memulai pembersihan sistem VPS..."
# 1. System Logs Cleanup
echo "๐ Membersihkan log journald (menyisakan 3 hari)..."
journalctl --vacuum-time=3d 2>/dev/null || echo "โ ๏ธ journalctl tidak didukung atau hak akses ditolak."
# 2. Package Manager Cache Cleanup
echo "๐ฆ Membersihkan cache paket apt..."
apt-get clean
apt-get autoclean -y
# 3. Docker Cache Cleanup
if systemctl is-active --quiet docker; then
echo "๐ณ Membersihkan cache Docker (images/containers tidak terpakai)..."
docker system prune -f
docker builder prune -f
else
echo "๐ณ Docker tidak aktif, melewati pembersihan Docker."
fi
# 4. Filesystem python cache in vps-monitor-bot
echo "๐ Membersihkan file cache python vps-monitor-bot..."
find . -name "*.pyc" -not -path "./venv/*" -delete
find . -name "__pycache__" -not -path "./venv/*" -type d -exec rm -rf {} + 2>/dev/null
# 5. Run Hermes Bot cleanup script if exists
HERMES_CLEAN_SH="/root/hermes-projects/hermes-ai-tech-intelligence/clean.sh"
if [ -f "$HERMES_CLEAN_SH" ]; then
echo "๐ Memicu skrip pembersihan Hermes Bot..."
bash "$HERMES_CLEAN_SH"
else
echo "โ ๏ธ Skrip pembersihan Hermes Bot tidak ditemukan di $HERMES_CLEAN_SH"
fi
# 6. Optimize other SQLite databases
echo "๐๏ธ Mengoptimasi database SQLite lainnya..."
for DB in "/root/.9router/db/data.sqlite" "/root/.hermes/state.db" "/root/.hermes/node/lib/node_modules/9router/app/cli/.build-home/.9router/db/data.sqlite"; do
if [ -f "$DB" ]; then
SIZE_BEFORE=$(du -h "$DB" | cut -f1)
python3 -c "import sqlite3; conn = sqlite3.connect('$DB'); conn.isolation_level = None; conn.execute('VACUUM'); conn.close()" 2>/dev/null
if [ $? -eq 0 ]; then
SIZE_AFTER=$(du -h "$DB" | cut -f1)
echo " -> $DB: Dioptimasi (Ukuran: $SIZE_BEFORE -> $SIZE_AFTER)"
else
echo " -> $DB: Gagal mengoptimasi"
fi
fi
done
# 7. Disk space summary
echo "๐ Penggunaan Disk saat ini:"
df -h / | tail -n 1 | awk '{print " -> Terpakai: "$3" / "$2" ("$5")"}'
echo "โ
[VPS Cleanup] Pembersihan sistem selesai!"