-
Notifications
You must be signed in to change notification settings - Fork 28
/
clean-backup.php
executable file
·72 lines (49 loc) · 1.36 KB
/
clean-backup.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
$nyear = date("Y");
$nmonth = date("m");
$nday = date("d");
$wdays = array('08', '15', '22', '29');
function check_date($date2check) {
global $nday, $nmonth, $nyear, $wdays;
/* make sure the string is right. should always be. */
if(strlen($date2check) != 8) {
return false;
}
/* get data.. should always be exact positions */
$year = substr($date2check, 0, 4);
$month = substr($date2check, 4, 2);
$day = substr($date2check, 6, 2);
/* drop anything not in this year (should already be done) */
if($year != $nyear) {
return false;
}
/* leave this month alone */
if($month === $nmonth) {
return false;
}
if($month < $nmonth) {
/* we'll always keep the first of every month */
if($day === '01'){
return false;
}
/* we keep weeklies for 3 months */
if(($month > ($nmonth-3)) && in_array($day, $wdays)){
return false;
}
/* we've filtered out what's to be kept */
return true;
}
/* return anything we don't know about */
return false;
}
if ($dir = @opendir("/local/backup")) {
while (($file = readdir($dir)) !== false && ($file != '.' || $file != '..')) {
$str = str_replace('mirrors.', '', $file);
$str = str_replace('repository.', '', $str);
$str = str_replace('.tar.bz2', '', $str);
if(check_date($str)){
`rm -f /local/backup/$file`;
}
}
closedir($dir);
}