Jump to content

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 <XXXXXX@gmail.com>";
$sendfrom = "Automated Backup <backup@XXXXXX.com>";
$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...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.