Esempio n. 1
0
/**
 *	get_archives_list()
 *
 *	Returns an array of backup archive zip filenames found.
 *
 *	@return		array		Array of .zip filenames; path NOT included.
 */
function get_archives_list()
{
    Auth::require_authentication();
    if (!isset(pb_backupbuddy::$classes['zipbuddy'])) {
        require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
        pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy(ABSPATH);
    }
    // List backup files in this directory.
    $backup_archives = array();
    $backup_archives_glob = glob(ABSPATH . 'backup*.zip');
    if (!is_array($backup_archives_glob) || empty($backup_archives_glob)) {
        // On failure glob() returns false or an empty array depending on server settings so normalize here.
        $backup_archives_glob = array();
    }
    foreach ($backup_archives_glob as $backup_archive) {
        $comment = pb_backupbuddy::$classes['zipbuddy']->get_comment($backup_archive);
        $comment = backupbuddy_core::normalize_comment_data($comment);
        $this_archive = array('file' => basename($backup_archive), 'comment' => $comment);
        $backup_archives[] = $this_archive;
    }
    unset($backup_archives_glob);
    return $backup_archives;
}
Esempio n. 2
0
 public static function getZipMeta($file)
 {
     if (!isset(pb_backupbuddy::$classes['zipbuddy'])) {
         require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
         pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy(backupbuddy_core::getBackupDirectory());
     }
     $comment_meta = array();
     if (isset($file)) {
         $comment = pb_backupbuddy::$classes['zipbuddy']->get_comment($file);
         $comment = backupbuddy_core::normalize_comment_data($comment);
         $comment_meta = array();
         foreach ($comment as $comment_line_name => $comment_line_value) {
             // Loop through all meta fields in the comment array to display.
             if (false !== ($response = backupbuddy_core::pretty_meta_info($comment_line_name, $comment_line_value))) {
                 $response[0] = '<span title="' . $comment_line_name . '">' . $response[0] . '</span>';
                 $comment_meta[$comment_line_name] = $response;
             }
         }
     }
     if (count($comment_meta) > 0) {
         return $comment_meta;
     } else {
         return false;
     }
 }
 protected function backup_zip_files_alternate($state = array())
 {
     // Dependent on the zip build strategy chosen we will need to set various operational
     // parameters on the zipbuddy object to be used by the method building the zip. Eventually
     // we can use strategy objects but for now we'll do it the old-fashioned way.
     // Strategies are:
     // Single-Burst/Single-Step: Step Period = Infinite; Min/Max Burst Content Size = Infinite;
     // Multi-Burst/Single-Step: Step Period = Infinite; Min/Max Burst Content Size = Per-Config;
     // Multi-Burst/Multi-Step: Step Period = Per-Config; Min/Max Burst Content Size = Per-Config;
     $zip_build_strategy_name = array(self::ZIP_BUILD_STRATEGY_SBSS => 'Single-Burst/Single-Step', self::ZIP_BUILD_STRATEGY_MBSS => 'Multi-Burst/Single-Step', self::ZIP_BUILD_STRATEGY_MBMS => 'Multi-Burst/Multi-Step');
     // Get the current strategy
     if (isset(pb_backupbuddy::$options['zip_build_strategy'])) {
         $zip_build_strategy = pb_backupbuddy::$options['zip_build_strategy'];
         if (self::ZIP_BUILD_STRATEGY_MIN > $zip_build_strategy || self::ZIP_BUILD_STRATEGY_MAX < $zip_build_strategy) {
             // Hmm, not valid - have to revert to default
             $zip_build_strategy = self::ZIP_BUILD_STRATEGY_MBSS;
             pb_backupbuddy::status('details', 'Zip Build Strategy not recognized - reverting to: ' . $zip_build_strategy_name[$zip_build_strategy]);
         } else {
             pb_backupbuddy::status('details', 'Zip Build Strategy: ' . $zip_build_strategy_name[$zip_build_strategy]);
         }
     } else {
         // Hmm, should be set - have to revert to default
         $zip_build_strategy = self::ZIP_BUILD_STRATEGY_MBSS;
         pb_backupbuddy::status('details', 'Zip Build Strategy not set - reverting to: ' . $zip_build_strategy_name[$zip_build_strategy]);
     }
     // Now we haev to check if running in Classic mode. If yes then we cannot use multi-step without continually
     // resetting the "start" time for the zip monitor. The better approach is to override the zip build strategy
     // if it is a multi-step strategy and at least revert it to multi-burst/single-step. If it is already this
     // or single-burst/single-step we can leave it as it is
     // The backup mode details _should_ be available through this class variable created in pre_backup() function.
     if ($this->_backup['profile']['backup_mode'] == '1') {
         // Running in Classic mode...
         if (self::ZIP_BUILD_STRATEGY_MBSS < $zip_build_strategy) {
             $zip_build_strategy = self::ZIP_BUILD_STRATEGY_MBSS;
             pb_backupbuddy::status('details', 'Zip Build Strategy overridden as incompatible with Classic backup mode - reverting to: ' . $zip_build_strategy_name[$zip_build_strategy]);
         }
     }
     // Now based on the stratgy set build parameters that we will set on the zipbuddy object that
     // define the zip build behaviour
     switch ($zip_build_strategy) {
         case self::ZIP_BUILD_STRATEGY_SBSS:
             $step_period = PHP_INT_MAX;
             // Effectively infinite
             $burst_min_content = 4 == PHP_INT_SIZE ? (double) (pow(2, 63) - 1) : (double) PHP_INT_MAX;
             // Hack to get large value for either 32 or 64 bit PHP
             $burst_max_content = 4 == PHP_INT_SIZE ? (double) (pow(2, 63) - 1) : (double) PHP_INT_MAX;
             break;
         case self::ZIP_BUILD_STRATEGY_MBSS:
             $step_period = PHP_INT_MAX;
             $burst_min_content = null;
             $burst_max_content = null;
             break;
         case self::ZIP_BUILD_STRATEGY_MBMS:
             $step_period = null;
             // Force the option value to be used
             $burst_min_content = null;
             $burst_max_content = null;
             break;
     }
     // We can set the values on the zipbuddy object at this point
     pb_backupbuddy::$classes['zipbuddy']->set_step_period($step_period);
     pb_backupbuddy::$classes['zipbuddy']->set_min_burst_content($burst_min_content);
     pb_backupbuddy::$classes['zipbuddy']->set_max_burst_content($burst_max_content);
     if (empty($state)) {
         // This is our first (and perhaps only) call, so do first time stuff
         pb_backupbuddy::status('milestone', 'start_files');
         pb_backupbuddy::status('details', 'Backup root: `' . $this->_backup['backup_root'] . '`.');
         // Set compression on / off.
         //pb_backupbuddy::$classes['zipbuddy']->set_compression( $this->_backup['compression'] );
         // Currently we'll still allow skipping the addition of the meta data in the comment
         // but eventually this will become mandatory (in al likelihood)
         // Save meta information in comment.
         if ('0' == pb_backupbuddy::$options['save_comment_meta']) {
             pb_backupbuddy::status('details', 'Skipping saving meta data to zip comment based on settings.');
             $comment = '';
         } else {
             pb_backupbuddy::status('details', 'Saving meta data to zip comment.');
             // Calculate some statistics to store in meta later. These need to be calculated before zipping in case the DB goes away later to prevent a possible failure.
             $totalPosts = 0;
             foreach (wp_count_posts('post') as $type => $count) {
                 $totalPosts += $count;
             }
             $totalPages = 0;
             foreach (wp_count_posts('page') as $type => $count) {
                 $totalPages += $count;
             }
             $totalComments = 0;
             foreach (wp_count_comments() as $type => $count) {
                 $totalComments += $count;
             }
             $totalUsers = count_users();
             $totalUsers = $totalUsers['total_users'];
             global $wpdb;
             $db_prefix = $wpdb->prefix;
             global $wp_version;
             $meta = array('serial' => $this->_backup['serial'], 'siteurl' => site_url(), 'type' => $this->_backup['type'], 'profile' => $this->_backup['profile']['title'], 'created' => $this->_backup['start_time'], 'db_prefix' => $db_prefix, 'bb_version' => pb_backupbuddy::settings('version'), 'wp_version' => $wp_version, 'dat_path' => str_replace($this->_backup['backup_root'], '', $this->_backup['temp_directory'] . 'backupbuddy_dat.php'), 'posts' => $totalPosts, 'pages' => $totalPages, 'comments' => $totalComments, 'users' => $totalUsers, 'note' => '');
             $comment = backupbuddy_core::normalize_comment_data($meta);
         }
         // Always create the empty zip archive with the optional meta data comment added at this point.
         // This is method independent so is done just in zipbuddy.
         $zip_response = pb_backupbuddy::$classes['zipbuddy']->create_empty_zip($this->_backup['archive_file'], $this->_backup['temporary_zip_directory'], $comment);
         if (false === $zip_response) {
             // Delete temporary data directory.
             if (file_exists($this->_backup['temp_directory'])) {
                 pb_backupbuddy::status('details', __('Removing temp data directory.', 'it-l10n-backupbuddy'));
                 pb_backupbuddy::$filesystem->unlink_recursive($this->_backup['temp_directory']);
             }
             // Delete temporary ZIP directory.
             if (file_exists($this->_backup['temporary_zip_directory'])) {
                 pb_backupbuddy::status('details', __('Removing temp zip directory.', 'it-l10n-backupbuddy'));
                 pb_backupbuddy::$filesystem->unlink_recursive($this->_backup['temporary_zip_directory']);
             }
             pb_backupbuddy::status('error', __('Error #4001: Unable to successfully generate ZIP archive. Backup FAILED. See logs above for more information.', 'it-l10n-backupbuddy'));
             pb_backupbuddy::status('haltScript', '');
             // Halt JS on page.
             return false;
         }
         // Create zip file!
         $zip_response = pb_backupbuddy::$classes['zipbuddy']->add_directory_to_zip($this->_backup['archive_file'], $this->_backup['backup_root'], $this->_backup['directory_exclusions'], $this->_backup['temporary_zip_directory']);
         // Zip results.
         if ($zip_response === true) {
             // Zip success.
             pb_backupbuddy::status('message', __('Backup ZIP file successfully created.', 'it-l10n-backupbuddy'));
             if (chmod($this->_backup['archive_file'], 0644)) {
                 pb_backupbuddy::status('details', __('Chmod of ZIP file to 0644 succeeded.', 'it-l10n-backupbuddy'));
             } else {
                 pb_backupbuddy::status('details', __('Chmod of ZIP file to 0644 failed.', 'it-l10n-backupbuddy'));
             }
         } elseif (is_array($zip_response)) {
             // First step returned a continuation state so we only do some stuff and then queue
             // a continuation step
             // Now recover the returned state and queue the next step.
             $newStep = array('function' => 'backup_zip_files', 'args' => array($zip_response), 'start_time' => 0, 'finish_time' => 0, 'attempts' => 0);
             //error_log( print_r( $this->_backup_options->options['steps'], true ) );
             array_splice($this->_backup_options->options['steps'], $this->_currentStepIndex + 1, 0, array($newStep));
             //error_log( print_r( $this->_backup_options->options['steps'], true ) );
             $this->_backup_options->save();
             pb_backupbuddy::status('details', 'Inserted additional zip grow step at `' . ($this->_currentStepIndex + 1) . '` to resume at index `' . $zip_response['zipper']['fp'] . '`. The next chunk will proceed shortly.');
         } else {
             // Zip failure.
             // Delete temporary data directory.
             if (file_exists($this->_backup['temp_directory'])) {
                 pb_backupbuddy::status('details', __('Removing temp data directory.', 'it-l10n-backupbuddy'));
                 pb_backupbuddy::$filesystem->unlink_recursive($this->_backup['temp_directory']);
             }
             // Delete temporary ZIP directory.
             if (file_exists($this->_backup['temporary_zip_directory'])) {
                 pb_backupbuddy::status('details', __('Removing temp zip directory.', 'it-l10n-backupbuddy'));
                 pb_backupbuddy::$filesystem->unlink_recursive($this->_backup['temporary_zip_directory']);
             }
             pb_backupbuddy::status('error', __('Error #4001: Unable to successfully generate ZIP archive. Backup FAILED. See logs above for more information.', 'it-l10n-backupbuddy'));
             pb_backupbuddy::status('haltScript', '');
             // Halt JS on page.
             return false;
         }
         // end zip failure.
     } else {
         // Continuation step with a state
         $zip_response = pb_backupbuddy::$classes['zipbuddy']->grow_zip($this->_backup['archive_file'], $this->_backup['temporary_zip_directory'], $state);
         if ($zip_response === true) {
             // Zip success.
             pb_backupbuddy::status('message', __('Backup ZIP file successfully created.', 'it-l10n-backupbuddy'));
             if (chmod($this->_backup['archive_file'], 0644)) {
                 pb_backupbuddy::status('details', __('Chmod of ZIP file to 0644 succeeded.', 'it-l10n-backupbuddy'));
             } else {
                 pb_backupbuddy::status('details', __('Chmod of ZIP file to 0644 failed.', 'it-l10n-backupbuddy'));
             }
         } elseif (is_array($zip_response)) {
             // First step returned a continuation state so we only do some stuff and then queue
             // a continuation step
             // Now recover the returned state and queue the next step.
             $newStep = array('function' => 'backup_zip_files', 'args' => array($zip_response), 'start_time' => 0, 'finish_time' => 0, 'attempts' => 0);
             //error_log( print_r( $this->_backup_options->options['steps'], true ) );
             array_splice($this->_backup_options->options['steps'], $this->_currentStepIndex + 1, 0, array($newStep));
             //error_log( print_r( $this->_backup_options->options['steps'], true ) );
             $this->_backup_options->save();
             pb_backupbuddy::status('details', 'Inserted additional zip grow step at `' . ($this->_currentStepIndex + 1) . '` to resume at index `' . $zip_response['zipper']['fp'] . '`. The next chunk will proceed shortly.');
         } else {
             // Zip failure.
             // Delete temporary data directory.
             if (file_exists($this->_backup['temp_directory'])) {
                 pb_backupbuddy::status('details', __('Removing temp data directory.', 'it-l10n-backupbuddy'));
                 pb_backupbuddy::$filesystem->unlink_recursive($this->_backup['temp_directory']);
             }
             // Delete temporary ZIP directory.
             if (file_exists($this->_backup['temporary_zip_directory'])) {
                 pb_backupbuddy::status('details', __('Removing temp zip directory.', 'it-l10n-backupbuddy'));
                 pb_backupbuddy::$filesystem->unlink_recursive($this->_backup['temporary_zip_directory']);
             }
             pb_backupbuddy::status('error', __('Error #4001: Unable to successfully generate ZIP archive. Backup FAILED. See logs above for more information.', 'it-l10n-backupbuddy'));
             pb_backupbuddy::status('haltScript', '');
             // Halt JS on page.
             return false;
         }
         // end zip failure.
     }
     // Need to make sure the database connection is active. Sometimes it goes away during long bouts doing other things -- sigh.
     // This is not essential so use include and not require (suppress any warning)
     @(include_once pb_backupbuddy::plugin_path() . '/lib/wpdbutils/wpdbutils.php');
     if (class_exists('pluginbuddy_wpdbutils')) {
         // This is the database object we want to use
         global $wpdb;
         // Get our helper object and let it use us to output status messages
         $dbhelper = new pluginbuddy_wpdbutils($wpdb);
         // If we cannot kick the database into life then signal the error and return false which will stop the backup
         // Otherwise all is ok and we can just fall through and let the function return true
         if (!$dbhelper->kick()) {
             pb_backupbuddy::status('error', __('Backup FAILED. Backup file produced but Database Server has gone away, unable to schedule next backup step', 'it-l10n-backupbuddy'));
             return false;
         } else {
             //pb_backupbuddy::status( 'details', 'Database seems to still be connected.' );
         }
     } else {
         // Utils not available so cannot verify database connection status - just notify
         pb_backupbuddy::status('details', __('Database Server connection status unverified.', 'it-l10n-backupbuddy'));
     }
     return $zip_response;
 }
Esempio n. 4
0
 public function set_backup_note()
 {
     if (!isset(pb_backupbuddy::$classes['zipbuddy'])) {
         require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
         pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy(backupbuddy_core::getBackupDirectory());
     }
     $backup_file = backupbuddy_core::getBackupDirectory() . pb_backupbuddy::_POST('backup_file');
     $note = pb_backupbuddy::_POST('note');
     $note = preg_replace("/[[:space:]]+/", ' ', $note);
     $note = preg_replace("/[^[:print:]]/", '', $note);
     $note = substr($note, 0, 200);
     // Returns true on success, else the error message.
     $old_comment = pb_backupbuddy::$classes['zipbuddy']->get_comment($backup_file);
     $comment = backupbuddy_core::normalize_comment_data($old_comment);
     $comment['note'] = $note;
     //$new_comment = base64_encode( serialize( $comment ) );
     $comment_result = pb_backupbuddy::$classes['zipbuddy']->set_comment($backup_file, $comment);
     if ($comment_result !== true) {
         echo $comment_result;
     } else {
         echo '1';
     }
     // Even if we cannot save the note into the archive file, store it in internal settings.
     $serial = backupbuddy_core::get_serial_from_file($backup_file);
     require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
     $backup_options = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt');
     if (true === ($result = $backup_options->is_ok())) {
         $backup_options->options['integrity']['comment'] = $note;
         $backup_options->save();
     }
     die;
 }
$backup_type = '';
if (!isset(pb_backupbuddy::$classes['zipbuddy'])) {
    require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
    pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy(backupbuddy_core::getBackupDirectory());
}
$previous_status_serial = pb_backupbuddy::get_status_serial();
// Store current status serial setting to reset back later.
if (true !== $skipLogRedirect) {
    pb_backupbuddy::status('details', 'Redirecting status logging temporarily.');
    pb_backupbuddy::set_status_serial('zipbuddy_test');
    // Redirect logging output to a certain log file.
}
// Look for comment.
pb_backupbuddy::status('details', 'Verifying comment in zip archive.');
$raw_comment = pb_backupbuddy::$classes['zipbuddy']->get_comment($file);
$comment = backupbuddy_core::normalize_comment_data($raw_comment);
$comment = $comment['note'];
$tests = array();
pb_backupbuddy::status('details', 'NOTE: It is normal to see several "File not found" messages in the next several log lines.');
// Check for DAT file.
$pass = false;
pb_backupbuddy::status('details', 'Verifying DAT file in zip archive.');
if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'wp-content/uploads/backupbuddy_temp/' . $serial . '/backupbuddy_dat.php') === true) {
    // Post 2.0 full backup
    $backup_type = 'full';
    $pass = true;
}
if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'wp-content/uploads/temp_' . $serial . '/backupbuddy_dat.php') === true) {
    // Pre 2.0 full backup
    $backup_type = 'full';
    $pass = true;
Esempio n. 6
0
 function backup_zip_files()
 {
     pb_backupbuddy::status('action', 'start_files');
     pb_backupbuddy::status('details', 'Backup root: `' . $this->_backup['backup_root'] . '`.');
     // Set compression on / off.
     //pb_backupbuddy::$classes['zipbuddy']->set_compression( $this->_backup['compression'] );
     // Create zip file!
     $zip_response = pb_backupbuddy::$classes['zipbuddy']->add_directory_to_zip($this->_backup['archive_file'], $this->_backup['backup_root'], $this->_backup['directory_exclusions'], $this->_backup['temporary_zip_directory']);
     // Zip results.
     if ($zip_response === true) {
         // Zip success.
         pb_backupbuddy::status('message', __('Backup ZIP file successfully created.', 'it-l10n-backupbuddy'));
         if (chmod($this->_backup['archive_file'], 0644)) {
             pb_backupbuddy::status('details', __('Chmod of ZIP file to 0644 succeeded.', 'it-l10n-backupbuddy'));
         } else {
             pb_backupbuddy::status('details', __('Chmod of ZIP file to 0644 failed.', 'it-l10n-backupbuddy'));
         }
         // Save meta information in comment.
         if ('0' == pb_backupbuddy::$options['save_comment_meta']) {
             pb_backupbuddy::status('details', 'Skipping saving meta data to zip comment based on settings.');
         } else {
             pb_backupbuddy::status('details', 'Saving meta data to zip comment.');
             $totalPosts = 0;
             foreach (wp_count_posts('post') as $type => $count) {
                 $totalPosts += $count;
             }
             $totalPages = 0;
             foreach (wp_count_posts('page') as $type => $count) {
                 $totalPages += $count;
             }
             $totalComments = 0;
             foreach (wp_count_comments() as $type => $count) {
                 $totalComments += $count;
             }
             $totalUsers = count_users();
             $totalUsers = $totalUsers['total_users'];
             global $wp_version;
             global $wpdb;
             $meta = array('serial' => $this->_backup['serial'], 'siteurl' => site_url(), 'type' => $this->_backup['type'], 'profile' => $this->_backup['profile']['title'], 'created' => $this->_backup['start_time'], 'db_prefix' => $wpdb->prefix, 'bb_version' => pb_backupbuddy::settings('version'), 'wp_version' => $wp_version, 'dat_path' => str_replace($this->_backup['backup_root'], '', $this->_backup['temp_directory'] . 'backupbuddy_dat.php'), 'posts' => $totalPosts, 'pages' => $totalPages, 'comments' => $totalComments, 'users' => $totalUsers, 'note' => '');
             $comment = backupbuddy_core::normalize_comment_data($meta);
             $comment_result = pb_backupbuddy::$classes['zipbuddy']->set_comment($this->_backup['archive_file'], $comment);
             if ($comment_result !== true) {
                 pb_backupbuddy::status('warning', 'Unable to save meta data to zip comment. This is not a fatal warning & will not impact the backup itself.');
             } else {
                 pb_backupbuddy::status('details', 'Saved meta data to zip comment.');
             }
         }
     } else {
         // Zip failure.
         // Delete temporary data directory.
         if (file_exists($this->_backup['temp_directory'])) {
             pb_backupbuddy::status('details', __('Removing temp data directory.', 'it-l10n-backupbuddy'));
             pb_backupbuddy::$filesystem->unlink_recursive($this->_backup['temp_directory']);
         }
         // Delete temporary ZIP directory.
         if (file_exists($this->_backup['temporary_zip_directory'])) {
             pb_backupbuddy::status('details', __('Removing temp zip directory.', 'it-l10n-backupbuddy'));
             pb_backupbuddy::$filesystem->unlink_recursive($this->_backup['temporary_zip_directory']);
         }
         pb_backupbuddy::status('error', __('Error #3382: Backup FAILED. Unable to successfully generate ZIP archive.', 'it-l10n-backupbuddy'));
         pb_backupbuddy::status('error', __('Error #3382 help: http://ithemes.com/codex/page/BackupBuddy:_Error_Codes#3382', 'it-l10n-backupbuddy'));
         pb_backupbuddy::status('action', 'halt_script');
         // Halt JS on page.
         return false;
     }
     // end zip failure.
     // Need to make sure the database connection is active. Sometimes it goes away during long bouts doing other things -- sigh.
     // This is not essential so use include and not require (suppress any warning)
     pb_backupbuddy::status('details', 'Loading DB kicker in case database has gone away.');
     @(include_once pb_backupbuddy::plugin_path() . '/lib/wpdbutils/wpdbutils.php');
     if (class_exists('pluginbuddy_wpdbutils')) {
         // This is the database object we want to use
         global $wpdb;
         // Get our helper object and let it use us to output status messages
         $dbhelper = new pluginbuddy_wpdbutils($wpdb);
         // If we cannot kick the database into life then signal the error and return false which will stop the backup
         // Otherwise all is ok and we can just fall through and let the function return true
         if (!$dbhelper->kick()) {
             pb_backupbuddy::status('error', __('Backup FAILED. Backup file produced but Database Server has gone away, unable to schedule next backup step', 'it-l10n-backupbuddy'));
             return false;
         } else {
             pb_backupbuddy::status('details', 'Database seems to still be connected.');
         }
     } else {
         // Utils not available so cannot verify database connection status - just notify
         pb_backupbuddy::status('details', __('Database Server connection status unverified.', 'it-l10n-backupbuddy'));
     }
     return true;
 }
Esempio n. 7
0
 public function integrity_status()
 {
     $serial = pb_backupbuddy::_GET('serial');
     $serial = str_replace('/\\', '', $serial);
     pb_backupbuddy::load();
     pb_backupbuddy::$ui->ajax_header();
     // Backup overall status.
     /*
     echo 'Backup status: ';
     if ( $integrity['status'] == 'pass' ) { // Pass.
     	echo '<span class="pb_label pb_label-success">Good</span>';
     } else { // Fail.
     	echo '<span class="pb_label pb_label-important">Bad</span>';
     }
     echo '<br>';
     */
     require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
     $backup_options = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt', $read_only = true);
     if (true !== ($result = $backup_options->is_ok())) {
         pb_backupbuddy::alert(__('Unable to access fileoptions data file.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
         die;
     }
     $integrity = $backup_options->options['integrity'];
     echo '<p><b>' . __('Backup File', 'it-l10n-backupbuddy') . '</b>: ' . $integrity['file'] . '</p>';
     $start_time = 'Unknown';
     $finish_time = 'Unknown';
     if (isset($backup_options->options['start_time'])) {
         $start_time = pb_backupbuddy::$format->date(pb_backupbuddy::$format->localize_time($backup_options->options['start_time'])) . ' <span class="description">(' . pb_backupbuddy::$format->time_ago($backup_options->options['finish_time']) . ' ago)</span>';
         if ($backup_options->options['finish_time'] > 0) {
             $finish_time = pb_backupbuddy::$format->date(pb_backupbuddy::$format->localize_time($backup_options->options['finish_time'])) . ' <span class="description">(' . pb_backupbuddy::$format->time_ago($backup_options->options['finish_time']) . ' ago)</span>';
         } else {
             // unfinished.
             $finish_time = '<i>Unfinished</i>';
         }
     }
     //***** BEGIN TESTS AND RESULTS.
     if (isset($integrity['status_details'])) {
         // $integrity['status_details'] is NOT array (old, pre-3.1.9).
         echo '<h3>Integrity Technical Details</h3>';
         echo '<textarea style="width: 100%; height: 175px;" wrap="off">';
         foreach ($integrity as $item_name => $item_value) {
             $item_value = str_replace('<br />', '<br>', $item_value);
             $item_value = str_replace('<br><br>', '<br>', $item_value);
             $item_value = str_replace('<br>', "\n     ", $item_value);
             echo $item_name . ' => ' . $item_value . "\n";
         }
         echo '</textarea><br><br><b>Note:</b> It is normal to see several "file not found" entries as BackupBuddy checks for expected files in multiple locations, expecting to only find each file once in one of those locations.';
     } else {
         // $integrity['status_details'] is array.
         echo '<br>';
         if (isset($integrity['status_details'])) {
             // PRE-v4.0 Tests.
             function pb_pretty_results($value)
             {
                 if ($value === true) {
                     return '<span class="pb_label pb_label-success">Pass</span>';
                 } else {
                     return '<span class="pb_label pb_label-important">Fail</span>';
                 }
             }
             // The tests & their status..
             $tests = array();
             $tests[] = array('BackupBackup data file exists', pb_pretty_results($integrity['status_details']['found_dat']));
             $tests[] = array('Database SQL file exists', pb_pretty_results($integrity['status_details']['found_sql']));
             if ($integrity['detected_type'] == 'full') {
                 // Full backup.
                 $tests[] = array('WordPress wp-config.php exists (full/files backups only)', pb_pretty_results($integrity['status_details']['found_wpconfig']));
             } elseif ($integrity['detected_type'] == 'files') {
                 // Files only backup.
                 $tests[] = array('WordPress wp-config.php exists (full/files backups only)', pb_pretty_results($integrity['status_details']['found_wpconfig']));
             } else {
                 // DB only.
                 $tests[] = array('WordPress wp-config.php exists (full/files backups only)', '<span class="pb_label pb_label-success">N/A</span>');
             }
         } else {
             // 4.0+ Tests.
             $tests = array();
             foreach ((array) $integrity['tests'] as $test) {
                 if (true === $test['pass']) {
                     $status_text = '<span class="pb_label pb_label-success">Pass</span>';
                 } else {
                     $status_text = '<span class="pb_label pb_label-important">Fail</span>';
                 }
                 $tests[] = array($test['test'], $status_text);
             }
         }
         $columns = array(__('Integrity Test', 'it-l10n-backupbuddy'), __('Status', 'it-l10n-backupbuddy'));
         pb_backupbuddy::$ui->list_table($tests, array('columns' => $columns, 'css' => 'width: 100%; min-width: 200px;'));
     }
     // end $integrity['status_details'] is an array.
     //***** END TESTS AND RESULTS.
     echo '<br><br>';
     //***** BEGIN STEPS.
     $steps = array();
     $steps[] = array('Start Time', $start_time, '');
     if (isset($backup_options->options['steps'])) {
         foreach ($backup_options->options['steps'] as $step) {
             if (isset($step['finish_time']) && $step['finish_time'] != 0) {
                 // Step name.
                 if ($step['function'] == 'backup_create_database_dump') {
                     if (count($step['args'][0]) == 1) {
                         $step_name = 'Database dump (breakout: ' . $step['args'][0][0] . ')';
                     } else {
                         $step_name = 'Database dump';
                     }
                 } elseif ($step['function'] == 'backup_zip_files') {
                     if (isset($backup_options->options['steps']['backup_zip_files'])) {
                         $zip_time = $backup_options->options['steps']['backup_zip_files'];
                     } else {
                         $zip_time = 0;
                     }
                     // Calculate write speed in MB/sec for this backup.
                     if ($zip_time == '0') {
                         // Took approx 0 seconds to backup so report this speed.
                         $write_speed = '> ' . pb_backupbuddy::$format->file_size($backup_options->options['integrity']['size']);
                     } else {
                         if ($zip_time == 0) {
                             $write_speed = '';
                         } else {
                             $write_speed = pb_backupbuddy::$format->file_size($backup_options->options['integrity']['size'] / $zip_time) . '/sec';
                         }
                     }
                     $step_name = 'Zip archive creation (Write speed: ' . $write_speed . ')';
                 } elseif ($step['function'] == 'post_backup') {
                     $step_name = 'Post-backup cleanup';
                 } elseif ($step['function'] == 'integrity_check') {
                     $step_name = 'Integrity Check';
                 } else {
                     $step_name = $step['function'];
                 }
                 // Step time taken.
                 $step_time = (string) ($step['finish_time'] - $step['start_time']) . ' seconds';
                 // Compile details for this step into array.
                 $steps[] = array($step_name, $step_time, $step['attempts']);
             }
         }
         // End foreach.
     } else {
         // End if serial in array is set.
         $step_times[] = 'unknown';
     }
     // End if serial in array is NOT set.
     // Total overall time from initiation to end.
     if (isset($backup_options->options['finish_time']) && isset($backup_options->options['start_time']) && $backup_options->options['finish_time'] != 0 && $backup_options->options['start_time'] != 0) {
         $total_time = $backup_options->options['finish_time'] - $backup_options->options['start_time'] . ' seconds';
     } else {
         $total_time = '<i>Unknown</i>';
     }
     $steps[] = array('Finish Time', $finish_time, '');
     $steps[] = array('<b>Total Overall Time</b>', $total_time, '');
     $columns = array(__('Backup', 'it-l10n-backupbuddy'), __('Time', 'it-l10n-backupbuddy'), __('Attempts', 'it-l10n-backupbuddy'));
     if (count($steps) == 0) {
         _e('No step statistics were found for this backup.', 'it-l10n-backupbuddy');
     } else {
         pb_backupbuddy::$ui->list_table($steps, array('columns' => $columns, 'css' => 'width: 100%; min-width: 200px;'));
     }
     echo '<br><br>';
     //***** END STEPS.
     //***** BEGIN COMMENT META.
     if (!isset(pb_backupbuddy::$classes['zipbuddy'])) {
         require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
         pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy(backupbuddy_core::getBackupDirectory());
     }
     $comment_meta = array();
     if (isset($backup_options->options['archive_file'])) {
         $comment = pb_backupbuddy::$classes['zipbuddy']->get_comment($backup_options->options['archive_file']);
         $comment = backupbuddy_core::normalize_comment_data($comment);
         $comment_meta = array();
         foreach ($comment as $comment_line_name => $comment_line_value) {
             // Loop through all meta fields in the comment array to display.
             if (false !== ($response = backupbuddy_core::pretty_meta_info($comment_line_name, $comment_line_value))) {
                 $comment_meta[] = $response;
             }
         }
     }
     if (count($comment_meta) > 0) {
         pb_backupbuddy::$ui->list_table($comment_meta, array('columns' => array('Meta Information', 'Value'), 'css' => 'width: 100%; min-width: 200px;'));
     } else {
         echo '<i>No meta data found in zip comment. Skipping meta information display.</i>';
     }
     //***** END COMMENT META.
     if (isset($backup_options->options['trigger'])) {
         $trigger = $backup_options->options['trigger'];
     } else {
         $trigger = 'Unknown trigger';
     }
     $scanned = pb_backupbuddy::$format->date($integrity['scan_time']);
     echo '<br><br>';
     echo ucfirst($trigger) . " backup {$integrity['file']} last scanned {$scanned}.";
     echo '<br><br><br>';
     echo '<a class="button secondary-button" onclick="jQuery(\'#pb_backupbuddy_advanced_debug\').slideToggle();">Display Advanced Debugging</a>';
     echo '<div id="pb_backupbuddy_advanced_debug" style="display: none;">';
     echo '<textarea style="width: 100%; height: 400px;" wrap="on">';
     echo print_r($backup_options->options, true);
     echo '</textarea><br><br>';
     echo '</div><br><br>';
     pb_backupbuddy::$ui->ajax_footer();
     die;
 }
Esempio n. 8
0
/**
 *	extract()
 *
 *	Extract backup zip file.
 *
 *	@return		array		True if the extraction was a success OR skipping of extraction is set.
 */
function extract_files()
{
    // Zip & Unzip library setup.
    require_once ABSPATH . 'importbuddy/lib/zipbuddy/zipbuddy.php';
    pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy(ABSPATH, array(), 'unzip');
    $backup_archive = ABSPATH . pb_backupbuddy::$options['file'];
    if (true === pb_backupbuddy::$options['skip_files']) {
        // Option to skip all file updating / extracting.
        pb_backupbuddy::status('message', 'Skipped extracting files based on debugging options.');
    } else {
        pb_backupbuddy::set_greedy_script_limits();
        pb_backupbuddy::status('message', 'Unzipping into `' . ABSPATH . '`');
        $destination_directory = ABSPATH;
        // Set compatibility mode if defined in advanced options.
        $compatibility_mode = false;
        // Default to no compatibility mode.
        if (pb_backupbuddy::$options['force_compatibility_medium'] != false) {
            $compatibility_mode = 'ziparchive';
        } elseif (pb_backupbuddy::$options['force_compatibility_slow'] != false) {
            $compatibility_mode = 'pclzip';
        }
        // Extract zip file & verify it worked.
        if (true !== ($result = pb_backupbuddy::$classes['zipbuddy']->unzip($backup_archive, $destination_directory, $compatibility_mode))) {
            pb_backupbuddy::status('error', 'Failed unzipping archive.');
            pb_backupbuddy::alert('Failed unzipping archive.', true);
            return false;
        }
        pb_backupbuddy::status('details', 'Success extracting Zip File "' . ABSPATH . pb_backupbuddy::$options['file'] . '" into "' . ABSPATH . '".');
    }
    // End extraction not skipped.
    // Made it here so zip returned true OR skipped unzip step.
    // Handle meta data in comment.
    pb_backupbuddy::status('details', 'Retrieving meta data from ZIP file (if any).');
    $comment = pb_backupbuddy::$classes['zipbuddy']->get_comment($backup_archive);
    $comment = backupbuddy_core::normalize_comment_data($comment);
    $comment_text = print_r($comment, true);
    $comment_text = str_replace(array("\n", "\r"), '; ', $comment_text);
    pb_backupbuddy::status('details', 'Backup meta data: `' . $comment_text . '`.');
    // Use meta to find DAT file (if possible). BB v3.3+.
    $dat_file = '';
    if ('' != $comment['dat_path']) {
        // Specific DAT location is known.
        pb_backupbuddy::status('details', 'Checking for DAT file as reported by meta data as file `' . ABSPATH . $comment['dat_path'] . '`.');
        if (file_exists(ABSPATH . $comment['dat_path'])) {
            $dat_file = ABSPATH . $comment['dat_path'];
            pb_backupbuddy::status('details', 'DAT file found based on meta path.');
        } else {
            pb_backupbuddy::status('warning', 'DAT file was not found as reported by meta data. This is unusual but may not be fatal. Commencing search for file...');
        }
    }
    // Deduce DAT file location based on backup filename. BB < v3.3.
    if ('' == $dat_file) {
        pb_backupbuddy::status('details', 'Scanning for DAT file based on backup file name.');
        $dat_file_locations = array(ABSPATH . 'wp-content/uploads/temp_' . pb_backupbuddy::$options['zip_id'] . '/backupbuddy_dat.php', ABSPATH . 'wp-content/uploads/backupbuddy_temp/' . pb_backupbuddy::$options['zip_id'] . '/backupbuddy_dat.php', ABSPATH . 'backupbuddy_dat.php');
        $dat_file = '';
        foreach ($dat_file_locations as $dat_file_location) {
            if (file_exists($dat_file_location)) {
                $dat_file = $dat_file_location;
                break;
            }
        }
        if ('' == $dat_file) {
            // DAT not found.
            $error_message = 'Error #9004: Key files missing. Backup data file, backupbuddy_dat.php was not found in the extracted files in any expected location. The unzip process either failed to fully complete, you renamed the backup ZIP file (rename it back to correct this), or the zip file is not a proper BackupBuddy backup.';
            pb_backupbuddy::status('error', $error_message);
            pb_backupbuddy::alert($error_message, true, '9004');
            return false;
        }
        pb_backupbuddy::status('details', 'Successfully found DAT file based on backup file name: `' . $dat_file . '`.');
    }
    // Get DAT file contents & save into options..
    pb_backupbuddy::$options['dat_file'] = pb_backupbuddy::$classes['import']->get_dat_file_array($dat_file);
    pb_backupbuddy::$options['temp_serial_directory'] = basename($dat_file);
    pb_backupbuddy::save();
    return true;
}
Esempio n. 9
0
 public static function backup_integrity_check($file, $fileoptions = '', $options = array(), $skipLogRedirect = false)
 {
     pb_backupbuddy::status('details', 'Started backup_integrity_check() function.');
     $serial = self::get_serial_from_file($file);
     // User selected to rescan a file.
     if (pb_backupbuddy::_GET('reset_integrity') == $serial) {
         pb_backupbuddy::alert('Rescanning backup integrity for backup file `' . basename($file) . '`');
         pb_backupbuddy::flush();
     }
     $options = array_merge(array('skip_database_dump' => '0'), $options);
     $scan_notes = array();
     // Get backup fileoptions.
     if ($fileoptions != '') {
         $backup_options =& $fileoptions;
     } else {
         require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
         $backup_options = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt', $read_only = false, $ignore_lock = false, $create_file = true);
         // Will create file to hold integrity data if nothing exists.
         if (true !== ($result = $backup_options->is_ok())) {
             pb_backupbuddy::status('error', __('Fatal Error #9034 C. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error on file `' . backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt' . '`: ' . $result);
             pb_backupbuddy::status('action', 'halt_script');
             // Halt JS on page.
             return false;
         }
     }
     if (isset($backup_options->options['profile'])) {
         $options = $backup_options->options['profile'];
         $options = array_merge(pb_backupbuddy::settings('profile_defaults'), $options);
     }
     // Return if cached.
     if (isset($backup_options->options['integrity']) && count($backup_options->options['integrity']) > 0 && pb_backupbuddy::_GET('reset_integrity') != $serial) {
         // Already have integrity data and NOT resetting this one.
         pb_backupbuddy::status('details', 'Integrity data for backup `' . $serial . '` is cached; not scanning again.');
         return $backup_options->options['integrity'];
     } elseif (pb_backupbuddy::_GET('reset_integrity') == $serial) {
         // Resetting this one.
         pb_backupbuddy::status('details', 'Resetting backup integrity stats for backup with serial `' . $serial . '`.');
     } else {
         // No integrity data; not resetting. Just keep going...
     }
     // Integrity check disabled. Skip.
     if (($options['integrity_check'] == '0' || pb_backupbuddy::$options['profiles'][0]['integrity_check'] == '0') && pb_backupbuddy::_GET('reset_integrity') == '') {
         // Integrity checking disabled. Allows run if manually rescanning on backups page.
         pb_backupbuddy::status('details', 'Integrity check disabled. Skipping scan.');
         $file_stats = @stat($file);
         if ($file_stats === false) {
             // stat failure.
             pb_backupbuddy::status('error', 'Error #4539774. Unable to get file details ( via stat() ) for file `' . $file . '`. The file may be corrupt or too large for the server.');
             $file_size = 0;
             $file_modified = 0;
         } else {
             // stat success.
             $file_size = $file_stats['size'];
             $file_modified = $file_stats['mtime'];
         }
         unset($file_stats);
         $integrity = array('status' => 'Unknown', 'tests' => array(), 'scan_time' => 0, 'detected_type' => 'unknown', 'size' => $file_size, 'modified' => $file_modified, 'file' => basename($file), 'comment' => false);
         $backup_options->options['integrity'] = array_merge(pb_backupbuddy::settings('backups_integrity_defaults'), $integrity);
         $backup_options->save();
         return $backup_options->options['integrity'];
     }
     //***** BEGIN CALCULATING STATUS DETAILS.
     $backup_type = '';
     if (!isset(pb_backupbuddy::$classes['zipbuddy'])) {
         require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
         pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy(backupbuddy_core::getBackupDirectory());
     }
     $previous_status_serial = pb_backupbuddy::get_status_serial();
     // Store current status serial setting to reset back later.
     if (true !== $skipLogRedirect) {
         pb_backupbuddy::status('details', 'Redirecting status logging temporarily.');
         pb_backupbuddy::set_status_serial('zipbuddy_test');
         // Redirect logging output to a certain log file.
     }
     // Look for comment.
     pb_backupbuddy::status('details', 'Verifying comment in zip archive.');
     $raw_comment = pb_backupbuddy::$classes['zipbuddy']->get_comment($file);
     $comment = backupbuddy_core::normalize_comment_data($raw_comment);
     $comment = $comment['note'];
     $tests = array();
     pb_backupbuddy::status('details', 'NOTE: It is normal to see several "File not found" messages in the next several log lines.');
     // Check for DAT file.
     $pass = false;
     pb_backupbuddy::status('details', 'Verifying DAT file in zip archive.');
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'wp-content/uploads/backupbuddy_temp/' . $serial . '/backupbuddy_dat.php') === true) {
         // Post 2.0 full backup
         $backup_type = 'full';
         $pass = true;
     }
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'wp-content/uploads/temp_' . $serial . '/backupbuddy_dat.php') === true) {
         // Pre 2.0 full backup
         $backup_type = 'full';
         $pass = true;
     }
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'backupbuddy_dat.php') === true) {
         // DB backup
         $backup_type = 'db';
         $pass = true;
     }
     $tests[] = array('test' => 'BackupBuddy data file', 'pass' => $pass);
     if ('files' == $options['type']) {
         pb_backupbuddy::status('details', 'Files only backup type so skipping scan of database files in backup as it is not applicable.');
     } else {
         // Non-files only backup so check for DB.
         // Check for DB .sql file.
         $pass = false;
         $db_test_note = '';
         pb_backupbuddy::status('details', 'Verifying database SQL file in zip archive.');
         if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'wp-content/uploads/backupbuddy_temp/' . $serial . '/db_1.sql') === true) {
             // post 2.0 full backup
             $backup_type = 'full';
             $pass = true;
         }
         if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'wp-content/uploads/temp_' . $serial . '/db.sql') === true) {
             // pre 2.0 full backup
             $backup_type = 'full';
             $pass = true;
         }
         if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'db_1.sql') === true) {
             // db only backup 2.0+
             $backup_type = 'db';
             $pass = true;
         }
         if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'db.sql') === true) {
             // db only backup pre-2.0
             $backup_type = 'db';
             $pass = true;
         }
         if ('1' == $options['skip_database_dump']) {
             if (false === $pass) {
                 pb_backupbuddy::status('warning', 'WARNING: Database .SQL does NOT exist because database dump was set to be skipped based on settings. Use with caution. The database was NOT backed up.');
             } else {
                 // DB dump set to be skipped but was found. Just in case...
                 pb_backupbuddy::status('warning', 'Warning #58458749. Database dump was set to be skip _BUT_ database file WAS found?');
             }
             $pass = true;
             $db_test_note = ' <span class="pb_label pb_label-warning">' . __('Database skipped', 'it-l10n-backupbuddy') . '</span>';
             $scan_notes[] = '<span class="pb_label pb_label-warning">' . __('Database skipped', 'it-l10n-backupbuddy') . '</span>';
         }
         $tests[] = array('test' => 'Database SQL file' . $db_test_note, 'pass' => $pass);
     }
     // Use filename to determine backup type if detectable as it is more authoritive than the above guesses.
     if (false !== stristr($file, '-db-')) {
         $backup_type = 'db';
     } elseif (false !== stristr($file, '-full-')) {
         $backup_type = 'full';
     } elseif (false !== stristr($file, '-files-')) {
         $backup_type = 'files';
     } else {
         // Filename determination was not conclusive. Leave as-is based on deduced backup type determined earlier.
     }
     // Check for wp-config.php file if full backup.
     if ('full' == $backup_type) {
         $pass = false;
         pb_backupbuddy::status('details', 'Verifying WordPress wp-config.php configuration file in zip archive.');
         if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'wp-config.php') === true) {
             $pass = true;
         }
         if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'wp-content/uploads/backupbuddy_temp/' . $serial . '/wp-config.php') === true) {
             $pass = true;
         }
         if (false === $pass) {
             if (isset($options['excludes'])) {
                 if (false !== stristr($options['excludes'], 'wp-config.')) {
                     pb_backupbuddy::status('warning', 'Warning: An exclusion containing wp-config.php was found. Exclusions: `' . str_replace(array("\r", "\r\n", "\n"), '; ', $options['excludes']) . '`.');
                 }
             }
         }
         $tests[] = array('test' => 'WordPress wp-config.php file (full backups only)', 'pass' => $pass);
     }
     // end if full backup.
     // Get zip scan log details.
     pb_backupbuddy::status('details', 'Retrieving zip scan log.');
     $temp_details = pb_backupbuddy::get_status('zipbuddy_test');
     // Get zipbuddy scan log.
     $scan_log = array();
     foreach ($temp_details as $temp_detail) {
         $scan_log[] = $temp_detail[4];
     }
     if (true !== $skipLogRedirect) {
         pb_backupbuddy::set_status_serial($previous_status_serial);
         // Stop redirecting log to a specific file & set back to what it was prior.
         pb_backupbuddy::status('details', 'Stopped temporary redirection of status logging.');
     }
     pb_backupbuddy::status('details', 'Calculating integrity scan status,');
     // Check for any failed tests.
     $is_ok = true;
     $integrity_description = '';
     foreach ($tests as $test) {
         if ($test['pass'] !== true) {
             $is_ok = false;
             $error = 'Error #389434. Integrity test FAILED. Test: `' . $test['test'] . '`. ';
             pb_backupbuddy::status('error', $error);
             $integrity_description .= $error;
         }
     }
     if (true === $is_ok) {
         $integrity_status = 'Pass';
     } else {
         $integrity_status = 'Fail';
     }
     pb_backupbuddy::status('details', 'Status: `' . $integrity_status . '`. Description: `' . $integrity_description . '`.');
     //***** END CALCULATING STATUS DETAILS.
     // Get file information from file system.
     pb_backupbuddy::status('details', 'Getting file details such as size, timestamp, etc.');
     $file_stats = @stat($file);
     if ($file_stats === false) {
         // stat failure.
         pb_backupbuddy::status('error', 'Error #4539774b. Unable to get file details ( via stat() ) for file `' . $file . '`. The file may be corrupt or too large for the server.');
         $file_size = 0;
         $file_modified = 0;
     } else {
         // stat success.
         $file_size = $file_stats['size'];
         $file_modified = $file_stats['ctime'];
         // Created time.
     }
     unset($file_stats);
     // Compile array of results for saving into data structure.
     $integrity = array('is_ok' => $is_ok, 'tests' => $tests, 'scan_time' => time(), 'scan_log' => $scan_log, 'scan_notes' => $scan_notes, 'detected_type' => $backup_type, 'size' => $file_size, 'modified' => $file_modified, 'file' => basename($file), 'comment' => $comment);
     pb_backupbuddy::status('details', 'Saving backup file integrity check details.');
     $backup_options->options['integrity'] = array_merge(pb_backupbuddy::settings('backups_integrity_defaults'), $integrity);
     $backup_options->save();
     return $backup_options->options['integrity'];
 }