public static function get_history() { global $wpdb; $options = Sns_Option::get_options(); $limitBackups = $options[Sns_Option::COUNT]->value; $table = SNS_DB_PREFIX . 'backups'; $history = $wpdb->get_results("SELECT\n `id`,\n `type`,\n `info`,\n `backup_date`,\n `hash`,\n `filename`\n FROM {$table}\n ORDER BY `backup_date` DESC\n\t\t\t\t\t\t\t\t\t\t\tLIMIT {$limitBackups}", OBJECT_K); return $history; }
public function save() { global $wpdb; $table_name = SNS_DB_PREFIX . 'backups'; $options = Sns_Option::get_options(true); $option_list = array(); foreach ($options as $option => $data) { if ($option == Sns_Option::FULL) { $option_list = array($option); break; } if ($option != Sns_Option::COUNT) { $option_list[] = $option; } } $destination = new Sns_Destination($this->type); $destinations = $destination->get_destinations(); $destination_list = array(); foreach ($destinations as $name => $dst) { if ($dst->status == Sns_Destination::SET) { $destination_list[] = $name; } } $info = json_encode(array('options' => $option_list, 'destinations' => $destination_list)); $data = array('type' => $this->type, 'info' => $info, 'backup_date' => date('Y-m-d H:i:s'), 'hash' => $this->hash, 'filename' => $this->filename); $r = $wpdb->insert($table_name, $data); if ($r === false) { throw new Sns_Exception_DB_Error('Error on inserting into ' . $table_name . ' data: ' . json_encode($data)); } }
function sns_backup_manual_backup() { @set_time_limit(0); register_shutdown_function('sns_register_shutdown'); try { Sns_Log::log_msg('########PROCESS STARTED########' . PHP_EOL); $state = Sns_State::get_status(); if ($state['status'] == Sns_State::STATUS_ACTIVE) { throw new Sns_Exception_Unavailable_Operation('There is an existing active process.Please wait.'); } $stateData = array('status' => Sns_State::STATUS_ACTIVE, 'type' => Sns_State::TYPE_BACKUP, 'start_date' => date('Y-m-d H:i:s')); Sns_State::update($stateData); Sns_Checker::check(); $locations = isset($_POST['locations']) ? $_POST['locations'] : array(); $destination = new Sns_Destination(Sns_Backup::BACKUP_MODE_MANUAL); $destination->set_destinations($locations); $destination->save(); $backup = new Sns_Backup(Sns_Backup::BACKUP_MODE_MANUAL); Sns_State::$currentBackupFilename = $backup->getFilename(); $dest = 'local'; if (count($locations)) { $dest .= ',' . implode(',', array_keys($locations)); } $options = Sns_Option::get_options(true); foreach ($options as $option => $data) { if ($option == Sns_Option::FULL) { $option_list = array($option); break; } if ($option != Sns_Option::COUNT) { $option_list[] = $option; } } $options = implode(',', array_values($option_list)); $engLogDecription = '----------------------------------------------------'; $engLogDecription .= "\n" . ucfirst($stateData['type']) . ": " . $options; $engLogDecription .= "\nDestination: " . $dest . "\n"; $engLogDecription .= "----------------------------------------------------\n"; Sns_Log::log_msg($engLogDecription); Sns_Log::log_action('Backing up'); $warns = $backup->backup(); Sns_Log::log_action('Backing up', SNS_LOG_END); Sns_Log::log_msg("\n"); $skipped_files = ''; if (!empty($warns['not_readable'])) { $skipped_files .= '*********WARNING**********' . PHP_EOL; $skipped_files .= 'The following files are not readable and were excluded from backup package' . PHP_EOL; $i = 1; foreach ($warns['not_readable'] as $file) { $skipped_files .= $i . '. ' . $file . PHP_EOL; $i++; } Sns_Log::log_msg($skipped_files); } $stateData = array('status' => Sns_State::STATUS_FINISHED, 'type' => Sns_State::TYPE_BACKUP); Sns_State::update($stateData); Sns_Log::log_msg('########PROCESS ENDED########' . PHP_EOL); } catch (Exception $e) { Sns_Log::log_exception_obj($e); $ex_data = Sns_Exception_Handler::get_exception_data($e); $stateData = array('status' => Sns_State::STATUS_FAILED, 'type' => Sns_State::TYPE_BACKUP, 'msg' => $ex_data['status'] . ' : ' . $ex_data['msg']); Sns_State::update($stateData); Sns_Log::log_msg('########PROCESS ENDED########' . PHP_EOL); Sns_Log::report('backup'); } die; }