?
Current Path : /home1/savoy/public_html/savoyglobal.net/dbbackup/ |
Linux gator3171.hostgator.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 |
Current File : /home1/savoy/public_html/savoyglobal.net/dbbackup/is_backup_db.php |
<?php require("PHPMailer/class.phpmailer.php"); define('ABSPATH', dirname(__FILE__) . '/'); $label = ' /*************************************************** Isrishti Automatic Backup ****************************************************/ '; /*************************************************** Database settings ****************************************************/ $db_server = 'localhost'; // Database server, usually "localhost", $dbarray=array('savoy_sgms'=>'','savoy_secapp'=>'','savoy_sibs'=>''); // on (mt) servers something like internal-db.s12345.gridserver.com $db_user = 'savoy_globaluser'; // Database username $db_pass = 'globalisrishti'; // Database password /*************************************************** E-mail settings ****************************************************/ $website = 'savoyglobal.net'; // Your site's domain (without www. part) /*************************************************** Misc options ****************************************************/ // Full path to folder where you are running the script, usually "/home/username/public_html" // (mt) servers have something like "/nfs/c01/h01/mnt/12345/domains/yourdomain.mobi/html/tools/backup2mail" $delete_backup = true; // delete gziped database from server after sending? $send_log = true; // send follow-up report? // - true = send log file to an e-mail after each backup transfer // - false = don't send log file, just leave it on the server /*************************************************** If everything goes well, you shouldn't modify anything below. ****************************************************/ error_reporting(E_ALL); function date_stamp() { global $html_output; $backup_date = date('Y-m-d-H-i'); return $backup_date; } function backup_filename() { global $db_name, $date_stamp, $html_output; $db_backup_filename = ABSPATH.($db_name == '' ? 'all_databases' : $db_name) . '_' . $date_stamp . '.sql.gz'; return $db_backup_filename; } function db_dump() { global $db_server, $db_name, $db_user, $db_pass, $backup_filename, $html_output; $cmd = 'mysqldump -u ' . $db_user . ' -h ' . $db_server ." -p'$db_pass' ". ($db_name == '' ? '--all-databases' : $db_name) . ' | gzip > ' . $backup_filename; $dump_status = (system($cmd) === false) ? 'No' : 'Yes'; return $dump_status; } function send_attachment($file, $file_is_db = true,$islog=false) { global $send_to, $website, $delete_backup, $db_name,$html_output; $subject=""; $mailhtmlcontent=""; $sent = 'No'; if(!$islog) { $toextra = $send_to; if ($toextra) { $mailsto = explode(",", $toextra); } } else $toextra=""; if($islog) $to = "haseeb.k@isrishti.com"; else $to = "savoybackups@gmail.com"; $toName = ""; $fromName = 'Savoy Global'; $subject = ' [' . $db_name . '] - Database ' . ($file_is_db ? 'Backup' : 'Report').' on '. date('Y-m-d H:i'); if(!$islog) $mailhtmlcontent = 'Database backup file:' . "\n" . ' - ' . $db_name . "\n\n"; else $mailhtmlcontent = 'Database backup Report:' . "\n"; $mail = new PHPMailer(); $mail->IsSMTP(); // Use SMTP $mail->Host = "smtp.gmail.com"; // Sets SMTP server $mail->SMTPDebug = 2; // 2 to enable SMTP debug information $mail->SMTPAuth = TRUE; // enable SMTP authentication $mail->SMTPSecure = "tls"; //Secure conection $mail->Port = 587; // set the SMTP port $mail->Username = 'info@letspace.in'; // SMTP account username $mail->Password = 'letisrishti'; // SMTP account password $mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low) $mail->CharSet = 'UTF-8'; $mail->Encoding = '8bit'; $mail->ContentType = 'text/html; charset=utf-8\r\n'; $mail->SetFrom('savoybackups@gmail.com', 'Savoy Global'); $mail->AddReplyTo($fromName); $mail->XMailer = "Automater Mailer"; $mail->Subject = $subject; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->AddAttachment($file); $mail->MsgHTML($mailhtmlcontent); if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $to)) $mail->AddAddress($to, $toName); foreach ($mailsto as $emailto) { if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $emailto)) $mail->AddBCC($emailto); } if (!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "<font color='red'>Message sent! ($toextra)</font>"; $sent = 'Yes'; echo ($file_is_db ? 'Backup file' : 'Report') . ' sent to ' . $send_to . '.<br />'; if ($file_is_db) { if ($delete_backup) { unlink($file); echo 'Backup file REMOVED from disk.<br />'; } else { echo 'Backup file LEFT on disk.<br />'; } } } return $sent; } function write_log() { global $backup_filename, $date_stamp, $send_log, $label,$db_name; $log_file = ABSPATH . '/backup_log.txt'; if (!$handle = fopen($log_file, 'a+')) exit; $dumped = db_dump(); $log_content = "\n" . $date_stamp . "\t\t\t" . $db_name . "\t\t\t". "\t\t\t" . $dumped . "\t\t\t" . send_attachment($backup_filename); $log_header = ''; if (filesize($log_file) == '0') { $log_header .= $label . "\n\n"; $log_header .= 'Backup log' . "\n"; $log_header .= '----------------------------------------------' . "\n"; $log_header .= 'DATESTAMP: DB DUMPED MAILED' . "\n"; $log_header .= '----------------------------------------------'; if (fwrite($handle, $log_header) === false) exit; } if (fwrite($handle, $log_header) === false) { //echo 'no<br />' . "\n"; exit; } else { // echo 'yes<br />' . "\n"; } if (fwrite($handle, $log_content) === false) { //echo 'no<br />' . "\n"; exit; } else { //echo 'yes<br />' . "\n"; } fclose($handle); if ($send_log) { send_attachment($log_file, false,true); } } foreach($dbarray as $key=>$value) { $db_name = $key; $send_to = $value; $date_stamp = date_stamp(); $backup_filename = backup_filename(); $init = write_log(); } ?>