Laravel Push DB
This package allows you to easily export your database. It also provides an artisan command,php artisan db:push to make the process simpler. You can either run manually from the console or use with Laravel scheduler. It's totally a matter of choice.
I built it to ease the task of having to backup your mysql database from your laravel application.
To setup this package
- Run
composer require therealsmat/laravel-push-db - Add
therealsmat\PushDB\PushDBServiceProvider::classto the providers array of yourapp.phpfile. - Run
php artisan vendor:publish --provider="therealsmat\PushDB\PushDBServiceProvider". You should get apushdb.phpfile in yourconfigdirectory. You can change the defaults if you wish. Also you get a new commanddb:pushautomatically. Runphp artisan listto view all available commands.
You can use this package in two ways.
- Controller
public function export(PushDB $db)
{
try{
if ($db->export()) {
return 'Database Export Successful';
}
return 'Database export not successful';
} catch (ProcessFailedException $e)
{
return $e->getMessage();
} catch (\Exception $e)
{
return $e->getMessage();
}
}
- Command
Simply runphp artisan db:pushand your database will be placed in the path you set from the pushdb.phpoutput_pathoption. As simple as this command is, it can be used in several ways.
Programmatically
Artisan::call('db:push');
Optionally, Storage::disk('s3')->put('Database.sql', config('pushdb.output_path'));
Of course, you must have set up your s3 disk from the filesystems.php file.
Schedule (Automatically)
You can schedule (1) above to run automatically using Laravel Scheduler e.g
$schedule->command('db:push --force')->daily();
The package was built using laravel and is intended to work with mysql databases (for now). It uses symfony's process component to execute a mysql command.
Roadmap
In the future, i plan to
- Include support for other databases
- Implement push to cloud storage feature e.g push to Dropbox, google drive e.t.c.
How to contribute?
- Clone the repository
- Create a new branch
- Send a Pull Request with the new features
- You can send me a mail @tosinsoremekun.com
Github Link
https://github.com/therealSMAT/laravel-push-db
Posted on Utopian.io - Rewarding Open Source Contributors