Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. <?php
  2. exec("/usr/bin/mysqldump -u mysql-user -h 123.145.167.189 -pmysql-pass database_name > /path-to-export/file.sql", $output);
  3. ?>
  4.  
  5. $return_var = NULL;
  6. $output = NULL;
  7. $command = "/usr/bin/mysqldump -u mysql-user -h 123.145.167.189 -pmysql-pass database_name > /path-to-export/file.sql";
  8. exec($command, $output, $return_var);
  9.  
  10. if($return_var) { /* there was an error code: $return_var, see the $output */ }
  11.  
  12. <?php
  13. exec("/usr/bin/mysqldump -u mysql-user -h 123.145.167.189 -pmysql-pass database_name", $output);
  14. /* $output will have sql backup, then save file with these codes */
  15. $h=fopen("/path-to-export/file.sql", "w+");
  16. fputs($h, $output);
  17. fclose($h);
  18. ?>
  19.  
  20. <?php
  21. define("BACKUP_PATH", "/full/path/to/backup/folder/with/trailing/slash/");
  22.  
  23. $server_name = "your.server.here";
  24. $username = "your_username";
  25. $password = "your_password";
  26. $database_name = "your_database_name";
  27. $date_string = date("Ymd");
  28.  
  29. $cmd = "mysqldump --hex-blob --routines --skip-lock-tables --log-error=mysqldump_error.log -h {$server_name} -u {$username} -p{$password} {$database_name} > " . BACKUP_PATH . "{$date_string}_{$database_name}.sql";
  30.  
  31. $arr_out = array();
  32. unset($return);
  33.  
  34. exec($cmd, $arr_out, $return);
  35.  
  36. if($return !== 0) {
  37. echo "mysqldump for {$server_name} : {$database_name} failed with a return code of {$return}nn";
  38. echo "Error message was:n";
  39. $file = escapeshellarg("mysqldump_error.log");
  40. $message = `tail -n 1 $file`;
  41. echo "- $messagenn";
  42. }
  43. ?>
  44.  
  45. exec("(mysqldump -u$username -p$password $database $tables > $dump_name) 2>&1", $output, $result);
  46.  
  47. var_dump($result);
  48. echo "<br />";
  49. var_dump($output);
  50. echo "<br />";
  51.  
  52. <?php exec('mysqldump --user=name_user --password=password_enter --host=localhost database_name > filenameofsql.sql'); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement