test db backup
This commit is contained in:
parent
ba495c3d08
commit
bc7b9f2319
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue