59 lines
1.5 KiB
Plaintext
Executable file
59 lines
1.5 KiB
Plaintext
Executable file
#!/usr/bin/php5
|
|
<?php
|
|
|
|
require_once '/usr/share/wetddump/functions.php';
|
|
|
|
mySfYaml::load('/etc/wetddump/mongodb.yml');
|
|
|
|
$log = mySfYaml::get('settings_log', '/var/log/wetddump/mongodb.log');
|
|
$dir = mySfYaml::get('settings_dir', '/var/lib/mongodbdump/');
|
|
|
|
if (!is_dir($dir)) {
|
|
$cmd = sprintf('mkdir -p %s', escapeshellarg($dir));
|
|
log_($cmd, $log);
|
|
exec_($cmd);
|
|
}
|
|
|
|
$cmd = sprintf('chdir %s', $dir);
|
|
log_($cmd, $log);
|
|
chdir($dir);
|
|
|
|
if (mySfYaml::get('settings_complete_enabled')) {
|
|
$cdir = mySfYaml::get('settings_complete_dir', 'complete/');
|
|
|
|
$cmd = sprintf('rm -rf %s', escapeshellarg($cdir));
|
|
log_($cmd, $log);
|
|
exec_($cmd);
|
|
|
|
$cmd = sprintf('mkdir -p %s', escapeshellarg($cdir));
|
|
log_($cmd, $log);
|
|
exec_($cmd);
|
|
|
|
$cmd = sprintf('rsync -avz --delete %s/* %s', mySfYaml::get('settings_mongodb'), $cdir);
|
|
log_($cmd, $log);
|
|
exec_($cmd);
|
|
}
|
|
|
|
if (mySfYaml::get('settings_mongodump_enabled')) {
|
|
$cdir = mySfYaml::get('settings_mongodump_dir', 'bson/');
|
|
|
|
$cmd = sprintf('rm -rf %s', escapeshellarg($cdir));
|
|
log_($cmd, $log);
|
|
exec_($cmd);
|
|
|
|
$cmd = sprintf('mkdir -p %s', escapeshellarg($cdir));
|
|
log_($cmd, $log);
|
|
exec_($cmd);
|
|
|
|
$options = mySfYaml::get('settings_mongodump_options', array());
|
|
|
|
$cmd = getMongodumpCmd(
|
|
mySfYaml::get('settings_mongodump_username', null),
|
|
mySfYaml::get('settings_mongodump_password', null),
|
|
implode(' ', $options),
|
|
$cdir
|
|
);
|
|
|
|
exec_($cmd);
|
|
}
|