test db backup

This commit is contained in:
saparatayev 2022-03-29 16:16:19 +05:00
parent ba495c3d08
commit bc7b9f2319
1 changed files with 35 additions and 0 deletions

View File

@ -2,6 +2,7 @@
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
@ -29,6 +30,40 @@ class DatabaseBackUp extends Command
$returnVar = NULL;
$output = NULL;
$path = storage_path() . "/app/backup/";
$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));
if($date->greaterThan($max_date)) {
$max_date = $date;
// $max_date_key = $key;
}
if($date->lessThan($min_date)) {
$min_date = $date;
$min_date_key = $key;
}
}
// info("{$max_date_key} => {$max_date}");
// info("{$min_date_key} => {$min_date}");
// info("{$min_date->diffInMinutes($max_date)}");
if($min_date->diffInMinutes($max_date) > 300) {
Storage::delete("backup/{$files[$min_date_key]}");
}
exec($command, $output, $returnVar);
}