Skip to content

Instantly share code, notes, and snippets.

@predominant
Created February 21, 2011 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save predominant/836848 to your computer and use it in GitHub Desktop.
Save predominant/836848 to your computer and use it in GitHub Desktop.
Creates dumps from CakePHP database configurations
#!/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);
}
$cmp = array(
'method' => 'bzip2',
'ext' => 'bz2',
);
if ($cmp['method'] == '') {
$cmp['ext'] = '';
} else {
$cmp['method'] = '| ' . $cmp['method'];
}
$config = $config->default;
foreach ($config as $k => &$v) {
$v = escapeshellarg($v);
if ($k === 'password') {
if ($v != '') {
$v = '-p' . $v;
}
}
}
`mysqldump -u {$config['login']} {$config['password']} {$config['database']} {$cmp['method']} > {$config['database']}.sql{$cmp['ext']}`;
@AD7six
Copy link

AD7six commented Feb 21, 2011

Hear ye hear ye, now slightly less shit and you should use it if it suits your purpose :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment