Created
February 21, 2011 09:24
-
-
Save predominant/836848 to your computer and use it in GitHub Desktop.
Creates dumps from CakePHP database configurations
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
#!/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']}`; |
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
Its been pointed out that this is completely shit, and you shouldn't use it. Other far more intelligent people have created tools that are infinitely better.