GoDaddy MySQL backups

Updated 20110212

  • Need automatic backups of mysql dbs
  • Need automatic backups of uploads (assets)

Note: Hosting absolute path is found in Hosting Plan control panel Home Tab under Server

 


SQL backup: Cron job to call silisoftware backupDB and email gz file

  • Can work without mysqldump command
  • Was getting warnings, we possibly have table names that contain MySQL reserved words, changed:

$result = mysql_query('SELECT * FROM '.$SelectedTables[$dbname][$t]);

to

$result = mysql_query("SELECT * FROM `".$SelectedTables[$dbname][$t]."`");

 

Assets backup: Omicronlab backup job to zip assets and email them

  • Splits zip file into into sequence of zip files (no larger than 10mb) with separate emails
  • Modified to remove SQL Dump stuff
<?php

/*
Backup website assets then send by email script
Credit to original author
Author: Mehdi Hasan, http://omicronlab.com/forum/-t850.html
201102 Modified by FlipperAndFriends.com to be compatible with Godaddy
- Removed DB part as uses mysqldump
- Updated to Swift 4.0.6
- Added timestamp to mail subject
- Added $path to mail subject
*/

// ******************************
// setup variables, edit below
// ******************************

$path = '/home/content/m/o/t/xxxxx/html/_xxxxxx.com/assets';// Which directory to backup? Don't add trailing slash

$zipfile = 'hrasset';// backup file name (DON'T INCLUDE ZIP EXTENTION, GMAIL MAY DELETE IT IF EXE INSIDE)

//Important: Select an empty directory here for $zippath
//The script will DELETE EVERY CONTENT of this directory before proceeding
$zippath = '/home/content/m/o/t/xxxxx/html/_xxxxxx.com/backupassets';// path to temporarily save backup file

$zip_split_size = 9 * 1024 * 1024;//In Megabyte
//Important: Gmail doesn't allow attachments more than 10 MB.
//And, your SMTP mail account should have necessary quota space
//free to send attachments. For this, set $zip_split_size variable wisely.
//Here, we set it to 9 MB.

$mailserver = 'relay-hosting.secureserver.net'; //SMTP server address
$to = 'webmaster@xxxx.com';// Where to send the emails?
$from = 'webmaster@xxxx.com';// Who should the emails be sent from? Must be valid Godaddy email account

//require_once('backupDB.functions.php');

//===================================================================================

// ******************************
// Do not Modify below this line!
// ******************************
$timenow = gmdate('F j, Y g:ia T', time() + date('Z'));
echo "It is now $timenow<br>";
// Delete any previous file from tmp directory
exec("rm -r -f $zippath/*");
$zipname = "$zippath/$zipfile.zip";
echo ("<h4><center>Zipping Directory: $path</center></h4> <br>");
echo "zip -q -r $zipname $path ";
//echo SafeExec("zip -q -r $zipname $path ");
echo passthru("zip -q -r $zipname $path ");
if (file_exists($zipname)==false){
exit ("<h4><center><font color=\"#FF0000\">Server failed to zip $path! <br><br>Hint: Make sure $zippath directory is CHOMD 777 and $path path exists.<br>Quiting... :( </font></center></h4>") ;
}

$EstimateSplittedFiles = intval(exec("zipsplit -t -n $zip_split_size -b $zippath $zipname "));
echo "EstimateSplittedFiles:$EstimateSplittedFiles";
if ($EstimateSplittedFiles<=0){
exit ("<h4><center><font color=\"#FF0000\">Server failed to split zip file $zipname! <br>Try to increase desired spilt size in \$zip_split_size variable.<br>Quiting... :( </center></h4>") ;
}

echo ("<h4><center>Estimated number of splitted files: " . $EstimateSplittedFiles .
"</center></h4> <br>");
echo ("<h4><center>Splitting zip file: $zipname</center></h4> <br>");
echo ("<center>");
echo "zipsplit -n $zip_split_size -b $zippath $zipname ";
echo passthru("zipsplit -n $zip_split_size -b $zippath $zipname ");
echo ("</center> <br>");
//Mailer
require_once "Swift-4.0.6/lib/swift_required.php";

$senddate = date("l j F Y");
$mailsubject = "WEB Backup - $timenow";// Subject in the email to be sent.
$mailbody = "$timenow:$path as zip files";// Brief Message.

//Start Swift
echo ("<h4><center>Starting Sending Mails ... ... ...</center></h4> <br>");
$i = 1;
echo ("<h4><center>$zippath/$zipfile" . FormatFileNumber($i) . ".zip</center></h4> <br>");
while (file_exists("$zippath/$zipfile" . FormatFileNumber($i) . ".zip"))
{
echo ("<h4><center>In Send email code</center></h4> <br>");

rename("$zippath/$zipfile" . FormatFileNumber($i) . ".zip", "$zippath/$zipfile" .FormatFileNumber($i));
$tmpFileName = "$zippath/$zipfile" . FormatFileNumber($i);
$mailsubject = "WEB Backup - $timenow - $zipfile" . FormatFileNumber($i);// Subject in the email to be sent.

echo ("<center>Processing: $tmpFileName </center><br>");
$transport = Swift_SmtpTransport::newInstance($mailserver, 25);
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance($mailsubject)
->setFrom($from)
->setTo($to)
->setBody($mailbody)
->attach(Swift_Attachment::fromPath($tmpFileName));
$result = $mailer->send($message);
echo "Send result: $result";
echo ("<h4><center>Just Sent: $tmpFileName </center></h4><br>");
//exec("rm -r -f $tmpFileName");
$i++;
flush;
}

//exec("rm -r -f $zipname");

echo ("<h4><center><font color=\"#008080\">Finish Sending all mails! Check your inbox :) </font></center></h4><br>");

function FormatFileNumber($num)
{
global $EstimateSplittedFiles;
return sprintf("%0" . strlen($EstimateSplittedFiles) . "d", $num);

}

?>

BUT, too many assets causes problems with godaddy email relay.. so  how about a syncronising tool?

Trying AllWaySync

 

 

 

 



OLD stuff below

 


Issue:

Need tool to automatically backup hosted folders (assets) and mysql db hosted on godaddy shared linux plan (Silverstripe CMS site)

 


omicronlab.com have a back up tool that does both folders & mysql database.. BUT uses mysqldump, which is not allowed on Godaddy shared hosting.. so.. we will remove the mySQL dump stuff from this tool..

Also updated it use the latest swift library.. but i can't remember why...

Notes:

  • Works using relay-hosting.secureserver.net
  • Sending email address does not need to be valid godaddy account
  • I also tested it with transport set to $transport = Swift_MailTransport::newInstance(); and it works fine

 

<?php

/*
Backup whole website and database (optional)
then send by email script
Last updated: 8 March, 2007
Author: Mehdi Hasan
The latest version can be obtained from here:
http://omicronlab.com/forum/-t850.html
*/

/*
Amended 20100910 Lindsay
- Removed DB part as uses mysqldump
- Updated to latest Swift 4.0.6
*/

// ******************************
// setup variables, edit below
// ******************************

$path = '/home/content/m/o/t/motosparkhost/html/_hairyraho.com/assets';// Which directory to backup? Don't add trailing slash

$zipfile = 'hrasset';// backup file name (DON'T INCLUDE ZIP EXTENTION, GMAIL MAY DELETE IT IF EXE INSIDE)

//Important: Select an empty directory here for $zippath
//The script will DELETE EVERY CONTENT of this directory before proceeding
$zippath = '/home/content/m/o/t/motosparkhost/html/_hairyraho.com/backups';// path to temporarily save backup file

$zip_split_size = 9 * 1024 * 1024;//In Megabyte
//Important: Gmail doesn't allow attachments more than 10 MB.
//And, your SMTP mail account should have necessary quota space
//free to send attachments. For this, set $zip_split_size variable wisely.
//Here, we set it to 9 MB.

$mailserver = 'relay-hosting.secureserver.net'; //SMTP server address
$mailserver_need_authentication='no'; //Use username & password for sending mail? 'yes' or 'no'
$smtpusername = 'webmaster@gravelrash.com'; //SMTP server username
$smtppassword = 'mailpassword'; //SMTP server password
$to = 'webmaster@gravelrash.com';// Where to send the emails?
$from = 'php@hairyraho.com';// Who should the emails be sent from?

//===================================================================================

// ******************************
// Do not Modify below this line!
// ******************************

// Delete any previous file from tmp directory
exec("rm -r -f $zippath/*");

$zipname = "$zippath/$zipfile.zip";
echo ("<h4><center>Zipping Directory: $path</center></h4> <br>");
passthru("nice -n 16 zip -q -r $zipname $path ");
if (file_exists($zipname)==false){
exit ("<h4><center><font color=\"#FF0000\">Server failed to zip $path! <br><br>Hint: Make sure $zippath directory is CHOMD 777 and $path path exists.<br>Quiting... :( </font></center></h4>") ;
}

$EstimateSplittedFiles = intval(exec("zipsplit -t -n $zip_split_size -b $zippath $zipname "));

if ($EstimateSplittedFiles<=0){
exit ("<h4><center><font color=\"#FF0000\">Server failed to split zip file $zipname! <br>Try to increase desired spilt size in \$zip_split_size variable.<br>Quiting... :( </center></h4>") ;
}

echo ("<h4><center>Estimated number of splitted files: " . $EstimateSplittedFiles .
"</center></h4> <br>");
echo ("<h4><center>Splitting zip file: $zipname</center></h4> <br>");
echo ("<center>");
exec("nice -n 16 zipsplit -n $zip_split_size -b $zippath $zipname ");
echo ("</center> <br>");
//Mailer
require_once "Swift-4.0.6/lib/swift_required.php";

$senddate = date("l j F Y");
$mailsubject = "WEB Backup - $senddate";// Subject in the email to be sent.
$mailbody = "Your web directory backup is attached to this email";// Brief Message.

//Start Swift

echo ("<h4><center>Starting Sending Mails ... ... ...</center></h4> <br>");

$i = 1;

echo ("<h4><center>$zippath/$zipfile" . FormatFileNumber($i) . ".zip</center></h4> <br>");

while (file_exists("$zippath/$zipfile" . FormatFileNumber($i) . ".zip"))
{

echo ("<h4><center>In Send email code</center></h4> <br>");

rename("$zippath/$zipfile" . FormatFileNumber($i) . ".zip", "$zippath/$zipfile" .FormatFileNumber($i));
$tmpFileName = "$zippath/$zipfile" . FormatFileNumber($i);

echo ("<center>Processing: $tmpFileName </center><br>");


$transport = Swift_SmtpTransport::newInstance($mailserver, 25);
//$transport = Swift_MailTransport::newInstance();
/* if ($mailserver_need_authentication="yes"){
$transport->setUsername($smtpusername);
$transport->setPassword($smtppassword);
}
*/
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance($mailsubject)
->setFrom(array($from => $from))
->setTo(array($to))
->setBody($mailbody)
->attach(Swift_Attachment::fromPath($tmpFileName));

$result = $mailer->send($message);
echo $result;

echo ("<h4><center>Just Sent: $tmpFileName </center></h4><br>");

exec("rm -r -f $tmpFileName");

$i++;

flush;
}

exec("rm -r -f $zipname");

echo ("<h4><center><font color=\"#008080\">Finish Sending all mails! Check your inbox :) </font></center></h4><br>");

function FormatFileNumber($num)
{
global $EstimateSplittedFiles;
return sprintf("%0" . strlen($EstimateSplittedFiles) . "d", $num);

}


?>

And we will use http://www.silisoftware.com backupDB tool as this can generate backups using php only and email the results..

Call with: http://www.hairyraho.com/silisoftware.com-backupdb/backupDB?StartBackup=complete&mailto=y

We need to target a specific DB as scheme in MYSQL is not accessible to me..

But.. generates bunch of warnings..  tracing.. seems it does a 'select * from Group' and perhaps 'group' is a mysql reserved word.. so.. changing to include backticks on target table names:

                        $result = mysql_query('SELECT * FROM '.$SelectedTables[$dbname][$t]);

to

                        $result = mysql_query("SELECT * FROM `".$SelectedTables[$dbname][$t]."`");

now works great.

 


Now we use godaddys cron manager to run each automally.

 


 

<?php

/*
Backup website assets then send by email script
Credit to original author
Author: Mehdi Hasan, http://omicronlab.com/forum/-t850.html
201102 Modified by FlipperAnd friends.com to be compatible with Godaddy
- Removed DB part as uses mysqldump
- Updated to Swift 4.0.6
- Added timestamp to mail subject
- Added $path to mail subject
*/

// ******************************
// setup variables, edit below
// ******************************

$path = '/home/content/m/o/t/motosparkhost/html/_hairyraho.com/assets';// Which directory to backup? Don't add trailing slash

$zipfile = 'hrasset';// backup file name (DON'T INCLUDE ZIP EXTENTION, GMAIL MAY DELETE IT IF EXE INSIDE)

//Important: Select an empty directory here for $zippath
//The script will DELETE EVERY CONTENT of this directory before proceeding
$zippath = '/home/content/m/o/t/motosparkhost/html/_hairyraho.com/backupassets';// path to temporarily save backup file

$zip_split_size = 9 * 1024 * 1024;//In Megabyte
//Important: Gmail doesn't allow attachments more than 10 MB.
//And, your SMTP mail account should have necessary quota space
//free to send attachments. For this, set $zip_split_size variable wisely.
//Here, we set it to 9 MB.

$mailserver = 'relay-hosting.secureserver.net'; //SMTP server address
$to = 'webmaster@gravelrash.com';// Where to send the emails?
$from = 'webmaster@gravelrash.com';// Who should the emails be sent from? Must be valid Godaddy email account

//require_once('backupDB.functions.php');

//===================================================================================

// ******************************
// Do not Modify below this line!
// ******************************
$timenow = gmdate('F j, Y g:ia T', time() + date('Z'));
echo "It is now $timenow<br>";
// Delete any previous file from tmp directory
exec("rm -r -f $zippath/*");
$zipname = "$zippath/$zipfile.zip";
echo ("<h4><center>Zipping Directory: $path</center></h4> <br>");
echo "zip -q -r $zipname $path ";
//echo SafeExec("zip -q -r $zipname $path ");
echo passthru("zip -q -r $zipname $path ");
if (file_exists($zipname)==false){
exit ("<h4><center><font color=\"#FF0000\">Server failed to zip $path! <br><br>Hint: Make sure $zippath directory is CHOMD 777 and $path path exists.<br>Quiting... :( </font></center></h4>") ;
}

$EstimateSplittedFiles = intval(exec("zipsplit -t -n $zip_split_size -b $zippath $zipname "));
echo "EstimateSplittedFiles:$EstimateSplittedFiles";
if ($EstimateSplittedFiles<=0){
exit ("<h4><center><font color=\"#FF0000\">Server failed to split zip file $zipname! <br>Try to increase desired spilt size in \$zip_split_size variable.<br>Quiting... :( </center></h4>") ;
}

echo ("<h4><center>Estimated number of splitted files: " . $EstimateSplittedFiles .
                "</center></h4> <br>");
echo ("<h4><center>Splitting zip file: $zipname</center></h4> <br>");
echo ("<center>");
echo "zipsplit -n $zip_split_size -b $zippath $zipname ";
echo passthru("zipsplit -n $zip_split_size -b $zippath $zipname ");
echo ("</center> <br>");
//Mailer
require_once "Swift-4.0.6/lib/swift_required.php";

$senddate = date("l j F Y");
$mailsubject = "WEB Backup - $timenow";// Subject in the email to be sent.
$mailbody = "$timenow:$path as zip files";// Brief Message.

//Start Swift
echo ("<h4><center>Starting Sending Mails ... ... ...</center></h4> <br>");
$i = 1;
echo ("<h4><center>$zippath/$zipfile" . FormatFileNumber($i) . ".zip</center></h4> <br>");
while (file_exists("$zippath/$zipfile" . FormatFileNumber($i) . ".zip"))
{
    echo ("<h4><center>In Send email code</center></h4> <br>");

    rename("$zippath/$zipfile" . FormatFileNumber($i) . ".zip", "$zippath/$zipfile" .FormatFileNumber($i));
    $tmpFileName = "$zippath/$zipfile" . FormatFileNumber($i);
    $mailsubject = "WEB Backup - $timenow - $zipfile" . FormatFileNumber($i);// Subject in the email to be sent.

    echo ("<center>Processing: $tmpFileName </center><br>");
    $transport = Swift_SmtpTransport::newInstance($mailserver, 25);
    $mailer = Swift_Mailer::newInstance($transport);
     $message = Swift_Message::newInstance($mailsubject)
        ->setFrom($from)
        ->setTo($to)
        ->setBody($mailbody)
        ->attach(Swift_Attachment::fromPath($tmpFileName));
        $result = $mailer->send($message);
        echo "Send result: $result";
        echo ("<h4><center>Just Sent: $tmpFileName </center></h4><br>");
        //exec("rm -r -f $tmpFileName");
        $i++;
        flush;
}

//exec("rm -r -f $zipname");

echo ("<h4><center><font color=\"#008080\">Finish Sending all mails! Check your inbox :) </font></center></h4><br>");

function FormatFileNumber($num)
{
                global $EstimateSplittedFiles;
                return sprintf("%0" . strlen($EstimateSplittedFiles) . "d", $num);

}

?>