Created
December 5, 2014 10:31
-
-
Save ScreamingDev/600be7369aeb87dc350b to your computer and use it in GitHub Desktop.
wordpress db dump single php file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'wp-config.php'; | |
$dbhost = DB_HOST; | |
$dbuser = DB_USER; | |
$dbpass = DB_PASSWORD; | |
$dbname = DB_NAME; | |
$h = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); | |
mysql_select_db(DB_NAME); | |
header('Content-type: text/sql'); | |
$backup_file = $dbname . date("Y-m-d-H-i-s") . '.sql'; | |
header('Content-Disposition: attachment; filename="' . $backup_file . '"'); | |
$cmd = 'mysqldump ' | |
. ' --host=' . escapeshellarg($dbhost) | |
. ' --user=' . escapeshellarg($dbuser) | |
. ' --password=' . escapeshellarg($dbpass) | |
. ' ' . escapeshellarg($dbname) | |
. ' > ' . $backup_file; | |
passthru($cmd, $return); | |
if ($return) { | |
echo "Some error occured."; | |
exit; | |
} | |
readfile($backup_file); | |
unlink($backup_file); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment