我需要使用cron作业每30分钟恢复一个数据库(mysql) [英] I need to restore a database (mysql) every 30 minutes using a cron job

查看:182
本文介绍了我需要使用cron作业每30分钟恢复一个数据库(mysql)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的cron工作,我需要每30分钟恢复一个数据库(mysql)。是否有一个cron作业命令,可以从已gzip压缩的.sql文件恢复数据库?

I'm new to cron jobs and I need to restore a database (mysql) every 30 minutes. Is there a cron job command that can restore a database from a .sql file that's been gzipped?

或者我需要创建一个php脚本来执行此操作,并创建一个cron作业每三十分钟调用一次这个脚本?

Or do I need to create a php script to do this and create a cron job to call this script every thirty minutes?

此外,这是一个单独的问题,但仍然与cron作业相关,我使用cron作业来备份不同的数据库每天一次,gzip它,并把它放在一个文件夹上面的根。是否有办法(自动)删除超过一个月的任何内容?或者,至少,保留最近的20个备份,并删除其余的?

Also, and this is a separate question but still related to cron jobs, I'm using a cron job to backup a different database once a day, gzip it and put it in a folder above the root. Is there a way to (automatically) delete anything older than a month? Or, at least, keep the most recent 20 backups and delete the rest?

没有很多好的教程,在这个主题,随机论坛帖子。

There's not a lot of good tutorial out there on this subject other that random forum posts. Any help is appreciated.

推荐答案

关于如何导入转储文件,只需放一个

Regarding how to import a dump file, simply put a

mysql -u user -ppassword databasename < /path/to/dump.sql 

添加到cron作业中。

into the cron job.

更多详细信息:如何还原MySQL .dump文件?

这篇关于我需要使用cron作业每30分钟恢复一个数据库(mysql)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆