create cron for backing up db
This commit is contained in:
@@ -90,3 +90,7 @@ HARIM_EDIT_ACCESS_USERNAME=
|
|||||||
HARIM_NEED_GUARANTEE_LETTER_URL=
|
HARIM_NEED_GUARANTEE_LETTER_URL=
|
||||||
HARIM_NEED_GUARANTEE_LETTER_PASSWORD=
|
HARIM_NEED_GUARANTEE_LETTER_PASSWORD=
|
||||||
HARIM_NEED_GUARANTEE_LETTER_USERNAME=
|
HARIM_NEED_GUARANTEE_LETTER_USERNAME=
|
||||||
|
|
||||||
|
BACKUP_TARGET_DIR=
|
||||||
|
BACKUP_USER=
|
||||||
|
BACKUP_PASSWORD=
|
||||||
51
app/Console/Commands/BackupDatabaseCommand.php
Normal file
51
app/Console/Commands/BackupDatabaseCommand.php
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Support\Facades\Process;
|
||||||
|
|
||||||
|
class BackupDatabaseCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'db:backup';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'physical database backup';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*/
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
$path = config('global_variables.BACKUP_TARGET_DIR');
|
||||||
|
$user = config('global_variables.BACKUP_USER');
|
||||||
|
$password = config('global_variables.BACKUP_PASSWORD');
|
||||||
|
$time = date('Y-m-d');
|
||||||
|
|
||||||
|
$backup = Process::path($path)->forever()->run("sudo mariadb-backup --backup --target-dir={$path}/{$time} --user={$user} --password={$password}");
|
||||||
|
|
||||||
|
if ($backup->failed()) {
|
||||||
|
Log::channel('mariadb-backup')->info("Backup failed at {$time}");
|
||||||
|
}
|
||||||
|
|
||||||
|
$prepare = Process::path($path)->forever()->run("sudo mariadb-backup --prepare --target-dir={$path}/{$time}");
|
||||||
|
|
||||||
|
if ($prepare->failed()) {
|
||||||
|
Log::channel('mariadb-backup')->info("Preparation failed at {$time}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::channel('mariadb-backup')->info("Backup successful at {$time}");
|
||||||
|
|
||||||
|
$this->info('done');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,6 +39,9 @@ class Kernel extends ConsoleKernel
|
|||||||
|
|
||||||
$schedule->command("webservice:roadobserved --daily-mode")
|
$schedule->command("webservice:roadobserved --daily-mode")
|
||||||
->dailyAt('00:45')->appendOutputTo(storage_path('logs/nikarayan.log'));
|
->dailyAt('00:45')->appendOutputTo(storage_path('logs/nikarayan.log'));
|
||||||
|
|
||||||
|
$schedule->command("db:backup")
|
||||||
|
->weekly()->at('03:00')->appendOutputTo(storage_path('logs/mariadb-backup.log'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class Mission extends Model
|
|||||||
protected function area(): Attribute
|
protected function area(): Attribute
|
||||||
{
|
{
|
||||||
return Attribute::make(
|
return Attribute::make(
|
||||||
get: fn($value) => json_decode($value)
|
get: fn($value) => json_decode($value, true)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class PaymentService
|
|||||||
'type' => 1,
|
'type' => 1,
|
||||||
'instanceid' => 123,
|
'instanceid' => 123,
|
||||||
'ownerid' => $driver_national_code,
|
'ownerid' => $driver_national_code,
|
||||||
'calculationBox' => "{\"rows\":[{\"amount\":" . $final_amount . ",\"code\":\"7070021060000015\"}]}"
|
'calculationBox' => "{\"rows\":[{\"amount\":" . $final_amount . ",\"code\":\"7070011026200593\"}]}"
|
||||||
);
|
);
|
||||||
|
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
|
|||||||
@@ -2,4 +2,7 @@
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'IS_DEVELOPMENT_ENV' => env('IS_DEVELOPMENT_ENV', false),
|
'IS_DEVELOPMENT_ENV' => env('IS_DEVELOPMENT_ENV', false),
|
||||||
|
"BACKUP_TARGET_DIR" => env('BACKUP_TARGET_DIR'),
|
||||||
|
"BACKUP_USER" => env('BACKUP_USER'),
|
||||||
|
"BACKUP_PASSWORD" => env('BACKUP_PASSWORD'),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -135,6 +135,11 @@ return [
|
|||||||
'path' => storage_path('logs/fms/error_rate_service.log'),
|
'path' => storage_path('logs/fms/error_rate_service.log'),
|
||||||
'level' => 'info',
|
'level' => 'info',
|
||||||
],
|
],
|
||||||
],
|
|
||||||
|
|
||||||
|
'mariadb-backup' => [
|
||||||
|
'driver' => 'single',
|
||||||
|
'path' => storage_path('logs/mariadb-backup.log'),
|
||||||
|
'level' => 'info',
|
||||||
|
],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user