kobena Posted April 14, 2011 Share Posted April 14, 2011 Larry explained explicitly how to backup in chapter 10. I want to go further by sending an attachment of the backed up file. Has anyone done this already? with the syntax $mime->addAttachment($file_name,$file_type); can someone tell me the $file_type? Also, "Testing HTML Email with an Image" didn't work for me but "Sending HTML Email" worked when i maintained the factory function argument as "mail" although i was using smtp. Can someone explain that to me? Thanks Link to comment Share on other sites More sharing options...
Larry Posted April 15, 2011 Share Posted April 15, 2011 I forget offhand what the output of the backup is. Maybe .sql? If so, you can use plain/text as the file type. Can't answer the other question given the (lack of) information provided. Link to comment Share on other sites More sharing options...
Jonathon Posted April 15, 2011 Share Posted April 15, 2011 Yes it's an .sql file 1 Link to comment Share on other sites More sharing options...
kobena Posted April 18, 2011 Author Share Posted April 18, 2011 Thanks larry for your response. One more thing, how can i get around this $mime->addAttachment("F:/backups/$db_name/{$table}_{$time}.sql.gz",plain/text); i tried $file_name='F:/backups/$db_name/{$table}_{$time}.sql.gz'; and then $mime->addAttachment($file_name,plain); but never worked out probably due to the variables. Any help will be very much appreciated. Link to comment Share on other sites More sharing options...
Larry Posted April 18, 2011 Share Posted April 18, 2011 I don't know exactly what you mean by "get around this", but I will say that this code: $file_name='F:/backups/$db_name/{$table}_{$time}.sql.gz'; won't work because variables within single quotes aren't extrapolated. Link to comment Share on other sites More sharing options...
kobena Posted April 18, 2011 Author Share Posted April 18, 2011 Thanks Larry for your response. I finally got around it using mysqldump and windows scheduler. my only problem using mysqldump is that all the records/rows come in a long string of characters making it difficult to read. Is there a way to add a new line to each row in mysqldump? I have searched all over but not getting anywhere. PHP 5.3.1 Mysql 5.1.41 Windows 2003 server OS The following backup and email script could be of help to novices like me: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php /* Quickly and easily backup your MySQL database and have the tgz emailed to you. You need PEAR installed with the Mail and Mail_Mime packages installed. Read more about PEAR here: http://pear.php.net */ require_once('Mail.php'); require_once('Mail/mime.php'); // location of your temp directory $tmpDir = "F:/backups/"; // username for MySQL $user = "user"; // password for MySQl $password = "password"; // database name to backup $dbName = "database_name"; // the zip file emailed to you will have this prefixed $prefix = "db_databasename_HO_"; // email settings... $to = "to@gmail.com"; $from = "from@gmail.com"; $subject = "db - backup-HO"; $sqlFile = $tmpDir.$prefix.date('d_m_Y').".sql"; $attachment = $tmpDir.$prefix.date('d_m_Y').".sql"; $creatBackup = "F:/xampp/mysql/bin/mysqldump -u ".$user." --password=".$password." ".$dbName." > ".$sqlFile; $createZip = "tar cvzf $attachment $sqlFile"; exec($creatBackup); exec($createZip); //system("mysqldump -h $dbhost -u $dbuser -p$dbpass $dbname > 'F:/backups/$sqlFile' //"); $headers = array('From' => $from, 'Subject' => $subject); $textMessage = $attachment; $htmlMessage = "Backing up of database"; $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); echo "Backup completed successfully and emailed"; unlink($sqlFile); unlink($attachment); ?> </body> </html> Link to comment Share on other sites More sharing options...
Matthaus Posted April 20, 2011 Share Posted April 20, 2011 Try adding this flag to mysqldump. --extended-insert=false (http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_extended-insert). It will make every row have its own insert statement, but should make it more readable. Hope that helps. -matthaus 1 Link to comment Share on other sites More sharing options...
Recommended Posts