create cron for backing up db

This commit is contained in:
2025-09-24 14:42:46 +03:30
parent c43909574e
commit fadc8379d9
7 changed files with 69 additions and 3 deletions

View File

@@ -90,3 +90,7 @@ HARIM_EDIT_ACCESS_USERNAME=
HARIM_NEED_GUARANTEE_LETTER_URL=
HARIM_NEED_GUARANTEE_LETTER_PASSWORD=
HARIM_NEED_GUARANTEE_LETTER_USERNAME=
BACKUP_TARGET_DIR=
BACKUP_USER=
BACKUP_PASSWORD=

View 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');
}
}

View File

@@ -39,6 +39,9 @@ class Kernel extends ConsoleKernel
$schedule->command("webservice:roadobserved --daily-mode")
->dailyAt('00:45')->appendOutputTo(storage_path('logs/nikarayan.log'));
$schedule->command("db:backup")
->weekly()->at('03:00')->appendOutputTo(storage_path('logs/mariadb-backup.log'));
}
/**

View File

@@ -26,7 +26,7 @@ class Mission extends Model
protected function area(): Attribute
{
return Attribute::make(
get: fn($value) => json_decode($value)
get: fn($value) => json_decode($value, true)
);
}

View File

@@ -23,7 +23,7 @@ class PaymentService
'type' => 1,
'instanceid' => 123,
'ownerid' => $driver_national_code,
'calculationBox' => "{\"rows\":[{\"amount\":" . $final_amount . ",\"code\":\"7070021060000015\"}]}"
'calculationBox' => "{\"rows\":[{\"amount\":" . $final_amount . ",\"code\":\"7070011026200593\"}]}"
);
$ch = curl_init();

View File

@@ -2,4 +2,7 @@
return [
'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'),
];

View File

@@ -135,6 +135,11 @@ return [
'path' => storage_path('logs/fms/error_rate_service.log'),
'level' => 'info',
],
],
'mariadb-backup' => [
'driver' => 'single',
'path' => storage_path('logs/mariadb-backup.log'),
'level' => 'info',
],
],
];