Exemplo n.º 1
0
 /**
  * runs backup process:
  * gets last backup info to identify if need to run new backup or continue precious
  * runs "makeBackup()"
  * 
  * @return type 
  */
 public function run()
 {
     TimezoneWork::set('UTC');
     It::debug("\n\n== STARTED MOVE DATABASE TO BACKUP ==", 'backup_database');
     $this->settings = Settings::model()->findByPk(1);
     /**
      * check if backup process is enabled */
     if (!$this->settings->db_exp_enabled) {
         It::debug("disabled", 'backup_database');
         return;
     } else {
         It::debug("enabled", 'backup_database');
     }
     /**
      * check time */
     $now = time();
     // Here we check if we should make backup
     $last_backup = BackupOldDataTx::getLastBackupInfo();
     // calculate date of the next backup
     $next_planned = strtotime($last_backup->backup_date) + $this->settings->db_exp_frequency * 86400;
     // exit if time not yet or prew backup not completed
     if ($next_planned >= $now and $last_backup->completed == 1) {
         It::debug("not time yet", 'backup_database');
         return;
     }
     /**
      * create new transaction */
     It::debug("create new transaction", 'backup_database');
     $last_backup = new BackupOldDataTx();
     $last_backup->backup_date = new CDbExpression('NOW()');
     $last_backup->data_timestamp_limit = date('Y-m-d 00:00:00', $now - $this->settings->db_exp_period * 86400);
     $last_backup->save();
     $this->current_backup = $last_backup;
     /**
      * add log */
     $this->addBackupLog("Need to Move Data stored before " . $last_backup->data_timestamp_limit . '; Date of backup: ' . $last_backup->backup_date . '; Frequency = ' . $this->settings->db_exp_frequency . '; ');
     It::debug("NOW = " . $now . " = " . date('Y-m-d H:i:s', $now), 'backup_database');
     It::debug("last backup (backup_frequency) = " . $this->settings->db_exp_frequency, 'backup_database');
     It::debug("last backup (id) = " . $last_backup->id, 'backup_database');
     It::debug("last backup (date of backup) = " . $last_backup->backup_date, 'backup_database');
     It::debug("last backup (data timestamp limit) = " . $last_backup->data_timestamp_limit, 'backup_database');
     It::debug("last backup (completed) = " . $last_backup->completed, 'backup_database');
     /**
      * make backup*/
     $this->makeBackup();
     //TODO: off delete row
 }