Open Source Database Backup package with Laravel

Words
207
Reading
1 min
Listen
Play
9y

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::class to the providers array of your app.php file.
  • Run php artisan vendor:publish --provider="therealsmat\PushDB\PushDBServiceProvider". You should get a pushdb.php file in your config directory. You can change the defaults if you wish. Also you get a new command db:push automatically. Run php artisan list to 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 run php artisan db:push and your database will be placed in the path you set from the pushdb.php output_path option. 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

Open Source Database Backup package with Laravel | Ecency