Recommend this page to a friend! |
Download .zip |
Info | Documentation | View files (19) | Download .zip | Reputation | Support forum (2) | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not enough user ratings | Total: 238 | All time: 7,957 This week: 198 |
Version | License | PHP version | Categories | |||
simple-backup 1.0.1 | Custom (specified... | 5 | PHP 5, Databases, System information |
Description | Author | |
This package can backup, download and restore a MySQL database. Recommendations PHP MySQL Database Synchronize |
<img src="/_docs/store_export.PNG"/><br/> A simple mysql database backup library for php. This library helps you backup your mysql database to a directory in your project or download it to your machine.
The library also allows you import or restore a database without stress. Follow the instructions below to get started.
Open your terminal or command prompt and type the below command:
composer require coderatio/simple-backup
SimpleBackup::start()
->setDbName('db_name')
->setDbUser('db_username')
->setDbPassword('db_password')
->includeOnly(['carts', 'houses', 'categories'])
->then()->storeAfterExportTo('backups')
->then()->getResponse();
SimpleBackup::start()
->setDbName('db_name')
->setDbUser('db_username')
->setDbPassword('db_password')
->excludeOnly(['users', 'posts'])
->then()->storeAfterExportTo('backups')
->then()->getResponse();
The export can be done in two ways. 1. Store in a directory 2. Download to your machine
To store the export in a directory, do this:
require 'vendor/autoload.php';
use Coderatio\SimpleBackup\SimpleBackup;
// Set the database to backup
$simpleBackup = SimpleBackup::setDatabase(['db_name', 'db_user', 'db_password', 'db_host'])
->storeAfterExportTo('pathtostore', 'file_name (optional)');
To get the stored file name, you can echo it out like this:
echo $simpleBackup->getExportedName();
You can also get the reponse by doing this:
/
* @return object
/
var_dump($simpleBackup->getResponse());
To download the export to your machine, do this:
require 'vendor/autoload.php';
use Coderatio\SimpleBackup\SimpleBackup;
// Set the database to backup
$simpleBackup = SimpleBackup::setDatabase(['db_name', 'db_user', 'db_password', 'db_host'])
->downloadAfterExport($file_name (optional));
If $file_name isn't provided, a random name will be generated for the download.
To add where clauses as you would do on SQL, you can do this before exporting:
<b>Note:</b> $tables
variable must be an associative array e.g
$tables = [
'users' => 'is_active = true'
];
$simpleBackup->setTableConditions(array $tables);
To limit how many rows to be included in your backup for a table, do this before exporting:
<b>Note:</b> Just like adding where clauses, the $tables
variable here must be an associative array. e.g
$tables = [
'users' => 50,
'posts' => 50
]
$simpleBackup->setTableLimitsOn(array $tables);
This package makes importing or restoring your mysql database easy. To import your database, do this:
require 'vendor/autoload.php';
use Coderatio\SimpleBackup\SimpleBackup;
// Set the database to backup
$simpleBackup = SimpleBackup::setDatabase(['db_name', 'db_user', 'db_password', 'db_host (optional)']])
->importFrom('pathtosql_file or sql_contents');
/
* You can then dump the response like this.
*
* @return object
/
var_dump($simpleBackup->getResponse());
<b>Note:</b> You can provide sql statements as the parameter. You may also overwrite the database configuration by passing it as second parameter to the importFrom(). e.g importFrom(pathtosql_file, array $db_config);
.
To contribute to this project, send a pull request or find me on <a href="https://twitter.com/josiahoyahaya" target="_blank">Twitter</a>.
This project is licenced with the MIT license.
Files | / | .idea |
File | Role | Description | ||
---|---|---|---|---|
inspectionProfiles (1 file) | ||||
misc.xml | Data | Auxiliary data | ||
modules.xml | Data | Auxiliary data | ||
php.xml | Data | Auxiliary data | ||
simple-backup.iml | Data | Auxiliary data | ||
symfony2.xml | Data | Auxiliary data | ||
vcs.xml | Data | Auxiliary data | ||
workspace.xml | Data | Auxiliary data |
Files | / | src |
File | Role | Description | ||
---|---|---|---|---|
Exceptions (1 file) | ||||
Foundation (4 files) | ||||
SimpleBackup.php | Class | Class source |
Files | / | src | / | Foundation |
File | Role | Description |
---|---|---|
Configurator.php | Class | Class source |
Database.php | Class | Class source |
Mysqldump.php | Class | Class source |
Provider.php | Class | Class source |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.