Exemple #1
0
 function start_backup_process($type, $trigger = 'manual', $pre_backup = array(), $post_backup = array(), $schedule_title = '', $serial_override = '', $export_plugins = array())
 {
     if ($serial_override != '') {
         $serial = $serial_override;
     } else {
         $serial = pb_backupbuddy::random_string(10);
     }
     pb_backupbuddy::set_status_serial($serial);
     // Default logging serial.
     pb_backupbuddy::status('details', __('Starting backup process function.', 'it-l10n-backupbuddy'));
     pb_backupbuddy::status('details', __('Peak memory usage', 'it-l10n-backupbuddy') . ': ' . round(memory_get_peak_usage() / 1048576, 3) . ' MB');
     if ($this->pre_backup($serial, $type, $trigger, $pre_backup, $post_backup, $schedule_title, $export_plugins) === false) {
         return false;
     }
     if ($trigger == 'scheduled' && pb_backupbuddy::$options['email_notify_scheduled_start'] != '') {
         pb_backupbuddy::status('details', __('Sending scheduled backup start email notification if applicable.', 'it-l10n-backupbuddy'));
         pb_backupbuddy::$classes['core']->mail_notify_scheduled('start', __('Scheduled backup', 'it-l10n-backupbuddy') . ' (' . $this->_backup['schedule_title'] . ') has begun.');
     }
     if (pb_backupbuddy::$options['backup_mode'] == '2' || $trigger == 'scheduled') {
         // Modern mode with crons.
         pb_backupbuddy::status('message', 'Running in modern backup mode based on settings. Mode value: `' . pb_backupbuddy::$options['backup_mode'] . '`. Trigger: `' . $trigger . '`.');
         // If using alternate cron on a manually triggered backup then skip running the cron on this pageload to avoid header already sent warnings.
         if ($trigger == 'manual' && defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) {
             $this->cron_next_step(false);
         } else {
             $this->cron_next_step(true);
         }
     } else {
         // Classic mode; everything runs in this single PHP page load.
         pb_backupbuddy::status('message', 'Running in classic backup mode based on settings.');
         $this->process_backup($this->_backup['serial'], $trigger);
     }
     return true;
 }
Exemple #2
0
 function process_backup($serial = 'blank')
 {
     pb_backupbuddy::set_status_serial($serial);
     pb_backupbuddy::status('details', '--- New PHP process.');
     pb_backupbuddy::set_greedy_script_limits();
     pb_backupbuddy::status('message', 'Running process for serial `' . $serial . '`...');
     require_once pb_backupbuddy::plugin_path() . '/classes/backup.php';
     $newBackup = new pb_backupbuddy_backup();
     $newBackup->process_backup($serial);
 }
Exemple #3
0
 function process_backup($serial = 'blank')
 {
     pb_backupbuddy::set_status_serial($serial);
     pb_backupbuddy::set_greedy_script_limits();
     pb_backupbuddy::status('message', 'Processing cron step for serial `' . $serial . '`...');
     if (!isset(pb_backupbuddy::$classes['backup'])) {
         require_once pb_backupbuddy::plugin_path() . '/classes/backup.php';
         pb_backupbuddy::$classes['backup'] = new pb_backupbuddy_backup();
     }
     pb_backupbuddy::$classes['backup']->process_backup($serial);
 }
Exemple #4
0
    public function rollback()
    {
        pb_backupbuddy::$ui->ajax_header();
        pb_backupbuddy::load_script('jquery');
        echo '<div id="pb_backupbuddy_working" style="width: 100px; margin-bottom: 30px;"><br><center><img src="' . pb_backupbuddy::plugin_url() . '/images/working.gif" title="Working... Please wait as this may take a moment..."></center></div>';
        ?>
		
		
		<script>
		function pb_status_append( status_string ) {
			var win = window.dialogArguments || opener || parent || top;
			win.pb_status_append( status_string );
		}
		function pb_status_undourl( undo_url ) {
			var win = window.dialogArguments || opener || parent || top;
			win.pb_status_undourl( undo_url );
		}
		
		var win = window.dialogArguments || opener || parent || top;
		win.window.scrollTo(0,0);
		</script>
		
		
		<?php 
        global $pb_backupbuddy_js_status;
        $pb_backupbuddy_js_status = true;
        pb_backupbuddy::set_status_serial('restore');
        $step = strip_tags(pb_backupbuddy::_GET('step'));
        if ('' == $step || !is_numeric($step)) {
            $step = 0;
        }
        $backupFile = strip_tags(pb_backupbuddy::_GET('archive'));
        if ('' == $backupFile) {
            pb_backupbuddy::alert('The backup file to restore from must be specified.');
            die;
        }
        $stepFile = pb_backupbuddy::plugin_path() . '/controllers/pages/rollback/_step' . $step . '.php';
        if (!file_exists($stepFile)) {
            pb_backupbuddy::alert('Error #849743. Invalid roll back step `' . htmlentities(pb_backupbuddy::_GET('step')) . '` (' . $step . ').');
            die;
        }
        require $stepFile;
        echo '<br><br><br>';
        echo '<script type="text/javascript">jQuery("#pb_backupbuddy_working").hide();</script>';
        pb_backupbuddy::$ui->ajax_footer();
        pb_backupbuddy::flush();
        die;
    }
 function start_backup_process($profile, $trigger = 'manual', $pre_backup = array(), $post_backup = array(), $schedule_title = '', $serial_override = '', $export_plugins = array(), $deployDirection = '', $deployDestinationSettings = '')
 {
     // Load profile defaults.
     $profile = array_merge(pb_backupbuddy::settings('profile_defaults'), $profile);
     foreach ($profile as $profile_item_name => &$profile_item) {
         // replace non-overridden defaults with actual default value.
         if ('-1' == $profile_item) {
             // Set to use default so go grab default.
             if (isset(pb_backupbuddy::$options['profiles'][0][$profile_item_name])) {
                 $profile_item = pb_backupbuddy::$options['profiles'][0][$profile_item_name];
                 // Grab value from defaults profile and replace with it.
             }
         }
     }
     // Handle backup mode.
     $backup_mode = pb_backupbuddy::$options['backup_mode'];
     // Load global default mode.
     if ('1' == $profile['backup_mode']) {
         // Profile forces classic.
         $backup_mode = '1';
     } elseif ('2' == $profile['backup_mode']) {
         // Profiles forces modern.
         $backup_mode = '2';
     }
     $profile['backup_mode'] = $backup_mode;
     unset($backup_mode);
     // If classic mode then we need to redirect output to displaying inline via JS instead of AJAX-based.
     if ('1' == $profile['backup_mode']) {
         //global $pb_backupbuddy_js_status;
         //$pb_backupbuddy_js_status = true;
     }
     if ($serial_override != '') {
         $serial = $serial_override;
     } else {
         $serial = pb_backupbuddy::random_string(10);
     }
     pb_backupbuddy::set_status_serial($serial);
     // Default logging serial.
     global $wp_version;
     pb_backupbuddy::status('details', 'BackupBuddy v' . pb_backupbuddy::settings('version') . ' using WordPress v' . $wp_version . ' on ' . PHP_OS . '.');
     //pb_backupbuddy::status( 'details', __('Peak memory usage', 'it-l10n-backupbuddy' ) . ': ' . round( memory_get_peak_usage() / 1048576, 3 ) . ' MB' );
     $type = $profile['type'];
     $archiveFile = $this->calculateArchiveFilename($serial, $type);
     //if ( 'pull' != $deployDirection ) {
     if ($this->pre_backup($serial, $archiveFile, $profile, $trigger, $pre_backup, $post_backup, $schedule_title, $export_plugins, $deployDirection, $deployDestinationSettings) === false) {
         pb_backupbuddy::status('details', 'pre_backup() function failed.');
         return false;
     }
     /*
     } else { // PULL deployment.
     	
     	pb_backupbuddy::status( 'details', 'About to load fileoptions data in create mode.' );
     	require_once( pb_backupbuddy::plugin_path() . '/classes/fileoptions.php' );
     	pb_backupbuddy::status( 'details', 'Fileoptions instance #40.' );
     	$this->_backup_options = new pb_backupbuddy_fileoptions( backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt', $read_only = false, $ignore_lock = false, $create_file = true );
     	if ( true !== ( $result = $this->_backup_options->is_ok() ) ) {
     		pb_backupbuddy::status( 'error', __('Fatal Error #38293. Unable to access fileoptions data.', 'it-l10n-backupbuddy' ) . ' Error: ' . $result );
     		pb_backupbuddy::status( 'haltScript', '' ); // Halt JS on page.
     		return false;
     	}
     	pb_backupbuddy::status( 'details', 'Fileoptions data loaded.' );
     	$this->_backup = &$this->_backup_options->options; // Set reference.
     	$this->_backup['serial'] = $serial;
     }
     */
     if ($trigger == 'scheduled' && pb_backupbuddy::$options['email_notify_scheduled_start'] != '') {
         pb_backupbuddy::status('details', __('Sending scheduled backup start email notification if applicable.', 'it-l10n-backupbuddy'));
         backupbuddy_core::mail_notify_scheduled($serial, 'start', __('Scheduled backup', 'it-l10n-backupbuddy') . ' (' . $this->_backup['schedule_title'] . ') has begun.');
     }
     if ($profile['backup_mode'] == '2') {
         // Modern mode with crons.
         pb_backupbuddy::status('message', 'Running in modern backup mode based on settings. Mode value: `' . $profile['backup_mode'] . '`. Trigger: `' . $trigger . '`.');
         unset($this->_backup_options);
         // File unlocking is handled on deconstruction.  Make sure unlocked before firing off another cron spawn.
         // If using alternate cron on a manually triggered backup then skip running the cron on this pageload to avoid header already sent warnings.
         if ($trigger != 'manual' || defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) {
             $this->cron_next_step(false);
         } else {
             //$this->cron_next_step( true );
             $this->cron_next_step(false);
             // as of Aug 9, 2013 no longer spawn the cron. Caused very odd issue of double code runs.
         }
     } else {
         // Classic mode; everything runs in this single PHP page load.
         pb_backupbuddy::status('message', 'Running in classic backup mode based on settings.');
         $this->process_backup($this->_backup['serial'], $trigger);
     }
     return true;
 }
            }
        }
    }
    $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[] = json_decode($temp_detail)->{'data'};
}
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;
    }
}
Exemple #7
0
 function backup_integrity_check($file, $fileoptions = '', $options = array())
 {
     $options = array_merge(array('skip_database_dump' => '0'), $options);
     pb_backupbuddy::status('details', 'Started backup_integrity_check() function.');
     $serial = $this->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) . '`');
     }
     if ($fileoptions != '') {
         $backup_options =& $fileoptions;
     } else {
         require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
         $backup_options = new pb_backupbuddy_fileoptions(pb_backupbuddy::$options['log_directory'] . '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 `' . pb_backupbuddy::$options['log_directory'] . '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);
         }
     }
     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 true;
     } 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...
     }
     if (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 true;
     }
     //***** 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(pb_backupbuddy::$options['backup_directory']);
     }
     pb_backupbuddy::status('details', 'Redirecting status logging temporarily.');
     $previous_status_serial = pb_backupbuddy::get_status_serial();
     // Store current status serial setting to reset back later.
     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 = pb_backupbuddy::$classes['core']->normalize_comment_data($raw_comment);
     $comment = $comment['note'];
     $tests = array();
     // 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' => 'BackupBackup data file exists', 'pass' => $pass);
     // Skip database checks if needed.
     //if ( $options['skip_database_dump'] != '1' ) {
     // Check for DB SQL file.
     $pass = false;
     pb_backupbuddy::status('details', 'Verifying database SQL file in zip archive.');
     if ($options['skip_database_dump'] == '1') {
         pb_backupbuddy::status('warning', 'WARNING: Database .SQL file does NOT exist because the database dump has been set to be SKIPPED based on settings. Use with cuation!');
     } else {
         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;
         }
     }
     $tests[] = array('test' => 'Database SQL file exists', 'pass' => $pass);
     // NOTE: As of 4.0 ALL db dumps append into db_1.sql. Future: break out into individual files. Check DB SQL files for BREAKOUT tables.
     /*
     if ( isset( $backup_options->options['breakout_tables'] ) && ( count( $backup_options->options['breakout_tables'] ) > 0 ) ) {
     	foreach( $backup_options->options['breakout_tables'] as $breakout_table ) {
     		$pass = false;
     		if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, 'wp-content/uploads/backupbuddy_temp/' . $serial . '/' . $breakout_table . '.sql' ) === true ) { // Full backup.
     			$pass = true;
     		}
     		if ( pb_backupbuddy::$classes['zipbuddy']->file_exists( $file, $breakout_table . '.sql' ) === true ) { // DB backup.
     			$pass = true;
     		}
     		$tests[] = array(
     			'test'		=>	'Breakout Database SQL file exists (' . $breakout_table . '.sql)',
     			'pass'		=>	$pass,
     		);
     	}
     }
     */
     // }
     if ('full' == $backup_type) {
         // Check for WordPress config file.
         $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;
         }
         $tests[] = array('test' => 'WordPress wp-config.php exists (full backups only)', 'pass' => $pass);
     }
     // 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];
     }
     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, '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 $is_ok;
 }
Exemple #8
0
<?php

// Incoming vars:
// $serial, $specialAction = '', $initRetryCount = 0, $sqlFile = ''
$init_wait_retry_count = $initRetryCount;
$echoNotWrite = $echo;
// Forward all logging to this serial file.
pb_backupbuddy::set_status_serial($serial);
if (true == get_transient('pb_backupbuddy_stop_backup-' . $serial)) {
    pb_backupbuddy::status('message', 'Backup STOPPED. Post backup cleanup step has been scheduled to clean up any temporary files.', $serial);
    require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
    $fileoptions_file = backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt';
    pb_backupbuddy::status('details', 'Fileoptions instance #30.');
    $backup_options = new pb_backupbuddy_fileoptions($fileoptions_file, false, $ignore_lock = true);
    if (true !== ($result = $backup_options->is_ok())) {
        pb_backupbuddy::status('error', 'Unable to access fileoptions file `' . $fileoptions_file . '`.', $serial);
    }
    // Wipe backup file.
    if (isset($backup_options->options['archive_file']) && file_exists($backup_options->options['archive_file'])) {
        // Final zip file.
        $unlink_result = @unlink($backup_options->options['archive_file']);
        if (true === $unlink_result) {
            pb_backupbuddy::status('details', 'Deleted stopped backup ZIP file.', $serial);
        } else {
            pb_backupbuddy::status('error', 'Unable to delete stopped backup file. You should delete it manually as it may be damaged from stopping mid-backup. File to delete: `' . $backup_options->options['archive_file'] . '`.', $serial);
        }
    } else {
        pb_backupbuddy::status('details', 'Archive file not found. Not deleting.', $serial);
    }
    // NOTE: fileoptions file will be wiped by periodic cleanup. We need to keep this for now...
    delete_transient('pb_backupbuddy_stop_backup-' . $serial);
Exemple #9
0
 function backup_integrity_check($file)
 {
     pb_backupbuddy::status('details', 'Started backup_integrity_check() function.');
     $serial = $this->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) . '`');
     }
     if (isset(pb_backupbuddy::$options['backups'][$serial]['integrity']) && count(pb_backupbuddy::$options['backups'][$serial]['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 true;
     } 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...
     }
     if (pb_backupbuddy::$options['integrity_check'] == '0') {
         // Integrity checking disabled.
         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', 'status_details' => __('Integrity checking disabled based on settings. This file has not been verified.', 'it-l10n-backupbuddy'), 'scan_time' => 0, 'detected_type' => 'unknown', 'size' => $file_size, 'modified' => $file_modified, 'file' => basename($file), 'comment' => false);
         pb_backupbuddy::$options['backups'][$serial]['integrity'] = array_merge(pb_backupbuddy::settings('backups_integrity_defaults'), $integrity);
         pb_backupbuddy::save();
         return true;
     }
     //***** BEGIN CALCULATING STATUS DETAILS.
     // Status defaults.
     $status_details = array('found_dat' => false, 'found_sql' => false, 'found_wpconfig' => false, 'scan_log' => '');
     $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(pb_backupbuddy::$options['backup_directory']);
     }
     pb_backupbuddy::status('details', 'Redirecting status logging temporarily.');
     $previous_status_serial = pb_backupbuddy::get_status_serial();
     // Store current status serial setting to reset back later.
     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 = pb_backupbuddy::$classes['core']->normalize_comment_data($raw_comment);
     $comment = $comment['note'];
     // Check for DAT file.
     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
         $status_details['found_dat'] = true;
         $backup_type = 'full';
     }
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'wp-content/uploads/temp_' . $serial . '/backupbuddy_dat.php') === true) {
         // Pre 2.0 full backup
         $status_details['found_dat'] = true;
         $backup_type = 'full';
     }
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'backupbuddy_dat.php') === true) {
         // DB backup
         $status_details['found_dat'] = true;
         $backup_type = 'db';
     }
     // Check for DB SQL file.
     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
         $status_details['found_sql'] = true;
         $backup_type = 'full';
     }
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'wp-content/uploads/temp_' . $serial . '/db.sql') === true) {
         // pre 2.0 full backup
         $status_details['found_sql'] = true;
         $backup_type = 'full';
     }
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'db_1.sql') === true) {
         // db only backup 2.0+
         $status_details['found_sql'] = true;
         $backup_type = 'db';
     }
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'db.sql') === true) {
         // db only backup pre-2.0
         $status_details['found_sql'] = true;
         $backup_type = 'db';
     }
     // Check for WordPress config file.
     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) {
         $status_details['found_wpconfig'] = true;
         $backup_type = 'full';
     }
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'wp-content/uploads/backupbuddy_temp/' . $serial . '/wp-config.php') === true) {
         $status_details['found_wpconfig'] = true;
         $backup_type = 'full';
     }
     // 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.
     foreach ($temp_details as $temp_detail) {
         $status_details['scan_log'][] = $temp_detail[4];
     }
     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.');
     // Calculate status descriptions.
     pb_backupbuddy::status('details', 'Calculating integrity scan status,');
     $integrity_status = 'pass';
     // Default.
     if ($status_details['found_dat'] !== true) {
         $integrity_status = 'fail';
         $integrity_description .= __('Error #7843564: Missing DAT file.', 'it-l10n-backupbuddy');
     }
     if ($status_details['found_sql'] !== true) {
         $integrity_status = 'fail';
         $integrity_description .= __('Error #4664236: Missing database SQL file.', 'it-l10n-backupbuddy');
     }
     if ($backup_type == 'full' && $status_details['found_wpconfig'] !== true) {
         $integrity_status = 'fail';
         $integrity_description .= __('Error #47834674: Missing wp-config.php file.', 'it-l10n-backupbuddy');
     }
     if ($integrity_status == 'pass') {
         // All tests passed.
         $integrity_description = __('All tests passed.', 'it-l10n-backupbuddy');
     }
     pb_backupbuddy::status('details', 'Status: `' . $integrity_status . '`. Description: `' . $integrity_description . '`.');
     //$integrity_description .= '<br><br>' . __('Technical Details', 'it-l10n-backupbuddy' ) . ':<br />' . $integrity_zipresult_details;
     //***** 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('status' => $integrity_status, 'status_details' => $status_details, 'scan_time' => time(), '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.');
     pb_backupbuddy::$options['backups'][$serial]['integrity'] = array_merge(pb_backupbuddy::settings('backups_integrity_defaults'), $integrity);
     pb_backupbuddy::save();
     //pb_backupbuddy::$classes['zipbuddy']->clear_status();
     if ($integrity_status == 'pass') {
         // 100% success
         return true;
     } else {
         return false;
     }
 }
Exemple #10
0
 function start_backup_process($profile, $trigger = 'manual', $pre_backup = array(), $post_backup = array(), $schedule_title = '', $serial_override = '', $export_plugins = array())
 {
     // Load profile defaults.
     $profile = array_merge(pb_backupbuddy::settings('profile_defaults'), $profile);
     foreach ($profile as $profile_item_name => &$profile_item) {
         // replace non-overridden defaults with actual default value.
         if ('-1' == $profile_item) {
             // Set to use default so go grab default.
             if (isset(pb_backupbuddy::$options['profiles'][0][$profile_item_name])) {
                 $profile_item = pb_backupbuddy::$options['profiles'][0][$profile_item_name];
                 // Grab value from defaults profile and replace with it.
             }
         }
     }
     // Handle backup mode.
     $backup_mode = pb_backupbuddy::$options['backup_mode'];
     // Load global default mode.
     if ('1' == $profile['backup_mode']) {
         // Profile forces classic.
         $backup_mode = '1';
     } elseif ('2' == $profile['backup_mode']) {
         // Profiles forces modern.
         $backup_mode = '2';
     }
     $profile['backup_mode'] = $backup_mode;
     unset($backup_mode);
     // If classic mode then we need to redirect output to displaying inline via JS instead of AJAX-based.
     if ('1' == $profile['backup_mode']) {
         //global $pb_backupbuddy_js_status;
         //$pb_backupbuddy_js_status = true;
     }
     if ($serial_override != '') {
         $serial = $serial_override;
     } else {
         $serial = pb_backupbuddy::random_string(10);
     }
     pb_backupbuddy::set_status_serial($serial);
     // Default logging serial.
     global $wp_version;
     pb_backupbuddy::status('details', 'BackupBuddy v' . pb_backupbuddy::settings('version') . ' using WordPress v' . $wp_version . ' on ' . PHP_OS . '.');
     //pb_backupbuddy::status( 'details', __('Peak memory usage', 'it-l10n-backupbuddy' ) . ': ' . round( memory_get_peak_usage() / 1048576, 3 ) . ' MB' );
     if ($this->pre_backup($serial, $profile, $trigger, $pre_backup, $post_backup, $schedule_title, $export_plugins) === false) {
         pb_backupbuddy::status('details', 'pre_backup() function failed.');
         return false;
     }
     if ($trigger == 'scheduled' && pb_backupbuddy::$options['email_notify_scheduled_start'] != '') {
         pb_backupbuddy::status('details', __('Sending scheduled backup start email notification if applicable.', 'it-l10n-backupbuddy'));
         backupbuddy_core::mail_notify_scheduled($serial, 'start', __('Scheduled backup', 'it-l10n-backupbuddy') . ' (' . $this->_backup['schedule_title'] . ') has begun.');
     }
     if ($profile['backup_mode'] == '2') {
         // Modern mode with crons.
         pb_backupbuddy::status('message', 'Running in modern backup mode based on settings. Mode value: `' . $profile['backup_mode'] . '`. Trigger: `' . $trigger . '`.');
         unset($this->_backup_options);
         // File unlocking is handled on deconstruction.  Make sure unlocked before firing off another cron spawn.
         // If using alternate cron on a manually triggered backup then skip running the cron on this pageload to avoid header already sent warnings.
         if ($trigger != 'manual' || defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) {
             $this->cron_next_step(false);
         } else {
             //$this->cron_next_step( true );
             $this->cron_next_step(false);
             // as of Aug 9, 2013 no longer spawn the cron. Caused very odd issue of double code runs.
         }
     } else {
         // Classic mode; everything runs in this single PHP page load.
         pb_backupbuddy::status('message', 'Running in classic backup mode based on settings.');
         $this->process_backup($this->_backup['serial'], $trigger);
     }
     return true;
 }
Exemple #11
0
	win.pb_status_append( status_string );
}
function pb_status_undourl( undo_url ) {
	var win = window.dialogArguments || opener || parent || top;
	win.pb_status_undourl( undo_url );
}

var win = window.dialogArguments || opener || parent || top;
win.window.scrollTo(0,0);
</script>


<?php 
global $pb_backupbuddy_js_status;
$pb_backupbuddy_js_status = true;
pb_backupbuddy::set_status_serial('deploy');
$step = strip_tags(pb_backupbuddy::_GET('step'));
if (!ctype_alnum($step)) {
    die('Error #8549845: Invalid step `' . htmlentities($step) . '`.');
}
$stepFile = pb_backupbuddy::plugin_path() . '/controllers/pages/deploy/_' . $step . '.php';
if (!file_exists($stepFile)) {
    pb_backupbuddy::alert('Error #3298238. Invalid deploy step `' . htmlentities(pb_backupbuddy::_GET('step')) . '` (' . $step . ').');
    die;
}
require $stepFile;
echo '<br><br><br>';
echo '<script type="text/javascript">jQuery("#pb_backupbuddy_working").hide();</script>';
pb_backupbuddy::$ui->ajax_footer();
pb_backupbuddy::flush();
die;
Exemple #12
0
    public function restore_file_restore()
    {
        $success = false;
        pb_backupbuddy::$ui->ajax_header(true, false);
        // js, no padding
        ?>
		<script type="text/javascript">
			function pb_status_append( status_string ) {
				target_id = 'pb_backupbuddy_status'; // importbuddy_status or pb_backupbuddy_status
				if( jQuery( '#' + target_id ).length == 0 ) { // No status box yet so suppress.
					return;
				}
				jQuery( '#' + target_id ).append( "\n" + status_string );
				textareaelem = document.getElementById( target_id );
				textareaelem.scrollTop = textareaelem.scrollHeight;
			}
		</script>
		<?php 
        global $pb_backupbuddy_js_status;
        $pb_backupbuddy_js_status = true;
        echo pb_backupbuddy::status_box('Restoring . . .');
        echo '<div id="pb_backupbuddy_working" style="width: 100px;"><br><center><img src="' . pb_backupbuddy::plugin_url() . '/images/working.gif" title="Working... Please wait as this may take a moment..."></center></div>';
        pb_backupbuddy::set_status_serial('restore');
        global $wp_version;
        pb_backupbuddy::status('details', 'BackupBuddy v' . pb_backupbuddy::settings('version') . ' using WordPress v' . $wp_version . ' on ' . PHP_OS . '.');
        $archive_file = pb_backupbuddy::_GET('archive');
        // archive to extract from.
        $files = pb_backupbuddy::_GET('files');
        // file to extract.
        $files_array = explode(',', $files);
        $files = array();
        foreach ($files_array as $file) {
            if (substr($file, -1) == '/') {
                // If directory then add wildcard.
                $file = $file . '*';
            }
            $files[$file] = $file;
        }
        unset($files_array);
        $serial = backupbuddy_core::get_serial_from_file($archive_file);
        // serial of archive.
        foreach ($files as $file) {
            $file = str_replace('*', '', $file);
            // Remove any wildcard.
            if (file_exists(ABSPATH . $file) && is_dir(ABSPATH . $file)) {
                if (($file_count = @scandir(ABSPATH . $file)) && count($file_count) > 2) {
                    pb_backupbuddy::status('error', __('Error #9036. The destination directory being restored already exists and is NOT empty. The directory will not be restored to prevent inadvertently losing files within the existing directory. Delete existing directory first if you wish to proceed or restore individual files.', 'it-l10n-backupbuddy') . ' Existing directory: `' . ABSPATH . $file . '`.');
                    echo '<script type="text/javascript">jQuery("#pb_backupbuddy_working").hide();</script>';
                    pb_backupbuddy::flush();
                    pb_backupbuddy::$ui->ajax_footer();
                    die;
                }
            }
        }
        require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
        $zipbuddy = new pluginbuddy_zipbuddy(backupbuddy_core::getBackupDirectory());
        // Calculate temp directory & lock it down.
        $temp_dir = get_temp_dir();
        $destination = $temp_dir . 'backupbuddy-' . $serial;
        if (!file_exists($destination) && false === mkdir($destination, 0777, true)) {
            $error = 'Error #458485945: Unable to create temporary location.';
            pb_backupbuddy::status('error', $error);
            echo '<script type="text/javascript">jQuery("#pb_backupbuddy_working").hide();</script>';
            pb_backupbuddy::flush();
            pb_backupbuddy::$ui->ajax_footer();
            die;
        }
        // If temp directory is within webroot then lock it down.
        $temp_dir = str_replace('\\', '/', $temp_dir);
        // Normalize for Windows.
        $temp_dir = rtrim($temp_dir, '/\\') . '/';
        // Enforce single trailing slash.
        if (FALSE !== stristr($temp_dir, ABSPATH)) {
            // Temp dir is within webroot.
            pb_backupbuddy::anti_directory_browsing($destination);
        }
        unset($temp_dir);
        pb_backupbuddy::status('details', 'Extracting into temporary directory "' . $destination . '".');
        pb_backupbuddy::status('details', 'Files to extract: `' . htmlentities(pb_backupbuddy::_GET('files')) . '`.');
        // Make sure temp subdirectories exist.
        /*
        foreach( $files as $file => $null ) {
        	mkdir( $destination . '/' . basename( $file ), 0777, true );
        }
        */
        pb_backupbuddy::flush();
        $extract_success = true;
        $extract_result = $zipbuddy->extract(backupbuddy_core::getBackupDirectory() . $archive_file, $destination, $files);
        if (false === $extract_result) {
            // failed.
            pb_backupbuddy::status('error', 'Error #584984458b. Unable to extract.');
            $extract_success = false;
        } else {
            // success.
            // Verify all files/directories to be extracted exist in temp destination directory. If any missing then delete everything and bail out.
            foreach ($files as &$file) {
                $file = str_replace('*', '', $file);
                // Remove any wildcard.
                if (!file_exists($destination . '/' . $file)) {
                    // Cleanup.
                    foreach ($files as $file) {
                        @trigger_error('');
                        // Clear out last error.
                        @unlink($destination . '/' . $file);
                        $last_error = error_get_last();
                        if (is_array($last_error)) {
                            pb_backupbuddy::status('error', $last_error['message'] . ' File: `' . $last_error['file'] . '`. Line: `' . $last_error['line'] . '`.');
                        }
                    }
                    pb_backupbuddy::status('error', 'Error #854783474. One or more expected files / directories missing.');
                    $extract_success = false;
                    break;
                }
            }
            unset($file);
        }
        if (true === $extract_success) {
            // Made it this far so files all exist. Move them all.
            foreach ($files as $file) {
                @trigger_error('');
                // Clear out last error.
                if (false === @rename($destination . '/' . $file, ABSPATH . $file)) {
                    $last_error = error_get_last();
                    if (is_array($last_error)) {
                        //print_r( $last_error );
                        pb_backupbuddy::status('error', $last_error['message'] . ' File: `' . $last_error['file'] . '`. Line: `' . $last_error['line'] . '`.');
                    }
                    $error = 'Error #9035. Unable to move restored file `' . $destination . '/' . $file . '` to `' . ABSPATH . $file . '`. Verify permissions on destination location & that the destination directory/file does not already exist.';
                    pb_backupbuddy::status('error', $error);
                } else {
                    $details = 'Moved `' . $destination . '/' . $file . '` to `' . ABSPATH . $file . '`.<br>';
                    pb_backupbuddy::status('details', $details);
                    $success = true;
                }
            }
        }
        // end extract succeeded.
        // Try to cleanup.
        if (file_exists($destination)) {
            if (false === pb_backupbuddy::$filesystem->unlink_recursive($destination)) {
                pb_backupbuddy::status('details', 'Unable to delete temporary holding directory `' . $destination . '`.');
            } else {
                pb_backupbuddy::status('details', 'Cleaned up temporary files.');
            }
        }
        if (true === $success) {
            pb_backupbuddy::status('message', 'Restore completed successfully.');
        }
        echo '<script type="text/javascript">jQuery("#pb_backupbuddy_working").hide();</script>';
        pb_backupbuddy::flush();
        pb_backupbuddy::$ui->ajax_footer();
        die;
    }
Exemple #13
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('haltScript', '');
             // 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 (pb_backupbuddy::$options['profiles'][0]['integrity_check'] == '0' && pb_backupbuddy::_GET('reset_integrity') == '' && isset($options['integrity_check']) && $options['integrity_check'] == '0') {
         // 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 (isset($options['type']) && '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[] = json_decode($temp_detail)->{'data'};
     }
     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['mtime'];
         // 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'];
 }
Exemple #14
0
    public function deploy()
    {
        pb_backupbuddy::$ui->ajax_header();
        pb_backupbuddy::load_script('jquery');
        echo '<div id="pb_backupbuddy_working" style="width: 100px; margin-bottom: 30px;"><br><center><img src="' . pb_backupbuddy::plugin_url() . '/images/working.gif" title="Working... Please wait as this may take a moment..."></center></div>';
        ?>
		
		
		<script>
		function pb_status_append( status_string ) {
			var win = window.dialogArguments || opener || parent || top;
			win.pb_status_append( status_string );
		}
		function pb_status_undourl( undo_url ) {
			var win = window.dialogArguments || opener || parent || top;
			win.pb_status_undourl( undo_url );
		}
		
		var win = window.dialogArguments || opener || parent || top;
		win.window.scrollTo(0,0);
		</script>
		
		
		<?php 
        global $pb_backupbuddy_js_status;
        $pb_backupbuddy_js_status = true;
        pb_backupbuddy::set_status_serial('deploy');
        $step = strip_tags(pb_backupbuddy::_GET('step'));
        if (!ctype_alnum($step)) {
            die('Error #8549845: Invalid step `' . htmlentities($step) . '`.');
        }
        $stepFile = pb_backupbuddy::plugin_path() . '/controllers/pages/deploy/_' . $step . '.php';
        if (!file_exists($stepFile)) {
            pb_backupbuddy::alert('Error #3298238. Invalid deploy step `' . htmlentities(pb_backupbuddy::_GET('step')) . '` (' . $step . ').');
            die;
        }
        require $stepFile;
        echo '<br><br><br>';
        echo '<script type="text/javascript">jQuery("#pb_backupbuddy_working").hide();</script>';
        pb_backupbuddy::$ui->ajax_footer();
        pb_backupbuddy::flush();
        die;
    }
Exemple #15
0
 function backup_integrity_check($file)
 {
     $serial = $this->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) . '`');
     }
     if (isset(pb_backupbuddy::$options['backups'][$serial]['integrity']) && count(pb_backupbuddy::$options['backups'][$serial]['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;
     } elseif (pb_backupbuddy::_GET('reset_integrity') == $serial) {
         // Resetting this one.
         pb_backupbuddy::status('details', 'Resetting backup integrity stats for backup with serial `' . $serial . '`.');
     }
     if (pb_backupbuddy::$options['integrity_check'] == '0') {
         // Integrity checking disabled.
         $file_stats = @stat($file);
         if ($file_stats === false) {
             // stat failure.
             pb_backupbuddy::alert('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', 'status_details' => __('Integrity checking disabled based on settings. This file has not been verified.', 'it-l10n-backupbuddy'), 'scan_time' => 0, 'detected_type' => 'unknown', 'size' => $file_size, 'modified' => $file_modified, 'file' => basename($file), 'comment' => false);
         pb_backupbuddy::$options['backups'][$serial]['integrity'] = array_merge(pb_backupbuddy::settings('backups_integrity_defaults'), $integrity);
         pb_backupbuddy::save();
         return;
     }
     // Defaults
     $integrity_checked = true;
     $found_dat = false;
     $found_sql = false;
     $found_wpc = false;
     $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(pb_backupbuddy::$options['backup_directory']);
     }
     // Redirect logging output to a certain log file.
     pb_backupbuddy::set_status_serial('zipbuddy_test');
     // Look for comment.
     $comment = pb_backupbuddy::$classes['zipbuddy']->get_comment($file);
     // Check for DAT file.
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'wp-content/uploads/backupbuddy_temp/' . $serial . '/backupbuddy_dat.php') === true) {
         // Post 2.0 full backup
         $found_dat = true;
         $backup_type = 'full';
     }
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'wp-content/uploads/temp_' . $serial . '/backupbuddy_dat.php') === true) {
         // Pre 2.0 full backup
         $found_dat = true;
         $backup_type = 'full';
     }
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'backupbuddy_dat.php') === true) {
         // DB backup
         $found_dat = true;
         $backup_type = 'db';
     }
     // Check for DB SQL file.
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'wp-content/uploads/backupbuddy_temp/' . $serial . '/db_1.sql') === true) {
         // post 2.0 full backup
         $found_sql = true;
         $backup_type = 'full';
     }
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'wp-content/uploads/temp_' . $serial . '/db.sql') === true) {
         // pre 2.0 full backup
         $found_sql = true;
         $backup_type = 'full';
     }
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'db_1.sql') === true) {
         // db only backup 2.0+
         $found_sql = true;
         $backup_type = 'db';
     }
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'db.sql') === true) {
         // db only backup pre-2.0
         $found_sql = true;
         $backup_type = 'db';
     }
     // Check for WordPress config file.
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'wp-config.php') === true) {
         $found_wpc = true;
         $backup_type = 'full';
     }
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, 'wp-content/uploads/backupbuddy_temp/' . $serial . '/wp-config.php') === true) {
         $found_wpc = true;
         $backup_type = 'full';
     }
     // Calculate status from results.
     $integrity_status = 'pass';
     $integrity_description = '';
     $status_items = pb_backupbuddy::get_status('zipbuddy_test');
     $integrity_zipresult_details = array();
     foreach ((array) $status_items as $status_item) {
         $integrity_zipresult_details[] = $status_item[4];
     }
     $integrity_zipresult_details = implode('<br />', $integrity_zipresult_details);
     // Clear logging to certain file.
     pb_backupbuddy::set_status_serial('');
     // Calculate status descriptions.
     if ($found_dat !== true) {
         $integrity_status = 'fail';
         $integrity_description .= __('Missing .dat file.', 'it-l10n-backupbuddy') . '<br />';
     }
     if ($found_sql !== true) {
         $integrity_status = 'fail';
         $integrity_description .= __('Missing DB SQL file.', 'it-l10n-backupbuddy') . '<br />';
     }
     if ($backup_type == 'full' && $found_wpc !== true) {
         $integrity_status = 'fail';
         $integrity_description .= __('Missing WP config file.', 'it-l10n-backupbuddy') . '<br />';
     }
     $integrity_scantime = time();
     if ($integrity_status == 'pass') {
         // All tests passed.
         $integrity_description = 'All tests passed.';
     } else {
         // One or more test failures encountered.
         $integrity_description .= '<br />' . __('Technical Details', 'it-l10n-backupbuddy') . ':<br />' . $integrity_zipresult_details;
     }
     // Get file information from file system.
     $file_stats = @stat($file);
     if ($file_stats === false) {
         // stat failure.
         pb_backupbuddy::alert('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['ctime'];
         // Created time.
     }
     unset($file_stats);
     // Compile array of results for saving into data structure.
     $integrity = array('status' => $integrity_status, 'status_details' => $integrity_description, 'scan_time' => $integrity_scantime, 'detected_type' => $backup_type, 'size' => $file_size, 'modified' => $file_modified, 'file' => basename($file), 'comment' => $comment);
     pb_backupbuddy::$options['backups'][$serial]['integrity'] = array_merge(pb_backupbuddy::settings('backups_integrity_defaults'), $integrity);
     pb_backupbuddy::save();
     //pb_backupbuddy::$classes['zipbuddy']->clear_status();
     if ($integrity_status == 'pass') {
         // 100% success
         return true;
     } else {
         return false;
     }
 }
<?php

pb_backupbuddy::$ui->title('Multisite Import Site (BETA)' . ' ' . pb_backupbuddy::video('4RmC5nLmabE', __('Multisite import', 'it-l10n-backupbuddy'), false));
pb_backupbuddy::$classes['core']->versions_confirm();
pb_backupbuddy::set_status_serial('ms_import');
/*
// Used for drag & drop / collapsing boxes.
wp_enqueue_style('dashboard');
wp_print_styles('dashboard');
wp_enqueue_script('dashboard');
wp_print_scripts('dashboard');

wp_enqueue_script( 'thickbox' );
wp_print_scripts( 'thickbox' );
wp_print_styles( 'thickbox' );
// Handles resizing thickbox.
if ( !wp_script_is( 'media-upload' ) ) {
	wp_enqueue_script( 'media-upload' );
	wp_print_scripts( 'media-upload' );
}
wp_enqueue_script( 'backupbuddy-ms-export', $this->_parent->_pluginURL . '/js/ms.js', array( 'jquery' ) );
wp_print_scripts( 'backupbuddy-ms-export' );
*/
$action = isset($_GET['action']) ? $_GET['action'] : false;
?>
<div class='wrap'>
<p>For BackupBuddy Multisite documentation, please visit the <a href='http://ithemes.com/codex/page/BackupBuddy_Multisite'>BackupBuddy Multisite Codex</a>.</p>
<?php 
//check_admin_referer( 'bbms-migration', 'pb_bbms_migrate' );
if (!current_user_can('manage_sites')) {
    wp_die(__('You do not have permission to access this page.', 'it-l10n-backupbuddy'));
		if( jQuery( '#' + target_id ).length == 0 ) { // No status box yet so suppress.
			return;
		}
		jQuery( '#' + target_id ).append( "\n" + message );
		textareaelem = document.getElementById( target_id );
		textareaelem.scrollTop = textareaelem.scrollHeight;
	}
	
	function backupbuddy_hourpad(n) { return ("0" + n).slice(-2); }
</script>
<?php 
$success = false;
global $pb_backupbuddy_js_status;
$pb_backupbuddy_js_status = true;
echo pb_backupbuddy::status_box('Restoring . . .');
echo '<div id="pb_backupbuddy_working" style="width: 100px;"><br><center><img src="' . pb_backupbuddy::plugin_url() . '/images/working.gif" title="Working... Please wait as this may take a moment..."></center></div>';
pb_backupbuddy::set_status_serial('restore');
global $wp_version;
pb_backupbuddy::status('details', 'BackupBuddy v' . pb_backupbuddy::settings('version') . ' using WordPress v' . $wp_version . ' on ' . PHP_OS . '.');
$archive_file = pb_backupbuddy::_GET('archive');
// archive to extract from.
require pb_backupbuddy::plugin_path() . '/classes/_restoreFiles.php';
$result = backupbuddy_restore_files::restore(backupbuddy_core::getBackupDirectory() . $archive_file, $files, $finalPath = ABSPATH);
echo '<script type="text/javascript">jQuery("#pb_backupbuddy_working").hide();</script>';
pb_backupbuddy::flush();
if (false === $result) {
} else {
}
pb_backupbuddy::$ui->ajax_footer();
pb_backupbuddy::$ui->ajax_footer();
die;
 public static function run_periodic_process($preferredStep = '', $preferredStepArgs = array())
 {
     require_once pb_backupbuddy::plugin_path() . '/destinations/live/live.php';
     $previous_status_serial = pb_backupbuddy::get_status_serial();
     // Hold current serial.
     pb_backupbuddy::set_status_serial('live_periodic');
     // Redirect logging output to a certain log file.
     global $wp_version;
     $liveID = backupbuddy_live::getLiveID();
     $logging_disabled = isset(pb_backupbuddy::$options['remote_destinations'][$liveID]['disable_logging']) && '1' == pb_backupbuddy::$options['remote_destinations'][$liveID]['disable_logging'];
     if (!$logging_disabled) {
         pb_backupbuddy::status('details', '-----');
         pb_backupbuddy::status('details', 'Live periodic process starting with BackupBuddy v' . pb_backupbuddy::settings('version') . ' with WordPress v' . $wp_version . '.');
     }
     // Make sure we are not PAUSED.
     if ('1' == pb_backupbuddy::$options['remote_destinations'][$liveID]['pause_periodic']) {
         pb_backupbuddy::status('details', 'Aborting periodic process as it is currently PAUSED based on settings.');
         // Undo log redirect.
         pb_backupbuddy::set_status_serial($previous_status_serial);
         return false;
     }
     // Logging disabled.
     if ($logging_disabled) {
         pb_backupbuddy::set_status_serial($previous_status_serial);
     }
     require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
     require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
     // Register a shutdown function to catch PHP errors and log them.
     register_shutdown_function('backupbuddy_live_periodic::shutdown_function');
     // Load state into self::$_state & fileoptions object into self::$_stateObj.
     if (false === self::_load_state()) {
         return false;
     }
     // No PHP runtime calculated yet. Try to see if test is finished.
     if (0 == pb_backupbuddy::$options['tested_php_runtime']) {
         backupbuddy_core::php_runtime_test_results();
     }
     // Update stats and save.
     if (0 === self::$_state['step']['start_time']) {
         self::$_state['step']['start_time'] = microtime(true);
     }
     self::$_state['step']['last_run_start'] = microtime(true);
     // Load destination settings.
     $destination_settings = self::get_destination_settings();
     // If wait_on_transfers was the last step running and time limit has passed then we can start from the beginning.
     if ('wait_on_transfers' == self::$_state['step']['function'] && self::$_state['stats']['wait_on_transfers_start'] > 0 && time() - self::$_state['stats']['wait_on_transfers_start'] > $destination_settings['max_wait_on_transfers_time'] * 60) {
         pb_backupbuddy::status('warning', 'Ran out of max time (`' . round((time() - self::$_state['stats']['wait_on_transfers_start']) / 60) . '` of `' . $destination_settings['max_wait_on_transfers_time'] . '` max mins) waiting for pending transfers to finish. Resetting back to beginning of periodic process.');
         self::$_state['step'] = self::$_stepDefaults;
         // Clear step state.
     }
     // Increment attempts if running the same function exactly as before. Set preferredStep args if we are indeed on this step.
     //sort( self::$_state['step']['args'] ); // Make sure order is same.
     //sort( $preferredStepArgs ); // Make sure order is same.
     if ('' == $preferredStep || self::$_state['step']['function'] == $preferredStep && self::$_state['step']['args'] == $preferredStepArgs) {
         // If preferredStep is blank OR ( preferredStep matches next step AND arguments are the same ).
         self::$_state['step']['attempts']++;
     }
     if ('' != $preferredStep) {
         self::_set_next_step($preferredStep, $preferredStepArgs);
     }
     // If restart transient is set then restart the Live process all the way back to daily_init. This is done when settings are saved so they will take effect immediately.
     if (false !== ($jump_step = get_transient('backupbuddy_live_jump'))) {
         pb_backupbuddy::status('details', 'Restart transient exists. Clearing.');
         delete_transient('backupbuddy_live_jump');
         $jump_step_name = $jump_step[0];
         $jump_step_args = array();
         if (isset($jump_step[1]) && is_array($jump_step[1])) {
             $jump_step_args = $jump_step[1];
         }
         self::_set_next_step($jump_step_name);
         pb_backupbuddy::status('details', 'Reset next step to `' . $jump_step_name . '` with args `' . print_r($jump_step_args, true) . '` due to backupbuddy_live_jump transient.');
     }
     // Check if a manual snapshot is requested.
     if (false !== get_transient('backupbuddy_live_snapshot')) {
         pb_backupbuddy::status('details', 'Manual Live Snapshot requested.');
         delete_transient('backupbuddy_live_snapshot');
         self::_request_manual_snapshot();
     }
     // Set first activity (creation of Live basically).
     if (0 == self::$_state['stats']['first_activity']) {
         self::$_state['stats']['first_activity'] = time();
     }
     // Save attempt.
     self::$_stateObj->save();
     // Run step function and process results.
     $schedule_next_step = false;
     $start_time = microtime(true);
     $run_function = self::$_state['step']['function'];
     pb_backupbuddy::status('details', 'Starting Live periodic function `' . $run_function . '`.');
     if (!is_callable('self::_step_' . $run_function)) {
         pb_backupbuddy::status('error', 'Error #439347494: Invalid step called: `' . $run_function . '` Unknown function: `self::_step_' . $run_function . '`.');
     }
     $function_response = call_user_func_array('self::_step_' . $run_function, self::$_state['step']['args']);
     // Run step function. Returns true on success, string error message on fatal failure, and array( 'status message', array( ARGS ) ) when chunking back to same step.
     self::$_state['step']['last_run_finish'] = microtime(true);
     self::$_state['stats']['last_activity'] = microtime(true);
     pb_backupbuddy::status('details', 'Ended Live periodic function `' . $run_function . '`.');
     // Process stepfunction results.
     if (is_array($function_response)) {
         // Chunking back to same step since we got an array. Index 0 = last_status, index 1 = args. Keeps same step function.
         $schedule_next_step = true;
         self::$_state['step']['chunks']++;
         self::$_state['step']['last_status'] = $function_response[0];
         self::$_state['step']['args'] = $function_response[1];
         pb_backupbuddy::status('details', 'Function needs chunked.');
         if ('update_files_list' != $run_function && pb_backupbuddy::$options['log_level'] == '3') {
             // Full logging enabled. Hide for update_files_list function due to its huge size.
             pb_backupbuddy::status('details', 'Response args due to logging level: `' . print_r($function_response, true) . '`.');
         }
     } elseif (is_string($function_response)) {
         // Fatal error.
         pb_backupbuddy::status('error', 'Error #32893283: One or more errors encountered running Live step function. Details: `' . $function_response . '`. See log above for more details.');
         backupbuddy_core::addNotification('live_error', 'BackupBuddy Stash Live Error', $function_response);
         if (FALSE === stristr($function_response, 'Error')) {
             // Make sure error-prefixed if not.
             $function_response = 'Error #489348: ' . $function_response;
         }
         self::$_state['step']['last_status'] = $function_response;
     } elseif (true === $function_response) {
         // Success finishing this step.
         // Interupted by a jump for the next step.
         if (false !== ($jump_step = get_transient('backupbuddy_live_jump'))) {
             pb_backupbuddy::status('details', 'Restart transient exists. Clearing.');
             delete_transient('backupbuddy_live_jump');
             $jump_step_name = $jump_step[0];
             $jump_step_args = array();
             if (isset($jump_step[1]) && is_array($jump_step[1])) {
                 $jump_step_args = $jump_step[1];
             }
             self::_set_next_step($jump_step_name);
             pb_backupbuddy::status('details', 'Reset next step to `' . $jump_step_name . '` with args `' . print_r($jump_step_args, true) . '` due to backupbuddy_live_jump transient.');
             $schedule_next_step = true;
         } else {
             // Normal next step running (if any).
             if (!isset(self::$_nextFunction[$run_function])) {
                 $schedule_next_step = false;
                 pb_backupbuddy::status('details', 'Function reported success. No more Live steps to directly run. Finishing until next periodic restart.');
                 self::$_state['step'] = self::$_stepDefaults;
                 // Clear step state.
             } else {
                 $schedule_next_step = true;
                 $nextFunction = self::$_nextFunction[$run_function];
                 self::_set_next_step($nextFunction);
                 pb_backupbuddy::status('details', 'Function reported success. Scheduled next function to run, `' . $nextFunction . '`.');
             }
         }
     } elseif (false === $function_response) {
         pb_backupbuddy::status('error', 'Error #3298338: Live (periodic) function `' . $run_function . '` failed without error message. Ending Live periodic process for this run without running more steps. See log above for details.');
         $schedule_next_step = false;
     } else {
         // Unknown response.
         pb_backupbuddy::status('error', 'Error #98238392: Unknown periodic Live step function response `' . print_r($function_response, true) . '` for function `' . $run_function . '`. Fatal error.');
         backupbuddy_core::addNotification('live_error', 'BackupBuddy Stash Live Error', $function_response);
         self::$_state['step']['last_status'] = 'Error: ' . $function_response;
         $schedule_next_step = false;
     }
     // Save state.
     self::$_stateObj->save();
     // Unlock fileoptions files if any remain locked.
     if (is_object(self::$_stateObj)) {
         self::$_stateObj->unlock();
     }
     if (is_object(self::$_catalogObj)) {
         self::$_catalogObj->unlock();
     }
     if (is_object(self::$_tablesObj)) {
         self::$_tablesObj->unlock();
     }
     // Schedule the next step in the WP cron to run whichever step has been set in the state.
     if (true === $schedule_next_step) {
         pb_backupbuddy::status('details', 'Scheduling next step.');
         // Schedule to run Live one more time for next chunk.
         $cronArgs = array();
         $schedule_result = backupbuddy_core::schedule_single_event(time() - 60, 'live_periodic', $cronArgs);
         // Schedules 60sec in the past to push near the top. Traditional backup process is 155sec in the past for first priority.
         if (true === $schedule_result) {
             pb_backupbuddy::status('details', 'Next Live Periodic chunk step cron event scheduled.');
         } else {
             pb_backupbuddy::status('error', 'Next Live Periodic chunk step cron event FAILED to be scheduled.');
         }
         // Only chains the first cron.
         if ('1' != pb_backupbuddy::$options['skip_spawn_cron_call']) {
             pb_backupbuddy::status('details', 'Spawning cron now.');
             update_option('_transient_doing_cron', 0);
             // Prevent cron-blocking for next item.
             spawn_cron(time() + 150);
             // Adds > 60 seconds to get around once per minute cron running limit.
         }
         // Schedule cron kicker (detects if it has not been too soon so we can call this judicously).
         self::_request_kick_cron();
     } else {
         // Nothing left to do for now. Take a nap and wait until the next time that the periodic functionality launches and starts the process all over again.
         pb_backupbuddy::status('details', 'No more steps remain for this run. Not scheduling next step.');
     }
     // Undo log redirect.
     pb_backupbuddy::set_status_serial($previous_status_serial);
     return true;
 }