AI Insights
Generate a summary and suggested tags for this post.
Kalau usaha WiFi jalan sebulan aja, list user hotspot bisa membengkak ribuan — kebanyakan sudah expired tapi masih ada di database. Router jadi berat, backup lama. Solusinya: auto-delete expired user pakai Scheduler + Script.

Kenapa Perlu Auto Cleanup?
| Masalah | Akibat |
|---|---|
| DB user membengkak | Backup config lambat |
| Scroll user manual | Susah nyari user aktif |
| Search jadi lemot | Query CLI berat |
| Router load naik | Response Winbox lambat |
Konsep Auto Cleanup
MikroTik tidak punya "auto-delete expired user" bawaan. Kita bikin sendiri dengan:
- Script → hapus user yang bytes-nya sudah habis / uptime sudah kelar
- Scheduler → jalankan script tersebut tiap jam / tiap hari

Script Hapus User Expired
Cara 1: Berdasarkan Bytes Habis
Kalau pakai limit-bytes-total (voucher paket kuota):
/system script
add name=hapus-expired source={
:foreach u in=[/ip hotspot user find] do={
:local limit [/ip hotspot user get $u limit-bytes-total];
:local used [/ip hotspot user get $u bytes-in];
:if (($limit > 0) && ($used >= $limit)) do={
/ip hotspot user remove $u
}
}
}Cara 2: Berdasarkan Waktu (Uptime)
Kalau pakai session-timeout (voucher paket waktu):
/system script
add name=hapus-expired-time source={
:foreach u in=[/ip hotspot user find where uptime>1d] do={
/ip hotspot user remove $u
}
}Cara 3: Berdasarkan Comment Tanggal
Cara paling reliable — beri comment tanggal saat generate voucher, hapus yang > 7 hari:
:foreach u in=[/ip hotspot user find comment~"batch-2024-01"] do={
/ip hotspot user remove $u
}Setup Scheduler Otomatis
Panggil script tiap 1 jam:
/system scheduler
add name=hapus-expired \
interval=1h \
on-event="/system script run hapus-expired" \
comment="Auto cleanup voucher expired"Atau tiap hari jam 3 pagi (jam sepi):
/system scheduler
add name=hapus-expired-daily \
start-time=03:00:00 \
interval=1d \
on-event="/system script run hapus-expired"Kombinasi: Cleanup + Backup
Sebelum hapus, backup dulu:
/system script
add name=cleanup-with-backup source={
/system backup save name=("bak-" . [/system clock get date]);
/system script run hapus-expired
}Tips Ekstra
| Tips | Detail |
|---|---|
| Notifikasi | Kirim log ke Telegram tiap cleanup |
| Batch per 100 user | Hindari lock DB kalau > 10.000 user |
| Log ke file | Simpan siapa saja yang dihapus |
| Jangan hapus active | Cek dulu hotspot active sebelum remove |
Common Mistake
| Kesalahan | Akibat | Solusi |
|---|---|---|
| Hapus user yg lagi login | Session terputus | Filter yg aktif via active list |
| Interval terlalu sering (1m) | Router boros CPU | Cukup tiap 1 jam |
| Script tanpa test | Bisa hapus salah user | Test manual dulu, output ke log |
| Tanpa backup | Susah recovery kalau salah | Backup config sebelum cleanup |
Kesimpulan
Auto-cleanup voucher expired = Script filter user + Scheduler interval. Setup sekali, database hotspot kamu tetap bersih selamanya. Untuk monitoring apa yang dihapus, kombinasikan dengan artikel Cara Monitoring Pengguna Hotspot MikroTik.
