Skip to content

Instantly share code, notes, and snippets.

@kkiernan
Last active March 4, 2024 19:19
Show Gist options
  • Save kkiernan/bdd0954d0149b89c372a to your computer and use it in GitHub Desktop.
Save kkiernan/bdd0954d0149b89c372a to your computer and use it in GitHub Desktop.
Laravel Artisan command that runs the mysqldump utility
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class MySqlDump extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'db:mysqldump {schema} {password}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Runs the mysqldump utility';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$ds = DIRECTORY_SEPARATOR;
$schema = $this->argument('schema');
$password = $this->argument('password');
$path = database_path() . $ds . 'backups' . $ds . date('Y') . $ds . date('m') . $ds;
$file = date('Y-m-d') . '_mysqldump.sql';
$command = sprintf('mysqldump %s -u forge -p\'%s\' > %s', $schema, $password, $path . $file);
if (!is_dir($path)) {
mkdir($path, 0755, true);
}
exec($command);
}
}
@privyreza
Copy link

Its not an error, just a warning, but the dump will succeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment