-
Notifications
You must be signed in to change notification settings - Fork 54
/
cleanup.php
38 lines (30 loc) · 1.33 KB
/
cleanup.php
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
31
32
33
34
35
36
37
38
<?php
include("clobberer_creds.php");
// disallow unless the correct token is given
if (getenv('CLEANUP_PASSWORD') != $CLEANUP_PASSWORD) {
echo "wrong CLEANUP_PASSWORD\n";
exit(1);
}
$dbh = new PDO($CLOBBERER_DSN, $CLOBBERER_USERNAME,
$CLOBBERER_PASSWORD, $CLOBBERER_PDO_OPTIONS);
if (!$dbh) {
print("Error: couldn't connect\n");
print($error);
exit(1);
}
header("Content-type: text/plain");
if (substr($CLOBBERER_DSN, 0, 5) == 'mysql') {
$q = "delete from builds where last_build_time < unix_timestamp(adddate(now(), interval -21 day)) and buildername not like 'rel%'";
$dbh->exec($q) === false and die(print_r($dbh->errorInfo(), TRUE));
$q = "delete from clobber_times where lastclobber < unix_timestamp(adddate(now(), interval -21 day))";
$dbh->exec($q) === false and die(print_r($dbh->errorInfo(), TRUE));
// optimize table? Only reclaims table space, so probably not helpful..
} else {
// sqlite
$q = "delete from builds where last_build_time < strftime('%s', 'now', '-21 days') and buildername not like 'rel%'";
$dbh->exec($q) === false and die(print_r($dbh->errorInfo(), TRUE));
$q = "delete from clobber_times where lastclobber < strftime('%s', 'now', '-21 days')";
$dbh->exec($q) === false and die(print_r($dbh->errorInfo(), TRUE));
$q = "vacuum";
$dbh->exec($q) === false and die(print_r($dbh->errorInfo(), TRUE));
}