Skip to content

Instantly share code, notes, and snippets.

@luissquall
Last active August 29, 2015 14:26
Show Gist options
  • Save luissquall/fc38cf76c4a84629edcf to your computer and use it in GitHub Desktop.
Save luissquall/fc38cf76c4a84629edcf to your computer and use it in GitHub Desktop.
<?php
/**
* dump.php?output=1
*
* Usage: curl http://domain.com/dump.php > dump.sql
*/
$bin = PHP_OS == 'Darwin' ? '/usr/local/mysql/bin/mysqldump' : '/usr/bin/mysqldump';
$user = 'root';
$password = '';
$db = 'cenotes';
$cmd = "$bin -u $user -p'$password' --default-character-set=utf8 $db";
$print = false;
if (!empty($_SERVER['QUERY_STRING'])) {
parse_str($_SERVER['QUERY_STRING'], $query);
if (isset($query['output']) && $query['output'] == 1) {
$print = true;
}
}
header('Content-Type: text/html; charset=utf-8');
if ($print) {
$output = shell_exec($cmd);
} else {
$cmd = $cmd . ' > ' . dirname (__FILE__) . '/dump.sql';
$output = exec($cmd . ' > ' . dirname (__FILE__) . '/dump.sql');
}
echo "/*$cmd*/";
echo "\n";
echo $output;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment