Mysql Archiver Script PHPMysql Archiver Script PHP
Backup your MySQL databases and restore backups with a breaeze.Mysql Archiver Script PHP
Backup your MySQL databases and restore backups with a breaeze.Overview
MysqlArchiver allows you to create archives ( backups ) of your MySQL databases and restore those archives whenever necessary. It's simple, efficient and very helpful.
IMPORTANT: when restoring an archive, all the data that wasn't in that backup WILL BE DELETED. so be ware.
Features
1. Archive an entire database or a few selected tables of your choice.
2. Restore any archive very easily in a matter of seconds.
3. Control the name and the location of the archive file.
Requirements
1. PHP 7+
2. Composer
3. That's it.
Instructions
This script is made using OOP so we'll be using objects most of the time.
You'll find a coding example in the screenshots.
Let's talk about each object in-depth for a bit.
1. MysqlArchiver\Config; is the configuration object. it's used to store database information like dbname, host, username and password.
You can pass that information as an array in the constructor of the config object OR you can use dedicated methods to do so.
- To set the dbname you'd use $config->setDBName( 'your_db_name_here' );
- To set the host you'd use $config->setHost( 'your_host_here' );
- To set the username you'd use $config->setUsername( 'your_username_here' );
- To set the password you'd use $config->setPassword( 'your_password_here' );
2. MysqlArchiver\Archiver; is the core archiving object. it accepts a config object in the constructor ( which is the object you created in step #1 ).
It contains 2 methods; export and import.
- export is the method used to export the database you specified in the config object. it accepts 2 optional parameters;
1. array $tables. an array of table names you'd like to be archived. defaults to an empty array which means archive all tables in a given database.
2. string $filename. a string of the location of the archived name defaults to null which will use a long string of the time and date of the created archive. test it for yourself to make a better sense of it.
Method definition:
public function export( array $tables = [], string $filename = null ) : string
You'll find more in-depth documentation in the readme.MD file in the root directory of the script