Skip to content

enderlinp/CodeIgniter4-Mysqldump-Commands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CodeIgniter4 Mysqldump Commands

Mysqldump Spark Commands (CLI) for CodeIgniter 4.

Installation

Copy Mysqldump.php to your CodeIgniter4 app/Commands directory.

Requirements

Install ifsnop/mysqldump-php library with composer, like so:

> composer require ifsnop/mysqldump-php

Usage

Perform a backup of your MySQL default database (MySQLi driver only) and store the backup file within your "{WRITEPATH}/sql" directory. Prompt the user to create it if it does not exist.

The backup file name format is dbname_Ymd_His.sql or dbname_Ymd_His.sql.gz with Gzip compression enabled (see below).

View the ifsnop/mysqldump-php documentation for more information.

Command Line (CLI)

Regular usage via command line is:

> php spark db:mysqldump

Available options are:

  • --c: Enable Gzip compression
  • --d: Add DROP TABLE statements
  • --i: Ignore all tables
  • --r: Reset AUTO_INCREMENT statements
  • --u: Set default character set to UTF8MB4

To compress (Gzip) the backup file, use:

> php spark db:mysqldump --c

To add DROP TABLE statements to the backup file, use:

> php spark db:mysqldump --d

To ignore all tables and remove AUTO_INCREMENT statements (equivalent to a TRUNCATE statement), use:

> php spark db:mysqldump --i --r

Running Commands (Controller)

Like any other spark command, you may use it within your controller with the command() function, like so:

<?php
// Database `ci4` successfully backup.
echo command('db:mysqldump');

or:

<?php
// Database `ci4` successfully backup.
$message = command('db:mysqldump --c');

return redirect()->back()->with('message', $message);

See the Running Commands section from CodeIgniter 4 documentation for more information.

License

Released under the MIT License.

About

Mysqldump Spark Commands (CLI) for CodeIgniter 4

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages