UniFi уменьшить размер БД
/var/lib/unifi/prune.js
// keep N-day worth of data
days=30;
dryrun=true;
use ace;
collectionNames = db.getCollectionNames();
for (i=0; i < collectionNames.length; i++) {
name = collectionNames[i];
query = null;
if (name.indexOf('stat')==0 || name.indexOf('event')==0 || name.indexOf('alarm')==0) {
query = {time: {$lt:new Date().getTime()-days*86400*1000}};
}
if (name.indexOf('session')==0) {
query = {assoc_time: {$lt:new Date().getTime()/1000-days*86400}};
}
if (name.indexOf('user')==0) {
query = {last_seen: {$lt:new Date().getTime()/1000-days*86400}};
}
if (query) {
count = db.getCollection(name).find(query).count();
print((dryrun ? "[dryrun] " : "") + "pruning " + count + " entries from " + name + "... ");
if (!dryrun)
db.getCollection(name).remove(query);
}
}
if (!dryrun) db.repairDatabase();
Запускаем:
Для отработки скрипта рисуем dryrun=false;
Запускаем. Ответ содержит:
{
"errmsg" : "Cannot repair database ace having size: 1023410176 (bytes) because free disk space is: 325328896 (bytes)",
"ok" : 0
}
bye
Сжать базу хотели менно для увеличения свободного места на диске. Увеличил раздел. Выполняем:
root@v17:~# df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 11G 6.1G 4.1G 61% /
udev 10M 0 10M 0% /dev
tmpfs 50M 232K 50M 1% /run
/dev/disk/by-uuid/21f7510b-f6a9-470b-bde9-58b22866dbef 11G 6.1G 4.1G 61% /
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 336M 0 336M 0% /run/shm
root@v17:~# mongo --port=27117 < /var/lib/unifi/prune.js
MongoDB shell version: 2.0.6
connecting to: 127.0.0.1:27117/test
30
false
switched to db ace
[
"admin",
"alarm",
"alarmdef",
"cache_device",
"cache_login",
"cache_scan",
"cache_sta",
"cache_stat",
"device",
"event",
"guest",
"map",
"map.chunks",
"map.files",
"payment",
"privilege",
"rogue",
"session",
"setting",
"site",
"stat_current",
"stat_daily",
"stat_hourly",
"stat_life",
"stat_minute",
"stat_monthly",
"system.indexes",
"task",
"user",
"usergroup",
"verification",
"voucher",
"wlanconf",
"wlangroup"
]
pruning 0 entries from alarm...
pruning 0 entries from alarmdef...
pruning 0 entries from event...
pruning 5 entries from session...
pruning 0 entries from stat_current...
pruning 0 entries from stat_daily...
pruning 10 entries from stat_hourly...
pruning 0 entries from stat_life...
pruning 0 entries from stat_minute...
pruning 0 entries from stat_monthly...
pruning 0 entries from user...
pruning 0 entries from usergroup...
null
{ "ok" : 1 }
bye
root@v17:~# df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 11G 5.4G 4.8G 53% /
udev 10M 0 10M 0% /dev
tmpfs 50M 232K 50M 1% /run
/dev/disk/by-uuid/21f7510b-f6a9-470b-bde9-58b22866dbef 11G 5.4G 4.8G 53% /
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 336M 0 336M 0% /run/shm
root@v17:~# du -hs /var/lib/unifi/db
2.3G /var/lib/unifi/db
То есть очистка базы дала 700 MB. Не густо.