tmax100
06-06-2007, 06:45 PM
Hi, this is a cron job in php.
Currently this script emails me SQL file. (works fine)
Can anyone help me changing this code to compress SQL to tgz and email me the tgz file?
Thank you very much.
Look below
===========================================
$to = "email@address.com";
$from = "email@address.com";
$subject = "db - backup";
$sqlFile = $tmpDir.$prefix.date('Y_m_d').".sql";
$attachment = $tmpDir.$prefix.date('Y_m_d').".sql";
$creatBackup = "mysqldump -u ".$user." --password=".$password." -h ".$host." ".$dbName." > ".$sqlFile;
exec($creatBackup);
$headers = array('From' => $from, 'Subject' => $subject);
$textMessage = $attachment;
$htmlMessage = "";
$mime = new Mail_Mime("\n");
$mime->setTxtBody($textMessage);
$mime->setHtmlBody($htmlMessage);
$mime->addAttachment($attachment, 'text/plain');
$body = $mime->get();
$hdrs = $mime->headers($headers);
$mail = &Mail::factory('mail');
$mail->send($to, $hdrs, $body);
unlink($attachment);
?>
Currently this script emails me SQL file. (works fine)
Can anyone help me changing this code to compress SQL to tgz and email me the tgz file?
Thank you very much.
Look below
===========================================
$to = "email@address.com";
$from = "email@address.com";
$subject = "db - backup";
$sqlFile = $tmpDir.$prefix.date('Y_m_d').".sql";
$attachment = $tmpDir.$prefix.date('Y_m_d').".sql";
$creatBackup = "mysqldump -u ".$user." --password=".$password." -h ".$host." ".$dbName." > ".$sqlFile;
exec($creatBackup);
$headers = array('From' => $from, 'Subject' => $subject);
$textMessage = $attachment;
$htmlMessage = "";
$mime = new Mail_Mime("\n");
$mime->setTxtBody($textMessage);
$mime->setHtmlBody($htmlMessage);
$mime->addAttachment($attachment, 'text/plain');
$body = $mime->get();
$hdrs = $mime->headers($headers);
$mail = &Mail::factory('mail');
$mail->send($to, $hdrs, $body);
unlink($attachment);
?>
