Example #1
0
    public static function getConfigOptions($part = null)
    {
        // new options
        $opt = array(CfgPart::DEFAULTS => array('host' => 'localhost', 'port' => '3306', 'user' => 'root', 'password' => '', 'compressdata' => false, 'addtobasedir' => '', 'rotate' => array('days' => 0, 'weeks' => 0, 'months' => 0), 'filter-ext' => false, 'with-passwords' => false, 'server-location' => 'auto', 'no-data' => false), CfgPart::DESCRIPTIONS => array('host' => 'mysql server host name', 'port' => 'mysql server port number', 'user' => 'mysql user name', 'password' => 'mysql user password', 'dbname' => <<<TXT
Database to backup if string or array of databases to backup.
If array it may be string expressing name of db or array overriding default settings.
If it is string starting with / then the text is executed as SQL command and its results are used instead.

Override of following settings is possible: dbname (array key is used if not provided), addtobasedir, compressdata.
Consult examples in examples/mysql folder.',
TXT
, 'dbname.sql' => "SQL select which will replace dbname with multiple values (eg. SELECT schema_name as dbname, false as compressdata FROM `information_schema`.`schemata` WHERE schema_name not in ('mysql', 'information_schema'))", 'addtobasedir' => '', 'compressdata' => 'compress data files on the fly (true=PHP zlib method, gzip=external utility)', 'rotate.days' => 'for how many days should backups be kept', 'rotate.weeks' => 'for how many weeks should backups be kept', 'rotate.months' => 'for how many months should backups be kept', 'filter-ext' => "specify external filter application like 'php -f filter.php -- '", 'with-passwords' => 'if true hash of user passwords will be stored', 'server-location' => 'if server is able to access backup folder (auto=try to detect,local=server able to write to backup folder,remote=slower as local)', 'no-data' => 'if used data from tables will not be included in backup'), CfgPart::REQUIRED => array('dbname'));
        // add old options from Storage_Filesystem
        //Core_Engine::array_merge_configOptions(parent::getConfigOptions(), $opt);
        $optOld = parent::getConfigOptions();
        foreach ($opt as $k => &$o) {
            if (array_key_exists($k, $optOld)) {
                $o = Core_Engine::array_merge_recursive_distinct($optOld[$k], $o);
            }
        }
        foreach ($optOld as $k => $o) {
            if (!array_key_exists($k, $opt)) {
                $opt[$k] = $o;
            }
        }
        if (is_null($part)) {
            return $opt;
        } else {
            return array_key_exists($part, $opt) ? $opt[$part] : array();
        }
    }
Example #2
0
 public function init($myrole, $drivers)
 {
     $this->_out->logNotice(">>>init " . get_class($this) . " compare driver");
     $this->_out->logDebug("opening DB file: " . $this->_options['file']);
     $this->_open();
     if ($this->_options['prefix']) {
         $this->_prefix = $this->_options['prefix'];
     } else {
         $this->_prefix = $this->_engine->getUniqueKey();
     }
     $this->_out->logDebug("we will use table name prefix: '{$this->_prefix}'");
     // TODO check that sqlite 3 is installed
     // TODO check mandatory options
     // TODO complain about not allowed options
     // TODO $options['prefix'] can't start with _ it would interfear with testing mode
     if ($this->_testing) {
         // TODO maybe using transaction ROLLBACK in shutdown is better
         $this->_prefix = "_" . $this->_prefix;
         $this->_out->logDebug("we are in testing mode so prefix is changed to: '{$this->_prefix}'");
     }
     $this->_createStructure($this->_options['rebuild']);
     $this->_dbIndexOn(false);
     // prepared statements
     $this->_prepFromRemote2 = $this->_db->prepare($this->_sql("INSERT INTO {$this->_prefix} (path, isDir, remote, rmd5, rtime, rsize) VALUES(:path, :isDir, :isRemote, :md5, :time, :size)", "prepare SQL: "));
     $this->_prepFromRemote1 = $this->_db->prepare($this->_sql("UPDATE {$this->_prefix} SET isDir=:isDir, remote=:isRemote, rsize=:size, rmd5=:md5, rtime=:time WHERE path=:path", "prepare SQL: "));
     $this->_prepFromLocalFull2 = $this->_db->prepare($this->_sql("INSERT INTO {$this->_prefix} (path, isDir, local, lmd5, ltime, lsize) VALUES(:path, :isDir, :isLocal, :md5, :time, :size)", "prepare SQL: "));
     $this->_prepFromLocalFull1 = $this->_db->prepare($this->_sql("UPDATE {$this->_prefix} SET isDir=:isDir, local=:isLocal, lsize=:size, lmd5=:md5, ltime=:time WHERE path=:path", "prepare SQL: "));
     $this->_prepFromLocal2 = $this->_db->prepare($this->_sql("INSERT INTO {$this->_prefix} (path, isDir, local, ltime, lsize) VALUES(:path, :isDir, :isLocal, :time, :size)", "prepare SQL: "));
     $this->_prepFromLocal1 = $this->_db->prepare($this->_sql("UPDATE {$this->_prefix} SET isDir=:isDir, local=:isLocal, lsize=:size, ltime=:time WHERE path=:path", "prepare SQL: "));
     $this->_prepFromLocalMd5 = $this->_db->prepare($this->_sql("UPDATE {$this->_prefix} SET lmd5=:md5 WHERE path=:path", "prepare SQL: "));
     $this->_prepFromRemoteMd5 = $this->_db->prepare($this->_sql("UPDATE {$this->_prefix} SET rmd5=:md5, rts=CASE WHEN rts is null THEN ltime ELSE rts END WHERE path=:path", "prepare SQL: "));
     // remote has done updates
     $this->_prepRemoteHasDeleted = $this->_db->prepare($this->_sql("DELETE FROM {$this->_prefix} WHERE path=:path", "prepare SQL: "));
     $this->_prepRemoteHasUploaded = $this->_db->prepare($this->_sql("UPDATE {$this->_prefix} SET remote=1, rmd5=lmd5, rsize=lsize, rts=ltime WHERE path=:path", "prepare SQL: "));
 }
Example #3
0
 /**
  * First output
  *
  * @return void
  */
 public function welcome()
 {
     $ver = "* v" . Core_Engine::getVersion();
     $ver .= str_repeat(" ", 34 - strlen($ver)) . "*";
     fputs(STDOUT, "***********************************" . PHP_EOL);
     fputs(STDOUT, "* xtBackup                        *" . PHP_EOL);
     fputs(STDOUT, $ver . PHP_EOL);
     fputs(STDOUT, "* sponsored by xtmotion.com, 2011 *" . PHP_EOL);
     fputs(STDOUT, "***********************************" . PHP_EOL);
     fputs(STDOUT, PHP_EOL);
 }
Example #4
0
 /**
  * @param Core_Engine $engine
  * @param Output_Stack $output
  * @param array $options
  *
  * @return \Storage_S3
  */
 public function __construct($identity, $engine, $output, $options)
 {
     // merge options with default options
     Core_Engine::array_merge_defaults($options, static::getConfigOptions(CfgPart::DEFAULTS), static::getConfigOptions(CfgPart::HINTS));
     // TODO see Compare_Sqlite constructor
     $this->_identity = $identity;
     $this->_out = $output;
     $this->_options = $options;
     $this->_engine = $engine;
     //init basedir property
     $this->getBaseDir();
 }
Example #5
0
 /**
  * @param Core_Engine  $engine
  * @param Output_Stack $output
  * @param array        $options
  *
  * @return \Storage_Filesystem
  */
 public function __construct($identity, $engine, $output, $options)
 {
     // merge options with default options
     Core_Engine::array_merge_defaults($options, static::getConfigOptions(CfgPart::DEFAULTS), static::getConfigOptions(CfgPart::HINTS));
     $this->_identity = $identity;
     $this->_out = $output;
     $this->_options = $options;
     $this->_engine = $engine;
     if (array_key_exists('basedir', $this->_options)) {
         $this->setBaseDir($this->_options['basedir']);
     }
     $this->_isWindows = strpos(strtolower(php_uname('s')), 'win') !== false;
     $this->_fileStat = new Storage_Filesystem_FileStat();
     if (array_key_exists('windows', $this->_options) && array_key_exists('encoding', $this->_options['windows'])) {
         $this->_fileStat->setWindowsEncoding($this->_options['windows']['encoding']);
     }
 }
Example #6
0
    echo "then to run it use 'php -f xtbackup.php -- ini[]=myconfig.ini'\n";
    echo "You can combine multiple INI files like this: 'php -f xtbackup.php -- ini[]=myconfig.ini ini[]=accesscredentials.ini'\n\n";
    echo "You can override INI setting by adding parameter to the end of command for example: \n";
    echo "'php -f xtbackup.php -- ini[]=myconfig.ini ini[]=accesscredentials.ini storage.s3.update=true'\n";
    echo "overrides 'storage.s3.update' that is setup within INI files.\n";
    exit(Core_StopException::RETCODE_OK);
}
// it is possible to suppress output to console in start phase of engine
$quiteStartIdx = array_search("--quiet-start", $argv);
if (false !== $quiteStartIdx) {
    unset($argv[$quiteStartIdx]);
}
// we need quite output if initializing INI file from start of the engine
$initIdx = array_search("--init", $argv);
if (false !== $initIdx || false !== $quiteStartIdx) {
    $output = false;
} else {
    // default output will be used in start phase of engine
    $output = null;
}
// initialize backup engine
$engine = new Core_Engine($argv, $output);
// show help message and stop if requested
if (false !== $initIdx) {
    echo $engine->generateIni();
    exit(Core_StopException::RETCODE_OK);
}
$engine->setAppHelpMessage("Use command line parameter --help to see usage instructions.");
$engine->init();
$engine->run();
exit($engine->finish());
Example #7
0
 /**
  * Load INI file or lines into configuration array
  *
  * @param string|array $fileName INI file name or array of INI file line
  * @param bool $onlyReturn don't merge to $this->_optionsIni if true
  * @return array
  */
 public function loadIni($fileName, $onlyReturn = false)
 {
     if (false !== $this->_options) {
         // if init() already executed
         self::$out->stop("init() already executed, loadIni() is not allowed any more.");
         return array();
     }
     if (is_array($fileName)) {
         // we use parse_ini_string
         $params = @parse_ini_string(implode("\n", $fileName));
     } else {
         // load and parse INI file
         $params = @parse_ini_file($fileName);
     }
     if (false === $params) {
         $le = error_get_last();
         self::$out->stop($le['message']);
     }
     // process keys
     $options = array();
     foreach ($params as $key => $val) {
         $a = explode(".", $key);
         $param = array();
         $b =& $param;
         foreach ($a as $k) {
             $b[$k] = array();
             $b =& $b[$k];
         }
         $b = $val;
         $options = array_merge_recursive($options, $param);
     }
     if (!$onlyReturn) {
         // merge with existing options
         //$this->_optionsIni = array_merge_recursive($this->_optionsIni, $options);
         $this->_optionsIni = Core_Engine::array_merge_recursive_distinct($this->_optionsIni, $options);
     }
     return $options;
 }