|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello. I am trying to backup my mysql database, and have it e-mailed to me. I have the cron job set up to make the backup of the mysql database, and it works. The only thing that I need is a cron job that will automatically, at 12:30 A.M., e-mail me the backup file. How would I do this??? Thanks.
|
|
#2
|
|||
|
|||
|
Code a perl script that will pipe out the file through sendmail to your email address. And just set up this script on cron to run at 12:30AM every day.
Hope this helps. Ralph. |
|
#3
|
|||
|
|||
|
Well, I don't exactly know how to code in Perl. The only information that I need in the e-mail is the attached file, no message or anything. Can someone make this script for me???
|
|
#4
|
||||
|
||||
|
Something like
mail -s "Database backup" you@somedomain.com < database.dmp should work. Not the most reliable way though... More info -> http://www.unix.com/showthread.php?threadid=568 http://www.unix.com/showthread.php?threadid=25 //NoXcuz
__________________
UN*X is sexy! who | grep -i blonde | date; cd ~; unzip; touch; strip; finger; mount; gasp; yes; uptime; umount; sleep |
|
#5
|
|||
|
|||
|
That didn't work
Thanks, but doing "mail -s "Database backup" you@somedomain.com < database.dmp" doesn't stay in my crontab thing (it is cut down to mail -s). I don't know why. I also tried "metasend -b -t someone@somewhere.com -s "My webpage!" -m text/html -f mypage.html," but that also dissapeared from the crontab thing (it is cut down to metasend -b).
What else can I do??? |
|
#6
|
||||
|
||||
|
Use backticks, like
`mail -s "Database backup" you@somedomain.com < dumpfile.dmp` The same should work for metasend (with backticks). //NoXcuz |
|
#7
|
|||
|
|||
|
Have a look at this:
http://www.cgi-interactive.co.uk/mysql_dump.html It is a simple bash script, that extracts the db schema, compresses the data and emails you the backup. Bash Shell Script (mysqlbackup) ====================== #!/bin/sh mysqldump -uroot -ppwd --opt db1 > /sqldata/db1.sql cd /sqldata/ tar -zcvf sqldata.tgz *.sql cd /scripts/ perl emailsql.cgi line #2 - change -u to be your db username line #2 - change -p to be your db password emailsql.cgi Script ============= #!/usr/bin/perl -w use MIME::Lite; $msg = MIME::Lite->new( From => 'mysqlbackup@yourdomain.com', To => 'who.ever@yourdomain.com', Subject => 'sqldata.tgz MySQL backup!', Type => 'text/plain', Data => "Hi WhoEverl,\n MySQL database backups."); $msg->attach(Type=>'application/x-tar', Path =>"/sqldata/sqldata.tgz", Filename =>"sqldata.tgz"); $msg->send; Next, edit your cron table, by running "crontab -e". This will open the cron table in your default text editor, when you save it the file will be reloaded and ready for use. 30 0 * * * * /path/to/mysqlbackup This cron entry will run at 00:30 hours every morning. |
|
#8
|
|||
|
|||
|
I figured it out
@NoXcuz: The reason that your command was getting cut off was because of the quotation marks... I removed them, and made the subject one word, and now it works.
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > Linux Help > E-mailing a file via a cron job |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|