コード例 #1
0
 public function getLoggerInstance()
 {
     if (self::$logger == NULL) {
         self::$logger = new Logger();
     }
     return self::$logger;
 }
コード例 #2
0
ファイル: SSHHost.php プロジェクト: jamesduan/etbackuptool
 function __construct($host, $user, $pass)
 {
     $this->date = Utils::getDateInstance();
     $this->logger = GlobalLogger::getLoggerInstance();
     $this->host_ip = $host;
     //$this->cur_dir="~";
     $this->ssh_connection = ssh2_connect($this->host_ip);
     if ($this->ssh_connection == false) {
         $errorInfo = "Your ipaddress is error!\n";
         $this->logger->addLog("ssh connect", 0, $errorInfo, $host);
         throw new Exception(Utils::red("lines: 25, {$errorInfo}"));
         //__distruct();
     }
     $auth_ret = ssh2_auth_password($this->ssh_connection, $user, $pass);
     if ($auth_ret == false) {
         $errorInfo = "your username or password have not matched!";
         $this->logger->addLog("authentication", 0, $errorInfo, $host);
         throw new Exception(Utils::red("SSHHost.php:lines: 31, {$errorInfo}"));
         //__distruct();
     }
 }
コード例 #3
0
 private function checkIsSp($str)
 {
     $logger = GlobalLogger::getLoggerInstance();
     $reg = "/\\~|\\!|\\@|\\#|\\\$|\\%|\\^|\\&|\\*|\\(|\\)|\\+|\\{|\\}|\\:|\\<|\\>|\\?|\\[|\\]|\\,|\\;|\\'|\\`|\\-|\\=|\\\\|\\|/";
     if (preg_match($reg, $str)) {
         $error_info = "[ini file] : '{$str}' have special characters!";
         $logger->addLog("SP", 0, $error_info, NULL);
         $logger::close();
         echo Utils::red($error_info . "\n");
         return False;
     } else {
         return True;
     }
 }
コード例 #4
0
 public function __construct()
 {
     $this->welcomInformations();
     $backupTypeU = unserialize(BACKUP_TYPE);
     // init task manager.
     $this->backupLogger = GlobalLogger::getLoggerInstance();
     $this->backupDate = Utils::getDateInstance();
     $tmp_tasks = array();
     $taskManager = new TaskManager();
     $this->taskList = $taskManager->getTasks();
     $array_length = count($this->taskList);
     $num = 1;
     foreach ($this->taskList as $key => $task) {
         $credentialInitInfo = "\n----------------task credential init begin--------------" . "\n";
         $this->backupLogger->addLog('credential init', 100, $credentialInitInfo, $task->target_host_spec->getIp());
         //echo $credentialInitInfo;
         $task = $this->initialize_credential($task);
         $this->backupLogger->addLog('credential init', 100, "init....", $task->target_host_spec->getIp());
         $tmp_tasks[$key] = $task;
         $credentialInitEndInfo = "\n----------------task credential init end----------------" . "\n\n\n\n";
         $this->backupLogger->addLog('credential init', 100, $credentialInitEndInfo, $task->target_host_spec->getIp());
         //echo $credentialInitEndInfo;
         $num++;
         //print_r($tmp_tasks);
     }
     //print_r($tmp_tasks);
     if ($num < $array_length + 1 or $num == 1) {
         exit("your credential is not complete, please try again!\n");
     }
     $task_num = 1;
     print_r($tmp_tasks);
     while (1) {
         $total_timer = Utils::getTimer();
         $total_timer->start();
         foreach ($tmp_tasks as $task) {
             $timer = Utils::getTimer();
             $host_type = $task->target_host_spec->getHost_type();
             //echo $host_type . "\n";
             $hostManager = new HostManager();
             // srcHost
             $srcHost = $hostManager->get_host($host_type);
             //print_r($task->target_host_spec);
             $srcHost->hostSpec = $task->target_host_spec;
             $srcHost->hostCredential = $task->target_host_credential;
             // destHost
             $target_dest_ip = $task->target_host_spec->getBackup_dest_ip();
             $hostSpecManager = new HostSpecManager();
             $storageHostSpec = $hostSpecManager->querryHostSpecByHostIp($target_dest_ip);
             $storageHost = new DestHost();
             $storageHost->hostSpec = $storageHostSpec;
             $storageHost->storageCredential = $task->storage_credential;
             $backupTaskInfo = "\n\n-----------------backup task {$task_num} begin-----------------\n\n";
             echo "time: " . $timer->startTime;
             $this->backupLogger->addLog('backup task', 100, $backupTaskInfo, $srcHost->hostSpec->getIp());
             echo $backupTaskInfo;
             $backupHandlerManager = new BackupHandlerManager();
             $backupType = $this->getBackupType($srcHost);
             $db_inputs = array();
             if ($backupType == $backupTypeU[1]) {
                 echo "This is a MySQLdb backup ....\n";
                 $db_inputs = $this->getDBInput();
                 $srcHost->hostCredential->user_db = $db_inputs['username'];
                 $srcHost->hostCredential->password_db = $db_inputs['password'];
             }
             //"linux_mysqldb";
             $this->backupHandler = $backupHandlerManager->getBackupHandler($backupType);
             $createBackupInfo = "\n...backup handler create ok!...\n";
             $this->backupLogger->addLog("backup task", 100, $createBackupInfo, $srcHost->hostSpec->getIp());
             $beginBackupInfo = "\n...begin execute backup task!...\n";
             $this->backupLogger->addLog("backup task", 100, $beginBackupInfo, $srcHost->hostSpec->getIp());
             $begin_time = microtime(true);
             $timer->start();
             $this->backupHandler->execute($srcHost, $storageHost, $this->backupLogger);
             $timer->stop();
             echo "time: " . $timer->stopTime;
             $total_time = $timer->spent();
             echo "\nUsed time: " . $total_time . "\n\n";
             $endInfo = "\n-----------------backup task {$task_num} end-------------------\n\n\n\n\n";
             $this->backupLogger->addLog("backup task", 100, $endInfo, $srcHost->hostSpec->getIp());
             echo $endInfo;
             $task_num++;
         }
         $total_timer->stop();
         $spent_time = $total_timer->total_time_H();
         echo "\n\n ############# all time spent {$spent_time} H #############\n\n";
         if ($spent_time > 24) {
             echo "\nBigger than 24 hours.\n";
             $sleep_time = (48 - $spent_time) * 3600;
             echo "sleep {$spent_time} s";
             sleep($sleep_time);
         } elseif ($spent_time <= 24) {
             $sleep_time = (24 - $spent_time) * 3600;
             echo "sleep {$sleep_time} s";
             sleep($sleep_time);
         }
     }
 }