luiz-albertoni/dynamic-mysql-db-backup

Dynamic save mysql dumps to your specific Storage

dev-master 2018-09-07 13:42 UTC

This package is auto-updated.

Last update: 2024-11-12 05:17:48 UTC


README

Overview

The DynamicMysqlDatabaseBackup is a Laravel package to dynamically take a dump from your Mysql database and storage to a filesystem (local filesystems, Amazon S3, and Rackspace Cloud Storage). It also allow the user to configurate which environment (local, dev, stage, prod) it should take a dump, permit the user storage the dump compressing to Zip format and the user is able to configure how many days the dump file should remain in the storage, so it dynamically storage and remove the backup files through Laravel's Scheduler.

Install

Composer install

composer require luiz-albertoni/dynamic-mysql-db-backup

Edit app/config/app.php to add the DynamicMysqlDumpServiceProvider under the 'providers' Array

Albertoni\DynamicMysqlDataBaseBackup\DynamicMysqlDumpServiceProvider::class,

Publish the configuration

php artisan vendor:publish --provider="Albertoni\DynamicMysqlDataBaseBackup\DynamicMysqlDumpServiceProvider" --tag='config' --force

Set Scheduler to run the package. Add the code below in App\Console\Kernel inside the schedule method.

 $schedule->call(function () {
            DynamicMysqlFacade::runDump();
        })->daily();

Configuration File

Config file name : dynamic-mysql-dump.php

<?php
return [
    /*
    |--------------------------------------------------------------------------
    | Dynamic Mysql Dump Configuration
    |--------------------------------------------------------------------------
    */

    'store_days' => 5,

    'specific_storage_type' => 'local',

    'specific_storage_path' => '',
    
    'use_zip' =>  true,

    'use_for_app_env' =>  ['local', 'dev', 'prod'],
];

What means each configuration var?

  • store_days : Number of days which we want to hold the dump file. Default value = 5

  • specific_storage_type: Which filesystem we are using for storage teh dump file. Default value = local

  • specific_storage_path: Specific path that we want to store the dump file in our filesystem. Default value = ''

  • use_zip: Signal to inform if it should be compress to the Zip format

  • use_for_app_env: Specific under which enviroment the package should take a dump

Dependencies

To use this package we are assuming:

  • The application is using the Laravel Framework
  • The application has a Mysql database installed
  • The application is using one FileSystem ( https://laravel.com/docs/5.4/filesystem )
  • The keys below exist in the .env file: DB_PASSWORD, DB_USERNAME, DB_DRIVER, DB_HOST, DB_DATABASE.

Advices

In the Scheduler Class do not forget to:

To do

  • Create a command to run the scheduler, beside use the Facade
  • Expand this code to handle different databases;