コード例 #1
0
 public function __construct()
 {
     try {
         $conf_arr = $this->readTaskConfig(TASK_PATH);
     } catch (Exception $e) {
         echo "except: " . $e->getMessage();
     }
     foreach ($conf_arr as $key => $value) {
         $task = new Task();
         $task->setTask_desc($value["task_desc"]);
         $task->setTask_serial_no($value["task_serial_no"]);
         $hostSpecManager = new HostSpecManager();
         //print_r($value['target_host_spec']);
         //print_r($hostSpecManager->querryHostSpecByKey($value['target_host_spec']));
         $task->setTarget_host_spec($hostSpecManager->querryHostSpecByKey($value["target_host_spec"]));
         $credManager = new CredentialManager();
         $task->setTarget_host_credential($credManager->querryCredentialByKey($value['target_host_credential']));
         $task->setStorage_credential($credManager->querryCredentialByKey($value['storage_credential']));
         $this->tasks[$key] = $task;
     }
 }
コード例 #2
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);
         }
     }
 }