good_evening
good_evening

Reputation: 21749

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.

Upvotes: 0

Views: 1461

Answers (4)

rockerest
rockerest

Reputation: 10508

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.

Upvotes: 0

Marc B
Marc B

Reputation: 360692

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 [email protected] -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.

Upvotes: 4

Andrew Wilkinson
Andrew Wilkinson

Reputation: 10846

Include the following in your crontab

@daily php php_file.php | mail -E -s "Subject line" [email protected]

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.

Upvotes: 0

vmpstr
vmpstr

Reputation: 5211

You could just write a script that does a mysqldump and then emails you the file... Are you actually asking someone to give you such a script or are you asking how to put it into cron?

Upvotes: 2

Related Questions