Backup your laravel database by a simple artisan command

Overview

Backup your laravel database by a simple artisan command

GitHub Tests Action Status GitHub Code Style Action Status Total Downloads Latest Stable Version License

This package will allow you to backup your laravel app database and you can also choose to send the backup file via email by simply running the command php artisan database:backup

Supported Databases

  • Mysql
  • Postgresql
  • sqlite

Installation

You can install the package via composer:

composer require mhmdomer/laravel-database-backup

You can publish the config file with:

php artisan vendor:publish --tag=database-backup

You can configure the maximum_backup_files and whether to send an email when a backup occurs as well as specifying the email to send the backup file to

This is the contents of the published config file:

[ /* |------------------------------------------------------------------------- | Send Mail |------------------------------------------------------------------------- | Specify if an email with the backup file attached should | be sent when creating a backup. */ 'send' => env('DB_BACKUP_SEND_MAIL', false), /* |------------------------------------------------------------------------- | Backup Mail |------------------------------------------------------------------------- | Specify the email that should receive the backup file. */ 'to' => env('DB_BACKUP_EMAIL', '[email protected]') ] ]; ">
return [

    /*
    |-------------------------------------------------------------------------
    | Backup Folder
    |-------------------------------------------------------------------------
    |
    | The path of the folder to save backups on and retrieve backups from.
    */

    'backup_folder' => storage_path('app/backup'),

    /*
    |-------------------------------------------------------------------------
    | Maximum Backup Files
    |-------------------------------------------------------------------------
    |
    | The maximum number of files that should be present inside the backup folder,
    | each new backup after this limit will result in removing the oldest backup file
    */

    'maximum_backup_files' => 10,

    /*
    |-------------------------------------------------------------------------
    | Mail Settings
    |-------------------------------------------------------------------------
    | Email configuration for backups.
    */

    "mail" => [

        /*
        |-------------------------------------------------------------------------
        | Send Mail
        |-------------------------------------------------------------------------
        | Specify if an email with the backup file attached should
        | be sent when creating a backup.
        */

        'send' => env('DB_BACKUP_SEND_MAIL', false),

        /*
        |-------------------------------------------------------------------------
        | Backup Mail
        |-------------------------------------------------------------------------
        | Specify the email that should receive the backup file.
        */

        'to' => env('DB_BACKUP_EMAIL', '[email protected]')
    ]
];

Usage

To create a backup of your database you can run:

php artisan database:backup

The above command is typically run as a schedule command, for example, you can add the following line in the schedule function inside app\Console\Kernel.php

$schedule->command('database:backup')->daily();

To disable sending a backup email you can add --no-mail option:

php artisan database:backup --no-mail

To get the latest backup file:

DatabaseBackup::getLatestBackupFile();

To get all backup files:

DatabaseBackup::getBackupFiles();

To download the latest backup file:

$backupFile = DatabaseBackup::getLatestBackupFile();
return response()->download($backupFile);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

You might also like...
This command will guide you through upgrade your composer.json config rom version 1 to version 2.

Upgrade composer.json This command will guide you through upgrade your composer.json config rom version 1 to version 2. How to use: $ cd YOUR_PROJECT_

Extendable Interactive Make Command for Laravel
Extendable Interactive Make Command for Laravel

Extendable Interactive Make Command for Laravel Make your life easier with interactive make command! Installation composer require hydreflab/laravel-m

Lovely PHP wrapper for using the command-line

ShellWrap What is it? It's a beautiful way to use powerful Linux/Unix tools in PHP. Easily and logically pipe commands together, capture errors as PHP

A PHP library for command-line argument processing

GetOpt.PHP GetOpt.PHP is a library for command-line argument processing. It supports PHP version 5.4 and above. Releases For an overview of the releas

🖥 PHP CLI application library, provide console argument parse, console controller/command run, color style, user interactive, format information show and more.  功能全面的PHP命令行应用库。提供控制台参数解析, 命令运行,颜色风格输出, 用户信息交互, 特殊格式信息显示
Command-Line Interface tools

Aura.Cli Provides the equivalent of request ( Context ) and response ( Stdio ) objects for the command line interface, including Getopt support, and a

Another Command Line Argument Parser

Optparse — Another Command Line Argument Parser Install 1. Get composer. 2. Put this into your local composer.json: { "require": { "chh/optparse

Twitter raffles in the command line, with PHP and minicli
Twitter raffles in the command line, with PHP and minicli

Rafflebird Rafflebird is a highly experimental CLI application for giveaways / raffles on Twitter, built in PHP with Minicli. Disclaimer: The recent s

A command line code generator for Drupal.

Drupal Code Generator A command line code generator for Drupal. Installation Download the latest stable release of the code generator.

Releases(v0.3.4)
Owner
Mohammed Omer
Mohammed Omer
A powerful command line application framework for PHP. It's an extensible, flexible component, You can build your command-based application in seconds!

CLIFramework CLIFramework is a command-line application framework, for building flexiable, simple command-line applications. Commands and Subcommands

Yo-An Lin 428 Dec 13, 2022
Simple but yet powerful library for running almost all artisan commands.

:artisan gui Simple but yet powerful library for running some artisan commands. Requirements Laravel 8.* php ^7.3 Installation Just install package: c

null 324 Dec 28, 2022
Customized loading ⌛ spinner for Laravel Artisan Console.

Laravel Console Spinner Laravel Console Spinner was created by Rahul Dey. It is just a custom Progress Bar inspired by icanhazstring/symfony-console-s

Rahul Dey 71 Oct 26, 2022
Handle signals in artisan commands

Using this package you can easily handle signals like SIGINT, SIGTERM in your Laravel app.

Spatie 96 Dec 29, 2022
A simple command-line tool whose aim is to facilitate the continous delivery of PHP apps

Deployer Simple command-line tool that aims to facilitate the continous delivery of PHP apps, particularly Laravel apps. Imagine you want to update yo

Fernando Bevilacqua 4 Sep 8, 2021
Simple command-line tool to access HiWeb account information

Simple command-line tool to access HiWeb account information.

Milad Nekofar 2 Dec 26, 2022
👨🏻‍🚀 A command-line tool that gives you the Alpine Day 2021 schedule in your timezone. 🚀

Alpine Day Schedule a command-line tool that gives you the Alpine Day 2021 schedule in your timezone. ?? Quick start Requires PHP 7.4+ # First, instal

Nuno Maduro 11 Jun 10, 2021
PHP Interminal is a command-line tool that gives you access to PHP Internals discussions in your terminal.

PHP Interminal is a command-line tool that gives you access to PHP Internals discussions in your terminal. ??

Nuno Maduro 32 Dec 26, 2022
Patrol is an elegant command-line tool that keeps your PHP Project's dependencies in check.

Patrol is an elegant command-line tool that keeps your PHP Project's dependencies in check. Installation / Usage Requires PHP 8.0+ First, install Patr

Nuno Maduro 237 Nov 14, 2022
Laracon Schedule a command-line tool that gives you the Laracon Online schedule in your timezone.

Laracon Schedule a command-line tool that gives you the Laracon Online schedule in your timezone. ?? Quick start Requires PHP 7.4+ # First, install: c

Nuno Maduro 101 Sep 16, 2022