简体   繁体   English

使用PHP和cronjob备份一个巨大的MySQL表

[英]Backing up a huge MySQL table using PHP and a cronjob

I'm working on developing a regular dump of our database. 我正在开发我们数据库的常规转储。 I'm using this script to create the backup and then feeding it through a regular cron job. 我正在使用此脚本创建备份,然后通过常规的cron作业提供它。 In the end we end up with a text file as well as an email archive of everything. 最后,我们最终得到了一个文本文件以及所有内容的电子邮件存档。

The problem we've encountered is the size of two of our tables. 我们遇到的问题是两个表的大小。 They each have 60k fields and grow daily. 它们每个都有6万个田地,每天都在种植。 I'm thinking incremental backup are the best solution for backup, but if it ever came to restoring it... It will be a huge project. 我认为增量备份是备份的最佳解决方案,但如果要恢复它......这将是一个巨大的项目。

My question is a two parter: 我的问题是两个人:

a) Is there a more straight forward way to backup huge tables on a daily basis and, if not, a)是否有更直接的方式每天备份大表,如果没有,

b) Is there an easy way to restore a backup from daily/weekly incremental backups? b)是否有一种简单的方法可以从每日/每周增量备份中恢复备份?

Thanks! 谢谢!

You may wish to check out Maatkit . 您可以查看Maatkit It's a bunch of perl scripts. 这是一堆perl脚本。 One of which is mk-parallel-dump which spawns multiple copies of mysqldump (by default, 1 per CPU in the machine) allowing the dump to go MUCH faster. 其中一个是MK-平行转储其中产卵的mysqldump的多个拷贝(默认情况下,1每个CPU在机器)允许所述转储去快得多 You can set this up in a cron job as well, like Daniel suggested. 你可以像在丹尼尔建议的那样在一个cron工作中设置它。

You can use a crob job to execute mysqldump to dump the tables down that you wish to backup. 您可以使用crob作业执行mysqldump以转储要备份的表。 Then just use a differential backup on that file for the daily backup and do a full backup once a week. 然后只需在该文件上使用差异备份进行每日备份,并每周进行一次完整备份。 The backup's heavy lifting should be done by your backup engine of choice. 备份的繁重应该由您选择的备份引擎完成。

Restoring a DB is never fun, so regardless it will be a big project. 恢复数据库永远不会有趣,所以无论它是一个大项目。

http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html

Let me know if this works for you. 如果这对您有用,请告诉我。

Consider using LVM snapshots to take periodic snapshots of your datasource, then use maatkit on the snapped copy in order to store an SQL dump. 考虑使用LVM快照来定期获取数据源的快照,然后在捕捉的副本上使用maatkit以存储SQL转储。 Do this on a slave MySQL db so that your backups don't cause performance problems for your live platform. 在从属MySQL数据库上执行此操作,以便备份不会导致实时平台出现性能问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM