Jump to content

CRON job auto backup


galvin

Recommended Posts

So this CRON job was running every night and working fine, emailing me a backup of the SQL database. A few weeks ago it stopped and I can't figure out why because nothing changed with the database name, password, etc.

 

I got this code from the internet a couple years ago so I'm wondering if maybe something about the code itself is outdated?

 

Anyone have any thoughts?


// Create the mysql backup file
// edit this section
$dbhost = "localhost"; // usually localhost
$dbuser = "XXXXXX";
$dbpass = "XXXXXXX";
$dbname = "XXXXXXX";
$sendto = "XXXXX <[email protected]>";
$sendfrom = "Automated Backup <[email protected]>";
$sendsubject = "Daily XXXXXXX Mysql Backup";
$bodyofemail = "Here is the daily XXXXX backup.";
// don't need to edit below this section

$backupfile = $dbname . date("Y-m-d") . '.sql';
system("mysqldump -h $dbhost -u $dbuser -p$dbpass $dbname > $backupfile");

// Mail the file

include('Mail.php');
include('Mail/mime.php');

$message = new Mail_mime();
$text = "$bodyofemail";
$message->setTXTBody($text);
$message->AddAttachment($backupfile);
$body = $message->get();
$extraheaders = array("From"=>"$sendfrom", "Subject"=>"$sendsubject");
$headers = $message->headers($extraheaders);
$mail = Mail::factory("mail");
$mail->send("$sendto", $headers, $body);

// Delete the file from your server
unlink($backupfile);
Link to comment
https://forums.phpfreaks.com/topic/278355-cron-job-auto-backup/
Share on other sites

  • 5 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.