delete more files if their number exceeds the definite value
This commit is contained in:
parent
b92d3c961d
commit
039e29d243
|
|
@ -33,37 +33,41 @@ class DatabaseBackUp extends Command
|
|||
|
||||
$path = storage_path() . "/app/backup/";
|
||||
|
||||
$minutes = 5;
|
||||
|
||||
$files = array_diff(scandir($path), array('..', '.'));
|
||||
|
||||
// info($files);
|
||||
|
||||
$max_date = $min_date = Carbon::createFromTimestamp(Storage::lastModified('backup/' . reset($files)));
|
||||
$min_date_key = key($files);
|
||||
// $max_date_key = $min_date_key = key($files);
|
||||
|
||||
foreach ($files as $key => $file) {
|
||||
|
||||
$date = Carbon::createFromTimestamp(Storage::lastModified('backup/' . $file));
|
||||
while(count($files) > $minutes) {
|
||||
|
||||
if($date->greaterThan($max_date)) {
|
||||
$max_date = $date;
|
||||
// $max_date_key = $key;
|
||||
$max_date = $min_date = Carbon::createFromTimestamp(Storage::lastModified('backup/' . reset($files)));
|
||||
$min_date_key = key($files);
|
||||
|
||||
foreach ($files as $key => $file) {
|
||||
|
||||
$date = Carbon::createFromTimestamp(Storage::lastModified('backup/' . $file));
|
||||
|
||||
if($date->greaterThan($max_date)) {
|
||||
$max_date = $date;
|
||||
}
|
||||
|
||||
if($date->lessThan($min_date)) {
|
||||
$min_date = $date;
|
||||
$min_date_key = $key;
|
||||
}
|
||||
}
|
||||
|
||||
if($date->lessThan($min_date)) {
|
||||
$min_date = $date;
|
||||
$min_date_key = $key;
|
||||
if($min_date->diffInMinutes($max_date) > $minutes) {
|
||||
|
||||
Storage::delete("backup/{$files[$min_date_key]}");
|
||||
|
||||
unset($files[$min_date_key]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// info("{$max_date_key} => {$max_date}");
|
||||
// info("{$min_date_key} => {$min_date}");
|
||||
|
||||
// info("{$min_date->diffInMinutes($max_date)}");
|
||||
|
||||
if($min_date->diffInMinutes($max_date) > 5) {
|
||||
Storage::delete("backup/{$files[$min_date_key]}");
|
||||
}
|
||||
|
||||
|
||||
exec($command, $output, $returnVar);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue