简体   繁体   中英

Cronjob for taking all MySQL database and sending it to e-mail

I want to create cronjob which would execute .php file and that file would get all database and that databe would be sent directly to my e-mail every day.

Have any ideas how could I do that?

Thank you very much.

What do you mean, "all database"? You want a listing of the databases held within the server? A dump of their contents? You don't need PHP for that, you can simply use a shell script:

mysqldump -p -u username_to_do_dump_with --all-databases | mail you@example.com -s 'database dumps'

In short: dump all databases held within mysql, pipe that output to the mail program, which sends the dump to you.

Of course, if you have a lot of data (particularly if you're storing files in the database), you're going to end up with a huge email, and emailing could corrupt the dump if there's any binary data. You'd most likely want to run the dump through gzip to reduce its side, and then have that .gz file sent out as an attachment, which would take a bit more scripting that this very simple version.

您可以编写一个执行mysqldump的脚本,然后通过电子邮件将文件发送给您...您实际上是在要求某人给您这样的脚本,还是在问如何将其放入cron?

Include the following in your crontab

@daily php php_file.php | mail -E -s "Subject line" your@emailaddress.com

mail is a program to send emails, it reads the body text from stdin and -s defines the subject line. -E means only send an email if there is body text, you may or may not want this.

Well you would write the php script, first.

Then you would put a line in your crontab something like this:

1 1 * * * path/to/your/script

To run the script once a day.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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