Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- date_default_timezone_set('Asia/Calcutta');
- require_once "../../variables.php";
- $gmessage = "Backing up databases\r\n\r\n";
- function backup($sitename, $db_user, $db_pass)
- {
- $db_server = $db_user.'.db.3740856.hostedresource.com'; // Database server, usually "localhost"
- $db_name = $db_user; // Database name, leave empty for 'all databases'
- $to ="[email protected], [email protected]"; // Address to wihch mail is to be sent
- $subject = "Backup of ".$sitename." at ".date('Y-m-d-H-i-s'); // subject of mail
- $headers = "From: ".$sitename."@dak.me\r\n";
- $bound_text = "Bound Text";
- $bound = "--".$bound_text."\r\n";
- $bound_last = "--".$bound_text."--\r\n"; // ========= I don't understand these three lines and their purpose ===
- $date_stamp = date('Y-m-d-H-i-s');
- $backup_filename = ($db_name == '' ? 'all_databases' : $db_name) . '_' . $date_stamp . '.sql.gz';
- $cmd = 'mysqldump -u ' . $db_user . ' -h ' . $db_server . ' --password=' . $db_pass . ' ' . ($db_name == '' ? '--all-databases' : $db_name) . ' | gzip > ' . $backup_filename;
- $dump_status = (passthru($cmd) === false) ? 'No' : 'Yes';
- $headers .= "MIME-Version: 1.0\r\n"
- ."Content-Type: multipart/mixed; boundary=\"$bound_text\"";
- $message .= "If you can see this MIME than your client doesn't accept MIME types!\r\n"
- .$bound;
- $message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
- ."Content-Transfer-Encoding: 7bit\r\n\r\n"
- ."Thank you for using dak database script from http://dak.me by <A HREF='http://mukeshdak.com'>Mukesh Dak</A>\r\n"
- .$bound;
- $file = file_get_contents("http://zdak.in/dcode/cron/".$backup_filename); // ======= don't forget to update this path ===========
- $message .= "Content-Type: application/x-zip-compressed; name=$backup_filename\"\r\n"
- ."Content-Transfer-Encoding: base64\r\n"
- ."Content-disposition: attachment; file=$backup_filename\r\n"
- ."\r\n"
- .chunk_split(base64_encode($file))
- .$bound_last;
- if($dump_status="Yes")
- {
- if(mail($to, $subject, $message, $headers))
- {
- // $gmessage .= "Backup of database ".$db_name." of ".$sitename." has been sent to ".$to."\r\n";
- unlink($backup_filename);
- } else {
- $gmessage .= 'MAIL FAILED';
- }
- }
- else{
- $gmessage .= "<p>There is some problem in taking dump of your database";
- }
- return "Backup of database ".$db_name." of ".$sitename." has been sent to ".$to."\r\n";
- } // function backup ends here
- ConnectDB();
- $result = mysql_query("SELECT * FROM ".TBL_DAKDATABASE." WHERE prepared='1'") or die("<p>Error in Table Selection: ".mysql_error());
- while($row = mysql_fetch_assoc($result))
- {
- $gmessage .= backup($row['linkurl'], $row['title'], $row['category']);
- }
- mysql_close(); // Close database connection
- //$gmessage .= backup('ShreeCement', 'shreecement', 'spiceS500');
- // backup of this database is causing problem
- $gmessage .= "\r\nDatabase backup job completed ".$_SERVER["PHP_SELF"]."\r\n\r\n";
- $gmessage .= "\r\n Script: http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."\r\n\r\n";
- mail("[email protected]", "Subject: Backupsuccessful", $gmessage, "From: [email protected]" );
- // send backup details to gmail without attachment
- echo "If you dont see any errors, everything went as planned";
- ?>
Add Comment
Please, Sign In to add comment