[a-z0-9]{8}) +(?\d{4})-(?\d{2})-(?\d{2}) +(?\d{2}):+(?\d{2}):+(?\d{2}) +(?[^ ]+) +(?[^ ]+).*/", $snapshot, $m ) ) { continue; } $backupName = $m["host"] . "|" . $m["path"]; if (!isset($backups[$backupName])) { $backups[$backupName] = 0; } $backupTime = mktime( $m["hour"], $m["minute"], $m["second"], $m["month"], $m["day"], $m["year"] ); if ($backupTime > $backups[$backupName]) { $backups[$backupName] = $backupTime; } } ksort($backups); file_put_contents( "/var/www/data/backups.json", json_encode($backups, JSON_UNESCAPED_SLASHES + JSON_PRETTY_PRINT) ); exit(); } header("Content-Type: text/plain"); $maxAge = isset($_GET["maxage"]) ? intval($_GET["maxage"]) : 28; $maxAge = $maxAge * 60 * 60; $backups = json_decode(file_get_contents("/var/www/data/backups.json"), true); foreach ($backups as $backupName => $backupTime) { echo "BACKUP|$backupName|"; if ($backupTime + $maxAge < time()) { echo "TOO_OLD"; } else { echo "OK"; } echo "\n"; }