louis1021 / mysql-php-backup-class
数据库的日终关闭备份机制,以防止数据丢失
dev-master
2020-07-18 14:56 UTC
This package is auto-updated.
Last update: 2024-09-19 00:08:52 UTC
README
本项目提供了一个有用的工具(PHP类),可以自动备份任何MySQL数据库,支持Amazon S3。
composer require louis1021/mysql-php-backup-class dev-master
AMAZON S3 尚未准备好!
变更日志
202007151522 - 现在我们已经有了当前的工作环境。
202007151454 - 重构并修复了mysqldump、mysql系统命令。
202007151300 - 添加了命名空间。
202007171257 - 重写了代码并成为了一个插件。
202007171242 - 是的,我已经分叉了。
功能
- Backup the whole database (All Tables) in one single file
- Backup each DB table in a seperate SQL Dump File
- Exclude specific tables from your Backup
- Backup data on Amazon S3 (Optional)
- Allows custom dump options
- Restore the whole database on the fly (Runs Once)
目前正在进行的任务
1. Add a Code Generation File
2. Validate user provided settings (DB Login and Amazon S3 Keys)
3. Validating user added dump options (within the 'addDumpOption' Method)
4. Creating the automatic scheduling of the backup process (CronJobs Creator)
5. Read Backup from Amazon S3 Storage if the local copy isn't available (in restore)
代码示例
基本备份使用
<?php use Louis1021\MysqlPhpBackupClass\DbBackup; $dbConfig = array('host' => 'localhost', 'login' => '{DBUsername}', 'password' => '{DBPassword}', 'database_name' => '{DBName}'); $dbBackupObj = new DbBackup($dbConfig); $dbBackupObj->setBackupDirectory('database/backup'); $dbBackupDbj->setCurrentWorkingDirectory(getcwd()); $dbBackupObj->executeBackup(); ?>
扩展备份使用(所有选项,注释代码)
<?php use Louis1021\MysqlPhpBackupClass\DbBackup; //Database address, credentials and name $dbConfig = array('host' => 'localhost', 'login' => '{DBUsername}', 'password' => '{DBPassword}', 'database_name' => '{DBName}'); //Amazon S3 Configurations Array (Optional) $amazonConfig = array('accessKey' => '{YOUR S3 ACCESS KEY}', 'secretKey' => '{Your S3 Secret Key}', 'bucketName' => '{Your Bucket}'); $dbBackupObj = new DbBackup($dbConfig); $dbBackupDbj->setCurrentWorkingDirectory(getcwd()); //Put backup files in the 'extendedExample' directory. NOTE: 'backups' DIR should be writable $dbBackupObj->setBackupDirectory('backups/extendedExample'); //To disable the single table files dumping (1 Dump file for the whole database) $dbBackupObj->setDumpType(0); //Exclude few tables from your backup execution $dbBackupObj->excludeTable('table1Name','tabel2Name','table3Name'); //Add few custom options to your backup execution $dbBackupObj->addDumpOption('--xml','--force'); //Get XML output and Continue on error //Transfer your backup files to Amazon S3 Storage // $dbBackupObj->enableS3Support($amazonConfig); //Start the actual backup process using the user specified settings and options $dbBackupObj->executeBackup(); ?>
基本恢复使用
<?php use Louis1021\MysqlPhpBackupClass\DbBackup; $dbConfig = array('host' => 'localhost', 'login' => '{DBUsername}', 'password' => '{DBPassword}', 'database_name' => '{DBName}'); $dbBackupObj = new DbBackup($dbConfig); $dbBackupObj->executeRestore(); ?>