Skip to content

Instantly share code, notes, and snippets.

@AD7six
Forked from predominant/CakePHP Database dumping
Created February 21, 2011 10:38
Show Gist options
  • Save AD7six/836909 to your computer and use it in GitHub Desktop.
Save AD7six/836909 to your computer and use it in GitHub Desktop.
#!/usr/bin/php
<?php
if (!defined('TMP')) {
define('TMP', getcwd() . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR);
}
$file = getcwd() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'database.php';
if (!is_readable($file)) {
echo "Can't find database config at : $file\n";
die(1);
}
require($file);
$config = new DATABASE_CONFIG();
if (!isset($config->default)) {
echo "Can't find default connection information\n";
die(1);
}
$config = $config->default;
$aArgs = array(
'--host' => $config['host'],
'--port' => $config['port'],
'--username' => $config['login'],
'--password' => $config['password'],
'--default-character-set' => (!empty($config['encoding']))?$config['encoding']:'',
'-db' => $config['database'],
);
$aArgs = array_filter($args);
$args = '';
foreach($aArgs as $k => $v) {
$args .= " $k=" . escapeshellarg($v);
}
`mysqldump$args | gzip > {$config['database']}.sql.gz`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment