d-garces-easyray/myphp-backup-st

myphp-backup的Structured版本,用于创建恢复MySQL数据库

dev-master 2024-03-27 15:05 UTC

This package is not auto-updated.

Last update: 2024-09-25 17:15:55 UTC


README

使用PHP执行简单快速的MySQL备份/还原。您可以使用它导出整个数据库或仅导出某些表。

需要PHP 5.0.5或更高版本。

更多信息: 使用PHP备份MySQL数据库

用法

备份

简单地将 myphp-backup.php 脚本上传到您的Web应用程序的DocumentRoot目录,通过FTP或其他方法,然后通过访问 http://www.example.com/myphp-backup.php 运行它。您也可以从命令行运行它。

在进行任何备份编辑之前,不要忘记设置数据库访问凭证,这些行来自 myphp-backup.php 脚本

/**
 * Define database parameters here
 */
define("DB_USER", 'your_username');
define("DB_PASSWORD", 'your_password');
define("DB_NAME", 'your_db_name');
define("DB_HOST", 'localhost');

define("BACKUP_DIR", 'myphp-backup-files'); // Comment this line to use same script's directory ('.')
define("TABLES", '*'); // Full backup
//define("TABLES", 'table1, table2, table3'); // Partial backup
define("CHARSET", 'utf8');
define("GZIP_BACKUP_FILE", true); // Set to false if you want plain SQL backup files (not gzipped)
define("DISABLE_FOREIGN_KEY_CHECKS", true); // Set to true if you are having foreign key constraint fails

默认情况下,备份文件将命名为 myphp-backup-{DB_NAME}-YYYYmmdd-HHMMSS.sql.gz 并存储在 myphp-backup-files 子目录中。示例输出备份文件

myphp-backup-files/myphp-backup-daniloaz-20170828-131745.sql.gz

还原

myphp-restore.php 脚本上传到您的DocumentRoot目录,并将备份文件上传到名为 myphp-backup-files 的子目录。然后,简单运行脚本,通过访问 http://www.example.com/myphp-restore.php 或从命令行。

您可以通过编辑这些行来更改备份文件名和子目录。别忘了设置用户凭证!

/**
 * Define database parameters here
 */
define("DB_USER", 'your_username');
define("DB_PASSWORD", 'your_password');
define("DB_NAME", 'your_db_name');
define("DB_HOST", 'localhost');
define("BACKUP_DIR", 'myphp-backup-files'); // Comment this line to use same script's directory ('.')
define("BACKUP_FILE", 'your-backup-file.sql.gz'); // Script will autodetect if backup file is gzipped or not based on .gz extension
define("CHARSET", 'utf8');
define("DISABLE_FOREIGN_KEY_CHECKS", true); // Set to true if you are having foreign key constraint fails

GitHub上的项目: https://github.com/daniloaz/myphp-backup

(c) Daniel López Azaña, 2012-2017 (http://www.daniloaz.com)