Ejemplo n.º 1
0
 public function run($args)
 {
     // don't run backup at the most busy minutes
     if (in_array(date('i'), array('00', '01', '15', '16', '30', '31', '45', '46'))) {
         return;
     }
     if (Yii::app()->mutex->lock('BackupOldData', 60 * 60)) {
         try {
             $obj = new BackupOldData();
             $obj->run();
         } catch (Exception $e) {
             It::debug('BackupOldDataCommand: backup old data process was failed: ' . $e->getMessage(), 'backup_database');
         }
         Yii::app()->mutex->unlock();
     }
 }
Ejemplo n.º 2
0
 /**
  * Copy old data from actula database to backup database
  * 
  * @param type $limit_timestamp 
  */
 private function copyDataBetweenDatabases($limit_timestamp)
 {
     $completed = true;
     $refresh_data = $this->updateMainStationInformation();
     if ($refresh_data) {
         $this->addBackupLog("Refresh info about stations, sensors, features.");
         foreach ($refresh_data as $sql) {
             $res = $this->db_conn->createCommand($sql)->query();
         }
     }
     // table 'listener_log' dependances
     $res = $this->prepareListenerLogInserts($limit_timestamp);
     $listener_log_ids = $res[0];
     $inserts_listener_log = $res[1];
     if (count($listener_log_ids)) {
         $inserts_listener_log_dependant = $this->prepareListenerLogDependantInserts($listener_log_ids);
         $completed = false;
     }
     // table 'listener' dependances
     $res = $this->prepareListenerInserts($limit_timestamp);
     $listener_ids = $res[0];
     $inserts_listener = $res[1];
     if (count($listener_ids)) {
         $inserts_listener_dependant = $this->prepareListenerDependantInserts($listener_ids);
         $completed = false;
     }
     if ($inserts_listener_log) {
         $res = $this->db_conn->createCommand($inserts_listener_log)->query();
         $completed = false;
     }
     if ($inserts_listener_log_dependant) {
         foreach ($inserts_listener_log_dependant as $sql) {
             $res = $this->db_conn->createCommand($sql)->query();
         }
         $completed = false;
     }
     if ($inserts_listener) {
         $res = $this->db_conn->createCommand($inserts_listener)->query();
     }
     if ($inserts_listener_dependant) {
         foreach ($inserts_listener_dependant as $sql) {
             $res = $this->db_conn->createCommand($sql)->query();
         }
     }
     if ($listener_ids) {
         $this->removeDataByIds('listener', $listener_ids);
     }
     if ($listener_log_ids) {
         $this->removeDataByIds('listener_log', $listener_log_ids);
     }
     if (count($listener_ids) >= 50 || count($listener_log_ids) >= 50) {
         $completed = false;
     }
     if ($completed) {
         $this->addBackupLog("Backup for this date is completed.");
         It::debug("copyDataBetweenDatabases (19)", 'backup_database');
         $res = $this->removeDataBeforeDate($limit_timestamp);
         It::debug("copyDataBetweenDatabases (20)", 'backup_database');
         $this->current_backup->completed = '1';
         $this->current_backup->save();
     } else {
         $this->addBackupLog("Backup for this date is not completed yet. Continue in a few minutes.");
     }
 }