Skip to content

Instantly share code, notes, and snippets.

@ScreamingDev
Created December 5, 2014 10:31
Show Gist options
  • Save ScreamingDev/600be7369aeb87dc350b to your computer and use it in GitHub Desktop.
Save ScreamingDev/600be7369aeb87dc350b to your computer and use it in GitHub Desktop.
wordpress db dump single php file
<?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