function __construct($backupconfig) { $config = lmbToolkit::instance()->getConf('yandex'); $this->logger = YaLogger::instance(); $auth = new YaAuth($config, $this->logger); $token = $auth->getToken(); if ($token == '') { throw Exception('Не могу получить токен'); } $this->disk = new YaDisk($token, $config, $this->logger); $this->db = $backupconfig->get('db'); $this->folders = $backupconfig->get('folders'); $this->tmp_dir = $backupconfig->get('tmp_dir'); $this->project = $backupconfig->get('project'); $this->backup_number = $backupconfig->get('stored_backups_number'); $this->server_dir = $backupconfig->get('dir'); $time = time(); $this->archive = date("Y-m-d", $time) . '-' . $time; }
new lmbBacktrace(); function write_error_in_log($errno, $errstr, $errfile, $errline) { global $logger; $back_trace = new lmbBacktrace(10, 10); $error_str = " error: {$errstr}\nfile: {$errfile}\nline: {$errline}\nbacktrace:" . $back_trace->toString(); $logger->log($error_str, "ERROR", $errno); } set_error_handler('write_error_in_log'); error_reporting(E_ALL); ini_set('display_errors', true); if ($argc < 2) { die('Usage: php cron_runner.php cron_job_file_path(starting from include_file_path)' . PHP_EOL); } $cron_job_file_path = $argv[1]; $logger = YaLogger::instance(); $lock_dir = LIMB_VAR_DIR . '/cron_job_lock/'; if (!file_exists($lock_dir)) { lmbFs::mkdir($lock_dir, 0777); } $name = array_shift(explode('.', basename($cron_job_file_path))); $lock_file = $lock_dir . $name; if (!file_exists($lock_file)) { file_put_contents($lock_file, ''); chmod($lock_file, 0777); } $fp = fopen($lock_file, 'w'); if (!flock($fp, LOCK_EX + LOCK_NB)) { $logger->logConflict(); return; }