Sahandi81
2 سال پیش توسط Sahandi81 مطرح شد
1 پاسخ

بک آپ دیتابیس

سلام.
یه دیتابیس داریم با نزدیک 50-60 تا فانکشن. موقع بکاپ گرفتن هم از طریق کامند لاین و هم از طریق نرم افزار navicat تعدادی از فانکشنا بک اپ گرفته نمیشه.
چیکار میشه کرد ؟


ثبت پرسش جدید
میلاد خسروی
تخصص : برنامه نویس بامزه
@milwad 2 سال پیش مطرح شد
0

سلام خسته نباشید
خب ببین میتونی یه کامنددرست کنی

php artisan make:command DatabaseBackUp

بعد درونش این کارو انجام بدی

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Carbon\Carbon;

class DatabaseBackUp extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'database:backup';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $filename = "backup-" . Carbon::now()->format('Y-m-d') . ".gz";

        $command = "mysqldump --user=" . env('DB_USERNAME') ." --password=" . env('DB_PASSWORD') . " --host=" . env('DB_HOST') . " " . env('DB_DATABASE') . "  | gzip > " . storage_path() . "/app/backup/" . $filename;

        $returnVar = NULL;
        $output  = NULL;

        exec($command, $output, $returnVar);
    }
}

توی مسیر storage/app/backup یه پوشه بساز
بعد توی فایل kernel.php بیا یه schedule ران کن

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        'App\Console\Commands\DatabaseBackUp'
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('database:backup')->daily();
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

و کامند php artisan database:backup بزن


برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام