Created
June 24, 2014 05:59
-
-
Save spolischook/969f98225088dc9eec1d to your computer and use it in GitHub Desktop.
Import mongoDb database dump
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
| <?php | |
| function show_run($text, $command, $canFail = false) | |
| { | |
| echo "\n* $text\n$command\n"; | |
| passthru($command, $return); | |
| if (0 !== $return && !$canFail) { | |
| echo "\n/!\\ The command returned $return\n"; | |
| exit(1); | |
| } | |
| } | |
| function show_action($action) | |
| { | |
| echo file_get_contents(__DIR__.'/banner'); | |
| printf("\n %s\n| %s |\n %s\n", str_repeat('-', strlen($action)+2), $action, str_repeat('-', strlen($action)+2)); | |
| } | |
| function read_arg(array $argv, $index, $default = null) | |
| { | |
| return isset($argv[$index+1]) ? $argv[$index+1] : $default; | |
| } | |
| function build_bootstrap() | |
| { | |
| show_run('Building bootstrap', 'vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php app'); | |
| } |
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/env php | |
| <?php | |
| require_once __DIR__.'/base_script.php'; | |
| $options = getopt("", array('db:', 'dir:')); | |
| $options['dir'] = !empty($options['dir']) ? $options['dir'] : "/"; | |
| $options['db'] = !empty($options['db']) ? $options['db']: "exercise"; | |
| $optionsLine = sprintf(" --dir=%s --db=%s", $options['dir'], $options['db']); | |
| foreach (scandir($options['dir']) as $file) { | |
| $pathParts = pathinfo($file); | |
| if ('bson' === $pathParts['extension']) { | |
| show_run( | |
| 'Import collection ' . $pathParts['filename'], | |
| sprintf('mongorestore -d %s -c %s %s.bson', $options['db'], $pathParts['filename'], $options['dir'] . $pathParts['filename']) | |
| ); | |
| } | |
| } | |
| exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment