Exemple #1
0
 public function start($backupFile, $skipUnzip = false)
 {
     $this->_before(__FUNCTION__);
     if (!file_exists($backupFile)) {
         return $this->_error('Unable to access backup file `' . $backupFile . '`. Verify it still exists and has proper read permissions.');
     }
     $this->_state['archive'] = $backupFile;
     $serial = backupbuddy_core::get_serial_from_file(basename($backupFile));
     $this->_state['serial'] = $serial;
     unset($backupFile);
     unset($serial);
     if (defined('PB_STANDALONE') && true === PB_STANDALONE) {
         $mysql_9010_log = ABSPATH . 'importbuddy/mysql_9010_log-' . pb_backupbuddy::$options['log_serial'] . '.txt';
         if (file_exists($mysql_9010_log)) {
             @unlink($mysql_9010_log);
         }
     }
     if (true !== $skipUnzip) {
         // Get zip meta information.
         $customTitle = 'Backup Details';
         pb_backupbuddy::status('details', 'Attempting to retrieve zip meta data from comment.');
         if (false !== ($metaInfo = backupbuddy_core::getZipMeta($this->_state['archive']))) {
             pb_backupbuddy::status('details', 'Found zip meta data.');
         } else {
             pb_backupbuddy::status('details', 'Did not find zip meta data.');
         }
         pb_backupbuddy::status('details', 'Loading zipbuddy.');
         require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
         $zipbuddy = new pluginbuddy_zipbuddy(dirname($this->_state['archive']));
         pb_backupbuddy::status('details', 'Zipbuddy loaded.');
     }
     // Find DAT file.
     pb_backupbuddy::status('details', 'Calculating possible DAT file locations.');
     $detectedDatLocation = '';
     $possibleDatLocations = array();
     if (isset($metaInfo['dat_path'])) {
         $possibleDatLocations[] = $metaInfo['dat_path'][1];
         // DAT file location encoded in meta info. Should always be valid.
     }
     $possibleDatLocations[] = 'wp-content/uploads/backupbuddy_temp/' . $this->_state['serial'] . '/backupbuddy_dat.php';
     // Full backup.
     $possibleDatLocations[] = 'backupbuddy_dat.php';
     // DB backup. (look for this second in case user left an old dat file in root).
     pb_backupbuddy::status('details', 'Possible DAT file locations: `' . implode(';', $possibleDatLocations) . '`.');
     $possibleDatLocations = array_unique($possibleDatLocations);
     if (true === $skipUnzip) {
         // Only look for DAT file in filesystem. Zip should be pre-extracted, eg by the user manually.
         pb_backupbuddy::status('details', 'Looking for DAT file in local filesystem (instead of in zip) since advanced skip unzip option set.');
         foreach ($possibleDatLocations as $possibleDatLocation) {
             // Look for DAT file in filesystem.
             pb_backupbuddy::status('details', 'Does `' . ABSPATH . $possibleDatLocation . '` exist?');
             if (true === file_exists(ABSPATH . $possibleDatLocation)) {
                 pb_backupbuddy::status('details', 'Yes, exists.');
                 $detectedDatLocation = $possibleDatLocation;
                 break;
             } else {
                 pb_backupbuddy::status('details', 'No, does not exist.');
             }
         }
         if ('' == $detectedDatLocation) {
             $message = 'Unable to find the DAT file for this backup archive pre-extracted in the filesystem. Make sure you have already unzipped this backup into the same directory as importbuddy.php.';
             return $this->_error($message);
         }
     } else {
         // Look for DAT file inside of zip archive.
         pb_backupbuddy::status('details', 'Looking for DAT file in zip archive itself.');
         foreach ($possibleDatLocations as $possibleDatLocation) {
             // Look for DAT file in zip.
             if (true === $zipbuddy->file_exists($this->_state['archive'], $possibleDatLocation, $leave_open = true)) {
                 $detectedDatLocation = $possibleDatLocation;
                 break;
             }
         }
         // end foreach.
     }
     if ('' == $detectedDatLocation) {
         return $this->_error('Unable to determine DAT file location. It may be missing OR the backup zip file may be incomplete or corrupted. Verify the backup zip has fully uploaded or re-upload it. You can try manually unzipping then selecting the advanced option to skip unzip.');
     }
     pb_backupbuddy::status('details', 'Confirmed DAT file location: `' . $detectedDatLocation . '`.');
     $this->_state['datLocation'] = $detectedDatLocation;
     unset($metaInfo);
     // No longer need anything from the meta information.
     if (true !== $skipUnzip) {
         function mkdir_recursive($path)
         {
             if (empty($path)) {
                 // prevent infinite loop on bad path
                 return;
             }
             is_dir(dirname($path)) || mkdir_recursive(dirname($path));
             return is_dir($path) || mkdir($path);
         }
         // Load DAT file contents.
         pb_backupbuddy::status('details', 'Creating temporary file directory `' . $this->_state['tempPath'] . '`.');
         pb_backupbuddy::$filesystem->unlink_recursive($this->_state['tempPath']);
         // Remove if already exists.
         mkdir_recursive($this->_state['tempPath']);
         // Make empty directory.
         // Restore DAT file.
         pb_backupbuddy::status('details', 'Extracting DAT file.');
         $files = array($detectedDatLocation => 'backupbuddy_dat.php');
         require pb_backupbuddy::plugin_path() . '/classes/_restoreFiles.php';
         $result = backupbuddy_restore_files::restore($this->_state['archive'], $files, $this->_state['tempPath'], $zipbuddy);
         echo '<script type="text/javascript">jQuery("#pb_backupbuddy_working").hide();</script>';
         pb_backupbuddy::flush();
         if (false === $result) {
             $this->_error('Error #85484: Unable to retrieve DAT file. This is a fatal error.');
             return false;
         }
         $datFile = $this->_state['tempPath'] . 'backupbuddy_dat.php';
     } else {
         $datFile = $this->_state['datLocation'];
     }
     if (false === ($datData = backupbuddy_core::get_dat_file_array($datFile))) {
         $this->_error('Error #4839484: Unable to retrieve DAT file. The backup may have failed opening due to lack of memory, permissions issues, or other reason. Use ImportBuddy to restore or check the Advanced Log above for details.');
         return false;
     }
     $this->_state['dat'] = $datData;
     pb_backupbuddy::status('details', 'DAT file extracted.');
     if (defined('PB_STANDALONE') && true === PB_STANDALONE) {
         $simpleVersion = substr(pb_backupbuddy::$options['bb_version'], 0, strpos(pb_backupbuddy::$options['bb_version'], ' '));
         if (isset($this->_state['dat']['backupbuddy_version']) && version_compare($this->_state['dat']['backupbuddy_version'], $simpleVersion, '>')) {
             pb_backupbuddy::status('error', 'Warning: You are attempting to restore an archive which was created with a newer version of BackupBuddy (' . $this->_state['dat']['backupbuddy_version'] . ') than this ImportBuddy (' . $simpleVersion . '). For best results use an ImportBuddy that is as least as up to date as the BackupBuddy which created the archive.');
         }
     }
     if ('rollback' == $this->_state['type']) {
         if (site_url() != $this->_state['dat']['siteurl']) {
             $this->_error(__('Error #5849843: Site URL does not match. You cannot roll back the database if the URL has changed or for backups or another site. Use importbuddy.php to restore or migrate instead.', 'it-l10n-backupbuddy'));
             return false;
         }
         global $wpdb;
         if ($this->_state['dat']['db_prefix'] != $wpdb->prefix) {
             $this->_error(__('Error #2389394: Database prefix does not match. You cannot roll back the database if the database prefix has changed or for backups or another site. Use importbuddy.php to restore or migrate instead.', 'it-l10n-backupbuddy'));
             return false;
         }
         pb_backupbuddy::$options['rollback_cleanups'][$this->_state['serial']] = time();
         pb_backupbuddy::save();
         // Generate UNDO script.
         pb_backupbuddy::status('details', 'Generating undo script.');
         $this->_state['undoFile'] = 'backupbuddy_rollback_undo-' . $this->_state['serial'] . '.php';
         $undoURL = rtrim(site_url(), '/\\') . '/' . $this->_state['undoFile'];
         if (false === copy(dirname(__FILE__) . '/_rollback_undo.php', ABSPATH . $this->_state['undoFile'])) {
             $this->_error(__('Warning: Unable to create undo script in site root. You will not be able to automated undoing the rollback if something fails so BackupBuddy will not continue.', 'it-l10n-backupbuddy'));
             return false;
         }
         $this->_state['undoURL'] = $undoURL;
     }
     pb_backupbuddy::status('details', 'Finished starting function.');
     return true;
 }
                } 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.
echo '<br><br>';
//***** END TESTS AND RESULTS.
// Output meta info table (if any).
$metaInfo = array();
if (isset($integrity['file']) && false === ($metaInfo = backupbuddy_core::getZipMeta(backupbuddy_core::getBackupDirectory() . $integrity['file']))) {
    // $backup_options->options['archive_file']
    echo '<i>No meta data found in zip comment. Skipping meta information display.</i>';
} else {
    pb_backupbuddy::$ui->list_table($metaInfo, array('columns' => array('Backup Details', 'Value'), 'css' => 'width: 100%; min-width: 200px;'));
}
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) {
Exemple #3
0
 public function integrity_status()
 {
     $serial = pb_backupbuddy::_GET('serial');
     $serial = str_replace('/\\', '', $serial);
     pb_backupbuddy::load();
     pb_backupbuddy::$ui->ajax_header();
     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.
     echo '<br><br>';
     //***** END TESTS AND RESULTS.
     // Output meta info table (if any).
     if (false === ($metaInfo = backupbuddy_core::getZipMeta(backupbuddy_core::getBackupDirectory() . $integrity['file']))) {
         // $backup_options->options['archive_file']
         echo '<i>No meta data found in zip comment. Skipping meta information display.</i>';
     } else {
         pb_backupbuddy::$ui->list_table($metaInfo, array('columns' => array('Backup Details', 'Value'), 'css' => 'width: 100%; min-width: 200px;'));
     }
     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 Steps', '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.
     if (isset($backup_options->options['trigger'])) {
         $trigger = $backup_options->options['trigger'];
     } else {
         $trigger = 'Unknown trigger';
     }
     $scanned = pb_backupbuddy::$format->date(pb_backupbuddy::$format->localize_time($integrity['scan_time']));
     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;
 }
Exemple #4
0
 public function start($backupFile)
 {
     $this->_before(__FUNCTION__);
     $this->_state['archive'] = $backupFile;
     $serial = backupbuddy_core::get_serial_from_file(basename($backupFile));
     $this->_state['serial'] = $serial;
     $this->_state['tempPath'] = backupbuddy_core::getTempDirectory() . $this->_state['type'] . '_' . $this->_state['serial'] . '/';
     unset($backupFile);
     unset($serial);
     // Get zip meta information.
     $customTitle = 'Backup Details';
     pb_backupbuddy::status('details', 'Attempting to retrieve zip meta data from comment.');
     if (false !== ($metaInfo = backupbuddy_core::getZipMeta($this->_state['archive']))) {
         pb_backupbuddy::status('details', 'Found zip meta data.');
     } else {
         pb_backupbuddy::status('details', 'Did not find zip meta data.');
     }
     //$this->_state['meta'] = $metaInfo;
     pb_backupbuddy::status('details', 'Loading zipbuddy.');
     require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
     $zipbuddy = new pluginbuddy_zipbuddy(backupbuddy_core::getBackupDirectory());
     pb_backupbuddy::status('details', 'Zipbuddy loaded.');
     // Find DAT file.
     pb_backupbuddy::status('details', 'Calculating possible DAT file locations.');
     $possibleDatLocations = array();
     if (isset($metaInfo['dat_path'])) {
         $possibleDatLocations[] = $metaInfo['dat_path'][1];
         // DAT file location encoded in meta info. Should always be valid.
     }
     $possibleDatLocations[] = 'backupbuddy_dat.php';
     // DB backup.
     $possibleDatLocations[] = 'wp-content/uploads/backupbuddy_temp/' . $this->_state['serial'] . '/backupbuddy_dat.php';
     // Full backup.
     pb_backupbuddy::status('details', 'Possible DAT file locations: `' . implode(';', $possibleDatLocations) . '`.');
     $possibleDatLocations = array_unique($possibleDatLocations);
     foreach ($possibleDatLocations as $possibleDatLocation) {
         if (true === $zipbuddy->file_exists($this->_state['archive'], $possibleDatLocation, $leave_open = true)) {
             $detectedDatLocation = $possibleDatLocation;
             break;
         }
     }
     // end foreach.
     pb_backupbuddy::status('details', 'Confirmed DAT file location: `' . $detectedDatLocation . '`.');
     $this->_state['datLocation'] = $detectedDatLocation;
     unset($metaInfo);
     // No longer need anything from the meta information.
     // Load DAT file contents.
     pb_backupbuddy::status('details', 'Creating temporary file directory `' . $this->_state['tempPath'] . '`.');
     pb_backupbuddy::$filesystem->unlink_recursive($this->_state['tempPath']);
     // Remove if already exists.
     mkdir($this->_state['tempPath']);
     // Make empty directory.
     // Restore DAT file.
     pb_backupbuddy::status('details', 'Extracting DAT file.');
     $files = array($detectedDatLocation => 'backupbuddy_dat.php');
     require pb_backupbuddy::plugin_path() . '/classes/_restoreFiles.php';
     $result = backupbuddy_restore_files::restore($this->_state['archive'], $files, $this->_state['tempPath'], $zipbuddy);
     echo '<script type="text/javascript">jQuery("#pb_backupbuddy_working").hide();</script>';
     pb_backupbuddy::flush();
     if (false === $result) {
         $this->_error('Error #85484: Unable to retrieve DAT file. This is a fatal error.');
         return false;
     }
     if (false === ($datData = backupbuddy_core::get_dat_file_array($this->_state['tempPath'] . 'backupbuddy_dat.php'))) {
         $this->_error('Error #4839484: Unable to retrieve DAT file. The backup may have failed opening due to lack of memory, permissions issues, or other reason. Use ImportBuddy to restore or check the Advanced Log above for details.');
         return false;
     }
     $this->_state['dat'] = $datData;
     pb_backupbuddy::status('details', 'DAT file extracted.');
     if (site_url() != $this->_state['dat']['siteurl']) {
         $this->_error(__('Error #5849843: Site URL does not match. You cannot roll back the database if the URL has changed or for backups or another site. Use importbuddy.php to restore or migrate instead.', 'it-l10n-backupbuddy'));
         return false;
     }
     global $wpdb;
     if ($this->_state['dat']['db_prefix'] != $wpdb->prefix) {
         $this->_error(__('Error #2389394: Database prefix does not match. You cannot roll back the database if the database prefix has changed or for backups or another site. Use importbuddy.php to restore or migrate instead.', 'it-l10n-backupbuddy'));
         return false;
     }
     // Store this serial in the db for future cleanup.
     if ('rollback' == $this->_state['type']) {
         pb_backupbuddy::$options['rollback_cleanups'][$this->_state['serial']] = time();
         pb_backupbuddy::save();
         // Generate UNDO script.
         pb_backupbuddy::status('details', 'Generating undo script.');
         $this->_state['undoFile'] = 'backupbuddy_rollback_undo-' . $this->_state['serial'] . '.php';
         $undoURL = rtrim(site_url(), '/\\') . '/' . $this->_state['undoFile'];
         if (false === copy(dirname(__FILE__) . '/_rollback_undo.php', ABSPATH . $this->_state['undoFile'])) {
             $this->_error(__('Warning: Unable to create undo script in site root. You will not be able to automated undoing the rollback if something fails so BackupBuddy will not continue.', 'it-l10n-backupbuddy'));
             return false;
         }
         $this->_state['undoURL'] = $undoURL;
     }
     pb_backupbuddy::status('details', 'Finished starting function.');
     return true;
 }