Skip to content

Instantly share code, notes, and snippets.

@predominant
Created February 21, 2011 09:24
Show Gist options
  • Select an option

  • Save predominant/836848 to your computer and use it in GitHub Desktop.

Select an option

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']}`;
@predominant
Copy link
Copy Markdown
Author

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.

@AD7six
Copy link
Copy Markdown

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