Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
aports
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael Pirogov
aports
Commits
bd3340f2
Commit
bd3340f2
authored
6 years ago
by
Leonardo Arena
Browse files
Options
Downloads
Patches
Plain Diff
non-free/unifi: add DB cron job
(disabled by default)
parent
a31b8a8b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
non-free/unifi/APKBUILD
+10
-2
10 additions, 2 deletions
non-free/unifi/APKBUILD
non-free/unifi/mongo_prune.js
+87
-0
87 additions, 0 deletions
non-free/unifi/mongo_prune.js
non-free/unifi/unifi_db_prune.cron
+2
-0
2 additions, 0 deletions
non-free/unifi/unifi_db_prune.cron
with
99 additions
and
2 deletions
non-free/unifi/APKBUILD
+
10
−
2
View file @
bd3340f2
...
...
@@ -4,7 +4,7 @@ pkgname=unifi
_pkgname
=
UniFi
pkgver
=
5.8.23
_pkgver
=
d5a5bbfda4
pkgrel
=
0
pkgrel
=
1
pkgdesc
=
"The Ubiquiti UniFi network controller"
url
=
"http://wiki.ubnt.com/UniFi_FAQ"
arch
=
"noarch"
...
...
@@ -19,6 +19,8 @@ source="$pkgname-$pkgver.zip::https://dl.ubnt.com/unifi/$pkgver-$_pkgver/$_pkgna
$pkgname
.initd
$pkgname
.confd
$pkgname
.logrotated
mongo_prune.js
unifi_db_prune.cron
"
builddir
=
"
$srcdir
/
$_pkgname
"
...
...
@@ -79,9 +81,15 @@ package() {
# tell search engines to do not index
echo
-e
"User-Agent:*
\n
Disallow:/"
>
"
$webapps
"
/
$pkgname
/ROOT/robots.txt
# install purging DB job (disabled by default)
install
-Dm644
"
$srcdir
"
/mongo_prune.js
"
$pkgdir
"
/etc/unifi/mongo_prune.js
install
-Dm755
"
$srcdir
"
/unifi_db_prune.cron
"
$pkgdir
"
/etc/periodic/weekly/unifi_db_prune
}
sha512sums
=
"2b42df2a84574ac9e282c7ff59eb86ce29170ea7ef5957690dec8772c90acda3c08c633b3bceeac08bb73ff1460143207a64d2405de19436faf20a042849231b unifi-5.8.23.zip
b19a7d684ef2ec7c4159417c21185ccd8ce498da25405b69014fdb32e346a0077f7edc5dfc994481d12936aa8dbf22e6baf29571fd0003aaad19609d24c549f4 unifi.initd
d339555a91de7488badbedf8a4c85cff878e7d0720a8cf6a8340f51f3666dcf4878b47a1fff4c9c2846d7af140d11e48e898f8c4dba1f81c1004b76a81f0821e unifi.confd
9e54d9e1c720b8e50c9af9363105f6ea9ff2cffff7dc67477a7701aacf21ba977424fe9fbaba6a00d5f64310a2e2517e9328a7acb91a4bc06ed237139a8e0d9b unifi.logrotated"
9e54d9e1c720b8e50c9af9363105f6ea9ff2cffff7dc67477a7701aacf21ba977424fe9fbaba6a00d5f64310a2e2517e9328a7acb91a4bc06ed237139a8e0d9b unifi.logrotated
3eec528077af9b32aa065610b4ffc50537a1c851c84624eaa63287787d853c0f8c953a97bd58bc6c2cab7f9f26eaff8c8b2815a84454169f7e0d96b94dfc91ee mongo_prune.js
25d66b144403676bcb6142f4942b62c6f969a6b359ccb4dd4fcb826b1e57f902179d01182369704970b2d6094b8b3789fd375c17cec908cac53f7abf01fb2e1b unifi_db_prune.cron"
This diff is collapsed.
Click to expand it.
non-free/unifi/mongo_prune.js
0 → 100644
+
87
−
0
View file @
bd3340f2
// keep N-day worth of data
var
days
=
14
;
// change to false to have the script to really exclude old records
// from the database. While true, no change at all will be made to the DB
var
dryrun
=
true
;
var
now
=
new
Date
().
getTime
(),
time_criteria
=
now
-
days
*
86400
*
1000
,
time_criteria_in_seconds
=
time_criteria
/
1000
;
print
((
dryrun
?
"
[dryrun]
"
:
""
)
+
"
pruning data older than
"
+
days
+
"
days (
"
+
time_criteria
+
"
)...
"
);
use
ace
;
var
collectionNames
=
db
.
getCollectionNames
();
for
(
i
=
0
;
i
<
collectionNames
.
length
;
i
++
)
{
var
name
=
collectionNames
[
i
];
var
query
=
null
;
if
(
name
===
'
event
'
||
name
===
'
alarm
'
)
{
query
=
{
time
:
{
$lt
:
time_criteria
}};
}
// rogue ap
if
(
name
===
'
rogue
'
)
{
query
=
{
last_seen
:
{
$lt
:
time_criteria_in_seconds
}};
}
// removes vouchers expired more than '$days' ago
// active and unused vouchers are NOT touched
if
(
name
===
'
voucher
'
)
{
query
=
{
end_time
:
{
$lt
:
time_criteria_in_seconds
}};
}
// guest authorization
if
(
name
===
'
guest
'
)
{
query
=
{
end
:
{
$lt
:
time_criteria_in_seconds
}};
}
// if an user was only seen ONCE, $last_seen will not be defined
// so, if $last_seen not defined, lets use $first_seen instead
// also check if $blocked or $use_fixedip is set. If true, do NOT purge the
// entry no matter how old it is. We want blocked/fixed_ip users to continue
// blocked/fixed_ip
if
(
name
===
'
user
'
)
{
query
=
{
blocked
:
{
$ne
:
true
},
use_fixedip
:
{
$ne
:
true
},
$or
:
[
{
last_seen
:
{
$lt
:
time_criteria_in_seconds
}
},
{
last_seen
:
{
$exists
:
false
},
first_seen
:
{
$lt
:
time_criteria_in_seconds
}
}
]
};
}
if
(
query
)
{
count1
=
db
.
getCollection
(
name
).
count
();
count2
=
db
.
getCollection
(
name
).
find
(
query
).
count
();
print
((
dryrun
?
"
[dryrun]
"
:
""
)
+
"
pruning
"
+
count2
+
"
entries (total
"
+
count1
+
"
) from
"
+
name
+
"
...
"
);
if
(
!
dryrun
)
{
db
.
getCollection
(
name
).
remove
(
query
);
db
.
runCommand
({
compact
:
name
});
}
}
}
use
ace_stat
;
var
collectionNames
=
db
.
getCollectionNames
();
for
(
i
=
0
;
i
<
collectionNames
.
length
;
i
++
)
{
var
name
=
collectionNames
[
i
];
var
query
=
null
;
// historical stats (stat.*)
if
(
name
.
indexOf
(
'
stat
'
)
==
0
)
{
query
=
{
time
:
{
$lt
:
time_criteria
}};
}
if
(
query
)
{
count1
=
db
.
getCollection
(
name
).
count
();
count2
=
db
.
getCollection
(
name
).
find
(
query
).
count
();
print
((
dryrun
?
"
[dryrun]
"
:
""
)
+
"
pruning
"
+
count2
+
"
entries (total
"
+
count1
+
"
) from
"
+
name
+
"
...
"
);
if
(
!
dryrun
)
{
db
.
getCollection
(
name
).
remove
(
query
);
db
.
runCommand
({
compact
:
name
});
}
}
}
if
(
!
dryrun
)
db
.
repairDatabase
();
This diff is collapsed.
Click to expand it.
non-free/unifi/unifi_db_prune.cron
0 → 100755
+
2
−
0
View file @
bd3340f2
#!/bin/sh
mongo
--port
27117 < /etc/unifi/mongo_prune.js
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment