public function run($arguments)
 {
     $arguments = Ithemes_Sync_Functions::merge_defaults($arguments, $this->default_arguments);
     pb_backupbuddy::$options['remote_destinations'][] = $arguments['settings'];
     pb_backupbuddy::save();
     $newDestination = array();
     $newDestination['title'] = $arguments['settings']['title'];
     $newDestination['type'] = $arguments['settings']['type'];
     backupbuddy_core::addNotification('destination_created', 'Remote destination created', 'A new remote destination "' . $newDestination['title'] . '" has been created.', $newDestination);
     $highest_destination_index = end(array_keys(pb_backupbuddy::$options['remote_destinations']));
     return array('api' => '1', 'status' => 'ok', 'message' => 'Destination added.', 'destination_id' => $highest_destination_index);
 }
Пример #2
0
    return false;
}
$schedule = pb_backupbuddy::settings('schedule_defaults');
$schedule['title'] = $title;
$schedule['profile'] = (int) $profile;
$schedule['interval'] = $interval;
$schedule['first_run'] = $first_run;
$schedule['remote_destinations'] = implode('|', $remote_destinations);
if (true == $delete_after) {
    $schedule['delete_after'] = '1';
} else {
    $schedule['delete_after'] = '0';
}
if (false == $enabled) {
    $schedule['on_off'] = '0';
} else {
    $schedule['on_off'] = '1';
}
$next_index = pb_backupbuddy::$options['next_schedule_index'];
// v2.1.3: $next_index = end( array_keys( pb_backupbuddy::$options['schedules'] ) ) + 1;
pb_backupbuddy::$options['next_schedule_index']++;
// This change will be saved in savesettings function below.
pb_backupbuddy::$options['schedules'][$next_index] = $schedule;
$result = backupbuddy_core::schedule_event($schedule['first_run'], $schedule['interval'], 'pb_backupbuddy-cron_scheduled_backup', array($next_index));
if ($result === false) {
    return 'Error scheduling event with WordPress. Your schedule may not work properly. Please try again. Error #3488439b. Check your BackupBuddy error log for details.';
} else {
    pb_backupbuddy::save();
    backupbuddy_core::addNotification('schedule_created', 'Backup schedule created', 'A new backup schedule "' . $schedule['title'] . '" has been created.', $schedule);
    return true;
}
Пример #3
0
</script>

<?php 
pb_backupbuddy::$ui->title(__('Settings', 'it-l10n-backupbuddy'));
backupbuddy_core::versions_confirm();
pb_backupbuddy::disalert('profile_suggest', '<span class="pb_label" style="font-size: 12px; margin-left: 10px; position: relative;">Tip</span> &nbsp; You can create & customize multiple different backup types with profiles on the <a href="?page=pb_backupbuddy_backup">Backups</a> page by selecting the gear icon next to each profile.');
$data = array();
// To pass to view.
// Reset settings to defaults.
if (pb_backupbuddy::_POST('reset_defaults') != '') {
    pb_backupbuddy::verify_nonce();
    if (call_user_func('pb_backupbuddy::reset_options', true) === true) {
        backupbuddy_core::verify_directories($skipTempGeneration = true);
        // Re-verify directories such as backup dir, temp, etc.
        //pb_backupbuddy::alert( 'Plugin settings have been reset to defaults.' );
        backupbuddy_core::addNotification('settings_reset', 'Plugin settigns reset', 'All plugin settings have been reset to defaults.');
    } else {
        pb_backupbuddy::alert('Unable to reset plugin settings. Verify you are running the latest version.');
    }
}
/* BEGIN VERIFYING BACKUP DIRECTORY */
if (isset($_POST['pb_backupbuddy_backup_directory'])) {
    $backup_directory = pb_backupbuddy::_POST('pb_backupbuddy_backup_directory');
    if ('' == $backup_directory) {
        // blank so set to default.
        $backup_directory = backupbuddy_core::_getBackupDirectoryDefault();
    }
    $backup_directory = str_replace('\\', '/', $backup_directory);
    $backup_directory = rtrim($backup_directory, '/\\') . '/';
    // Enforce single trailing slash.
    if (!is_dir($backup_directory)) {
Пример #4
0
 function process_backup($serial, $trigger = 'manual')
 {
     //pb_backupbuddy::status( 'details', 'Running process_backup() for serial `' . $serial . '`.' );
     // Assign reference to backup data structure for this backup.
     if (!isset($this->_backup_options)) {
         pb_backupbuddy::status('details', 'About to load fileoptions data for serial `' . $serial . '`.');
         $attempt_transient_prefix = 'pb_backupbuddy_lock_attempts-';
         require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
         pb_backupbuddy::status('details', 'Fileoptions instance #39.');
         $this->_backup_options = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt');
         if (true !== ($result = $this->_backup_options->is_ok())) {
             // Unable to access fileoptions.
             $attempt_delay_base = 10;
             // Base number of seconds to delay. Each subsequent attempt increases this delay by a multiple of the attempt number.
             $max_attempts = 8;
             // Max number of attempts to try to delay around a file lock. Delay increases each time.
             $this->_backup['serial'] = $serial;
             // Needs to be populated for use by cron schedule step.
             pb_backupbuddy::status('warning', __('Warning #9034 B. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Warning: ' . $result, $serial);
             // Track lock attempts in transient system. This is not vital & since locks may be having issues track this elsewhere.
             $lock_attempts = get_transient($attempt_transient_prefix . $serial);
             if (false === $lock_attempts) {
                 $lock_attempts = 0;
             }
             $lock_attempts++;
             set_transient($attempt_transient_prefix . $serial, $lock_attempts, 60 * 60 * 24);
             // Increment lock attempts. Hold attempt count for 24 hours to help make sure we don't lose attempt count if very low site activity, etc.
             if ($lock_attempts > $max_attempts) {
                 pb_backupbuddy::status('error', 'Backup halted. Maximum number of attempts made attempting to access locked fileoptions file. This may be caused by something causing backup steps to run out of order or file permission issues on the temporary directory holding the file `' . $fileoptions_file . '`. Verify correct permissions.', $serial);
                 pb_backupbuddy::status('haltScript', '', $serial);
                 // Halt JS on page.
                 delete_transient($attempt_transient_prefix . $serial);
                 return false;
             }
             $wait_time = $attempt_delay_base * $lock_attempts;
             pb_backupbuddy::status('message', 'A scheduled step attempted to run before the previous step completed. The previous step may have failed or two steps may be attempting to run simultaneously.', $serial);
             pb_backupbuddy::status('message', 'Waiting `' . $wait_time . '` seconds before continuing. Attempt #' . $lock_attempts . ' of ' . $max_attempts . ' max allowed before giving up.', $serial);
             $this->cron_next_step(false, $wait_time);
             return false;
         } else {
             // Accessed fileoptions. Clear/reset any attempt count.
             delete_transient($attempt_transient_prefix . $serial);
         }
         pb_backupbuddy::status('details', 'Fileoptions data loaded.');
         $this->_backup =& $this->_backup_options->options;
     }
     if ('-1' == $this->_backup_options->options['finish_time']) {
         pb_backupbuddy::status('details', 'Warning #8328332: This backup is marked as cancelled. Halting.');
         return false;
     }
     if ($this->_backup_options->options['profile']['backup_mode'] != '1') {
         // Only check for cronPass action if in modern mode.
         pb_backupbuddy::status('finishAction', 'cronPass');
     }
     // Handle cancelled backups (stop button).
     if (true == get_transient('pb_backupbuddy_stop_backup-' . $serial)) {
         // Backup flagged for stoppage. Proceed directly to cleanup.
         pb_backupbuddy::status('message', 'Backup STOPPED by user. Post backup cleanup step has been scheduled to clean up any temporary files.');
         foreach ($this->_backup['steps'] as $step_id => $step) {
             if ($step['function'] != 'post_backup') {
                 if ($step['start_time'] == 0) {
                     $this->_backup['steps'][$step_id]['start_time'] = -1;
                     // Flag for skipping.
                 }
             } else {
                 // Post backup step.
                 $this->_backup['steps'][$step_id]['args'] = array(true, true);
                 // Run post_backup in fail mode & delete backup file.
             }
         }
         //pb_backupbuddy::save();
         $this->_backup_options->save();
         pb_backupbuddy::status('haltScript', '');
         // Halt JS on page.
     }
     $found_next_step = false;
     //pb_backupbuddy::status( 'details', 'Steps: ' . print_r( $this->_backup['steps'], true ) );
     //pb_backupbuddy::status( 'details', 'FullOptions: ' . print_r( $this->_backup, true ) );
     // Loop through steps finding first step that has not run.
     $foundComplete = 0;
     foreach ((array) $this->_backup['steps'] as $step_index => $step) {
         $this->_currentStepIndex = $step_index;
         //pb_backupbuddy::status( 'details', 'step: ' . $step['function'] . 'start: ' . $step['start_time'] );
         if ($step['start_time'] != -1 && $step['start_time'] != 0 && $step['finish_time'] == 0) {
             // A step is not marked for skippage, has begun but has not finished. This should not happen but the WP cron is funky. Wait a while before continuing.
             // Re-load, respecting locks to help avoid race conditions.
             $this->_backup_options->load($ignore_lock = false, $create_file = false, $retryCount = 0);
             if (true !== $this->_backup_options->is_ok()) {
                 // Unable to access fileoptions.
                 pb_backupbuddy::status('warning', 'Unable to update out of order step attempt count due to file lock. It may be being written to by the other step at this moment.');
             } else {
                 pb_backupbuddy::status('details', 'Saving update to step attempt count.');
                 $this->_backup['steps'][$step_index]['attempts']++;
                 // Increment this as an attempt.
                 $this->_backup_options->save();
             }
             if ($step['attempts'] < 6) {
                 $wait_time = 60 * $step['attempts'];
                 // Each attempt adds a minute of wait time.
                 pb_backupbuddy::status('warning', 'A scheduled step attempted to run before the previous step completed. Waiting `' . $wait_time . '` seconds before continuing for it to catch up. Attempt number `' . $step['attempts'] . '`.');
                 $this->cron_next_step(false, $wait_time);
                 return false;
             } else {
                 // Too many attempts to run this step.
                 pb_backupbuddy::status('error', 'A scheduled step attempted to run before the previous step completed. After several attempts (`' . $step['attempts'] . '`) of failure BackupBuddy has given up. Halting backup.');
                 return false;
             }
             break;
         } elseif ($step['start_time'] == 0) {
             // Step that is not marked for skippage and has not started yet.
             $found_next_step = true;
             $this->_backup['steps'][$step_index]['start_time'] = microtime(true);
             // Set this step time to now.
             $this->_backup['steps'][$step_index]['attempts']++;
             // Increment this as an attempt.
             $this->_backup_options->save();
             pb_backupbuddy::status('details', 'Found next step to run: `' . $step['function'] . '`.');
             break;
             // Break out of foreach loop to continue.
         } elseif ($step['start_time'] == -1) {
             // Step flagged for skipping. Do not run.
             pb_backupbuddy::status('details', 'Step `' . $step['function'] . '` flagged for skipping. Skipping.');
         } else {
             // Last case: Finished. Skip.
             // Do nothing for completed steps.
             $foundComplete++;
         }
     }
     // End foreach().
     if ($found_next_step === false) {
         // No more steps to perform; return.
         // NOTE: This should normally NOT be seen.  If it is run then a cron was scheduled despite there being no steps left which would not make sense.  This does appear some though as of Jul 22, 2015 for unknown reasons.  Missing post_backup() function?
         pb_backupbuddy::status('details', 'Backup steps:');
         pb_backupbuddy::status('details', print_r($this->_backup['steps'], true));
         pb_backupbuddy::status('warning', 'No more unfinished steps found. This is unexpected usually not normal though may not be harmful to the backup. Total found completed: `' . $foundComplete . '`.');
         return false;
     }
     //pb_backupbuddy::save();
     pb_backupbuddy::status('details', __('Peak memory usage', 'it-l10n-backupbuddy') . ': ' . round(memory_get_peak_usage() / 1048576, 3) . ' MB');
     /********* Begin Running Step Function **********/
     if (method_exists($this, $step['function'])) {
         /*
         $args = '';
         foreach( $step['args'] as $arg ) {
         	if ( is_array( $arg ) ) {
         		$args .= '{' . implode( ',', $arg ) . '},';
         	} else {
         		$args .= str_replace('],[', '|', trim(json_encode($step['args']), '[]'));
         	}
         }
         */
         pb_backupbuddy::status('details', '-----');
         pb_backupbuddy::status('details', 'Starting step function `' . $step['function'] . '`. Attempt #' . ($step['attempts'] + 1) . '.');
         // attempts 0-indexed.
         $functionTitle = $step['function'];
         $subFunctionTitle = '';
         $functionTitle = backupbuddy_core::prettyFunctionTitle($step['function'], $step['args']);
         pb_backupbuddy::status('startFunction', json_encode(array('function' => $step['function'], 'title' => $functionTitle)));
         if ('' != $subFunctionTitle) {
             pb_backupbuddy::status('startSubFunction', json_encode(array('function' => $step['function'] . '_subfunctiontitle', 'title' => $subFunctionTitle)));
         }
         $response = call_user_func_array(array(&$this, $step['function']), $step['args']);
     } else {
         pb_backupbuddy::status('error', __('Error #82783745: Invalid function `' . $step['function'] . '`'));
         $response = false;
     }
     /********* End Running Step Function **********/
     //unset( $step );
     if ($response === false) {
         // Function finished but reported failure.
         // Failure caused by backup cancellation.
         if (true == get_transient('pb_backupbuddy_stop_backup-' . $serial)) {
             pb_backupbuddy::status('haltScript', '');
             // Halt JS on page.
             return false;
         }
         pb_backupbuddy::status('error', 'Failed function `' . $this->_backup['steps'][$step_index]['function'] . '`. Backup terminated.');
         pb_backupbuddy::status('errorFunction', $this->_backup['steps'][$step_index]['function']);
         pb_backupbuddy::status('details', __('Peak memory usage', 'it-l10n-backupbuddy') . ': ' . round(memory_get_peak_usage() / 1048576, 3) . ' MB');
         pb_backupbuddy::status('haltScript', '');
         // Halt JS on page.
         $args = print_r($this->_backup['steps'][$step_index]['args'], true);
         $attachment = NULL;
         $attachment_note = 'Enable full logging for troubleshooting (a log will be sent with future error emails while enabled).';
         if (pb_backupbuddy::$options['log_level'] == '3') {
             // Full logging enabled.
             // Log file will be attached.
             $log_file = backupbuddy_core::getLogDirectory() . 'status-' . $serial . '_' . pb_backupbuddy::$options['log_serial'] . '.txt';
             if (file_exists($log_file)) {
                 $attachment = $log_file;
                 $attachment_note = 'A log file is attached which may provide further details.';
             } else {
                 $attachment = NULL;
             }
         }
         // Send error notification email.
         backupbuddy_core::mail_error('One or more backup steps reported a failure. ' . $attachment_note . ' Backup failure running function `' . $this->_backup['steps'][$step_index]['function'] . '` with the arguments `' . $args . '` with backup serial `' . $serial . '`. Please run a manual backup of the same type to verify backups are working properly or view the backup status log.', NULL, $attachment);
         return false;
     } else {
         // Function finished successfully.
         $this->_backup['steps'][$step_index]['finish_time'] = microtime(true);
         if ('backup_create_database_dump' != $this->_backup['steps'][$step_index]['function'] && 'send_remote_destination' != $this->_backup['steps'][$step_index]['function']) {
             // Wipe arguments.  Keeps fileoptions for growing crazily for finished steps containing state data such as deployment or new zip functionality passing chunking state.
             $this->_backup['steps'][$step_index]['args'] = time();
         }
         $this->_backup['updated_time'] = microtime(true);
         $this->_backup_options->save();
         pb_backupbuddy::status('details', sprintf(__('Finished function `%s`. Peak memory usage', 'it-l10n-backupbuddy') . ': ' . round(memory_get_peak_usage() / 1048576, 3) . ' MB', $this->_backup['steps'][$step_index]['function']) . ' with BackupBuddy v' . pb_backupbuddy::settings('version')) . '.';
         pb_backupbuddy::status('finishFunction', json_encode(array('function' => $this->_backup['steps'][$step_index]['function'])));
         pb_backupbuddy::status('details', '-----');
         $found_another_step = false;
         foreach ($this->_backup['steps'] as $next_step) {
             // Loop through each step and see if any have not started yet.
             if ($next_step['start_time'] == 0) {
                 // Another unstarted step exists. Schedule it.
                 $found_another_step = true;
                 if ($this->_backup['profile']['backup_mode'] == '2') {
                     // Modern mode with crons.
                     $this->cron_next_step(null, null, $next_step['function']);
                 } elseif ($this->_backup['profile']['backup_mode'] == '1') {
                     // classic mode
                     pb_backupbuddy::status('details', 'Classic mode; skipping cron & triggering next step.');
                     $this->process_backup($this->_backup['serial'], $trigger);
                 } else {
                     pb_backupbuddy::status('error', 'Error #3838932: Fatal error. Unknown backup mode `' . $this->_backup['profile']['backup_mode'] . '`. Expected 1 (classic) or 2 (modern).');
                     return false;
                 }
                 break;
             }
         }
         // End foreach().
         if ($found_another_step == false) {
             pb_backupbuddy::status('details', __('No more backup steps remain. Finishing...', 'it-l10n-backupbuddy'));
             $this->_backup['finish_time'] = microtime(true);
             $this->_backup_options->save();
             pb_backupbuddy::status('startFunction', json_encode(array('function' => 'backup_success', 'title' => __('Backup completed successfully.', 'it-l10n-backupbuddy'))));
             pb_backupbuddy::status('finishFunction', json_encode(array('function' => 'backup_success')));
             // Notification for manual and scheduled backups (omits deployment stuff).
             if ($this->_backup['trigger'] == 'manual' || 'scheduled' == $this->_backup['trigger']) {
                 $data = array();
                 $data['serial'] = $this->_backup['serial'];
                 $data['type'] = $this->_backup['type'];
                 $data['profile_title'] = $this->_backup['profile']['title'];
                 if ('' != $this->_backup['schedule_title']) {
                     $data['schedule_title'] = $this->_backup['schedule_title'];
                 }
                 backupbuddy_core::addNotification('backup_success', 'Backup completed successfully', 'A ' . $this->_backup['trigger'] . ' backup has completed successfully on your site.', $data);
             }
         } else {
             pb_backupbuddy::status('details', 'Completed step function `' . $step['function'] . '`.');
             //pb_backupbuddy::status( 'details', 'The next should run in a moment. If it does not please check for plugin conflicts and that the next step is scheduled in the cron on the Server Information page.' );
         }
         // If full logging, output fileoptions state data to brwoser for display in console.
         if (pb_backupbuddy::$options['log_level'] == '3') {
             // Full logging enabled.
             $thisBackup = $this->_backup;
             if ('' != $this->_backup['deployment_direction']) {
                 // Remove steps for deployment because it gets too large.
                 $thisBackup['steps'] = '** Removed since deployment type **';
             }
             pb_backupbuddy::status('backupState', json_encode($thisBackup));
             //base64_encode( json_encode( $this->_backup ) ) );
         }
         return true;
     }
 }
Пример #5
0
        //echo 'first: ' . $first_run;
        $next_scheduled_time = wp_next_scheduled('pb_backupbuddy-cron_scheduled_backup', array((int) $_GET['edit']));
        $result = backupbuddy_core::unschedule_event($next_scheduled_time, 'pb_backupbuddy-cron_scheduled_backup', array((int) $_GET['edit']));
        // Remove old schedule. pb_backupbuddy::$options['schedules'][$_GET['edit']]['first_run']
        if ($result === FALSE) {
            pb_backupbuddy::alert('Error #589689. Unable to unschedule scheduled cron job with WordPress. Please see your BackupBuddy error log for details.');
        }
        $result = backupbuddy_core::schedule_event($first_run, $submitted_schedule['data']['interval'], 'pb_backupbuddy-cron_scheduled_backup', array((int) $_GET['edit']));
        // Add new schedule.
        if ($result === FALSE) {
            pb_backupbuddy::alert('Error scheduling event with WordPress. Your schedule may not work properly. Please try again. Error #3488439. Check your BackupBuddy error log for details.', true);
        }
        pb_backupbuddy::save();
        //pb_backupbuddy::alert( 'Edited schedule `' . htmlentities( $submitted_schedule['data']['title'] ) . '`.' );
        $editedSchedule = $submitted_schedule['data'];
        backupbuddy_core::addNotification('schedule_updated', 'Backup schedule updated', 'An existing schedule "' . $editedSchedule['title'] . '" has been updated.', $editedSchedule);
    }
} elseif (count($submitted_schedule['errors']) > 0) {
    foreach ($submitted_schedule['errors'] as $error) {
        pb_backupbuddy::alert($error);
    }
}
$data['schedule_form'] = $schedule_form;
// Validate that all internal schedules are properly registered in the WordPress cron
backupbuddy_core::validateSchedules();
$schedules = array();
foreach (pb_backupbuddy::$options['schedules'] as $schedule_id => $schedule) {
    $profile = pb_backupbuddy::$options['profiles'][(int) $schedule['profile']];
    $title = $schedule['title'];
    if ($profile['type'] == 'full') {
        $type = 'Full';
Пример #6
0
        // ADD NEW.
        // Copy over dropbox token.
        $save_result['data']['token'] = pb_backupbuddy::$options['dropboxtemptoken'];
        pb_backupbuddy::$options['remote_destinations'][] = $save_result['data'];
        $newDestination = array();
        $newDestination['title'] = $save_result['data']['title'];
        $newDestination['type'] = $save_result['data']['type'];
        backupbuddy_core::addNotification('destination_created', 'Remote destination created', 'A new remote destination "' . $newDestination['title'] . '" has been created.', $newDestination);
        pb_backupbuddy::save();
        echo 'Destination Added.';
    } elseif (!isset(pb_backupbuddy::$options['remote_destinations'][$destination_id])) {
        // EDITING NONEXISTANT.
        echo 'Error #54859. Invalid destination ID `' . $destination_id . '`.';
    } else {
        // EDITING EXISTING -- Save!
        // Copy over dropbox token.
        //$token_copy_holder = pb_backupbuddy::$options['remote_destinations'][$destination_id]['token'];
        pb_backupbuddy::$options['remote_destinations'][$destination_id] = array_merge(pb_backupbuddy::$options['remote_destinations'][$destination_id], $save_result['data']);
        //echo '<pre>' . print_r( pb_backupbuddy::$options['remote_destinations'][$destination_id], true ) . '</pre>';
        pb_backupbuddy::save();
        echo 'Settings saved.';
        $editedDestination = array();
        $editedDestination['title'] = $save_result['data']['title'];
        $editedDestination['type'] = $save_result['data']['type'];
        backupbuddy_core::addNotification('destination_updated', 'Remote destination updated', 'An existing remote destination "' . $editedDestination['title'] . '" has been updated.', $editedDestination);
    }
} else {
    echo "Error saving settings.\n\n";
    echo implode("\n", $save_result['errors']);
}
die;
Пример #7
0
// Reset settings to defaults.
if (pb_backupbuddy::_POST('reset_defaults') != '') {
    pb_backupbuddy::verify_nonce();
    $keepDestNote = '';
    $remote_destinations = pb_backupbuddy::$options['remote_destinations'];
    pb_backupbuddy::$options = pb_backupbuddy::settings('default_options');
    if ('1' == pb_backupbuddy::_POST('keep_destinations')) {
        pb_backupbuddy::$options['remote_destinations'] = $remote_destinations;
        $keepDestNote = ' ' . __('Remote destination settings were not reset.', 'it-l10n-backupbuddy');
    }
    pb_backupbuddy::save();
    backupbuddy_core::verify_directories($skipTempGeneration = true);
    // Re-verify directories such as backup dir, temp, etc.
    $resetNote = __('Plugin settings have been reset to defaults.', 'it-l10n-backupbuddy');
    pb_backupbuddy::alert($resetNote . $keepDestNote);
    backupbuddy_core::addNotification('settings_reset', 'Plugin settings reset', $resetNote . $keepDestNote);
}
/* BEGIN VERIFYING BACKUP DIRECTORY */
if (isset($_POST['pb_backupbuddy_backup_directory'])) {
    $backup_directory = pb_backupbuddy::_POST('pb_backupbuddy_backup_directory');
    if ('' == $backup_directory) {
        // blank so set to default.
        $backup_directory = backupbuddy_core::_getBackupDirectoryDefault();
    }
    $backup_directory = str_replace('\\', '/', $backup_directory);
    $backup_directory = rtrim($backup_directory, '/\\') . '/';
    // Enforce single trailing slash.
    if (!is_dir($backup_directory)) {
        if (false === @mkdir($backup_directory, 0755)) {
            pb_backupbuddy::alert('Error #4838594589: Selected backup directory does not exist and it could not be created. Verify the path is correct or manually create the directory and set proper permissions. Reset to default path.');
            $_POST['pb_backupbuddy_backup_directory'] = backupbuddy_core::getBackupDirectory();
Пример #8
0
</span></h3>
					<div class="inside">
						<label><?php 
    _e('Malware', 'it-l10n-backupbuddy');
    ?>
</label>
						<?php 
    if (!empty($scan['MALWARE']['WARN'])) {
        // Malware found.
        echo lined_array($scan['MALWARE']['WARN']);
        backupbuddy_core::addNotification('malware_found', 'Malware detected on `' . $url . '`.', 'A malware scan was run on the site and detected malware.', array(), true);
        // Urgent
    } else {
        // No malware found.
        echo '<i>', __('none', 'it-l10n-backupbuddy'), '</i><br />';
        backupbuddy_core::addNotification('malware_not_found', 'No malware detected on `' . $url . '`.', 'A malware scan was run on the site and did not detect malware.');
    }
    ?>
<br />
					</div>
				</div>
				
				<div id="breadcrumbslike" class="postbox">
					<div class="handlediv" title="<?php 
    _e('Click to toggle', 'it-l10n-backupbuddy');
    ?>
"><br /></div>
					<h3 class="hndle"><span><?php 
    _e('Web server details', 'it-l10n-backupbuddy');
    ?>
</span></h3>
Пример #9
0
<?php

if (true !== $confirm) {
    return false;
}
$next_scheduled_time = wp_next_scheduled('pb_backupbuddy-cron_scheduled_backup', array((int) $scheduleID));
if (FALSE === backupbuddy_core::unschedule_event($next_scheduled_time, 'pb_backupbuddy-cron_scheduled_backup', array((int) $scheduleID))) {
    return false;
}
$deletedSchedule = pb_backupbuddy::$options['schedules'][$scheduleID];
unset(pb_backupbuddy::$options['schedules'][$scheduleID]);
pb_backupbuddy::save();
backupbuddy_core::addNotification('schedule_deleted', 'Backup schedule deleted', 'An existing backup schedule "' . $deletedSchedule['title'] . '" has been deleted.', $deletedSchedule);
return true;
Пример #10
0
 public static function delete_destination($destination_id, $confirm = false)
 {
     if ($confirm === false) {
         return 'Error #54858597. Not deleted. Confirmation parameter missing.';
     }
     // Delete destination.
     $deletedDestination = array();
     $deletedDestination['type'] = pb_backupbuddy::$options['remote_destinations'][$destination_id]['type'];
     $deletedDestination['title'] = pb_backupbuddy::$options['remote_destinations'][$destination_id]['title'];
     unset(pb_backupbuddy::$options['remote_destinations'][$destination_id]);
     // Remove this destination from all schedules using it.
     foreach (pb_backupbuddy::$options['schedules'] as $schedule_id => $schedule) {
         $remote_list = '';
         $trimmed_destination = false;
         $remote_destinations = explode('|', $schedule['remote_destinations']);
         foreach ($remote_destinations as $remote_destination) {
             if ($remote_destination == $destination_id) {
                 $trimmed_destination = true;
             } else {
                 $remote_list .= $remote_destination . '|';
             }
         }
         if ($trimmed_destination === true) {
             pb_backupbuddy::$options['schedules'][$schedule_id]['remote_destinations'] = $remote_list;
         }
     }
     // end foreach.
     pb_backupbuddy::save();
     backupbuddy_core::addNotification('destination_deleted', 'Remote destination deleted', 'An existing remote destination "' . $deletedDestination['title'] . '" has been deleted.', $deletedDestination);
     return true;
 }
Пример #11
0
 public static function _step_run_remote_snapshot()
 {
     if (false === self::_load_state()) {
         return false;
     }
     // If not all files have uploaded, skip snapshot for now.
     if (self::$_state['stats']['files_pending_send'] > 0 || self::$_state['stats']['tables_pending_send'] > 0) {
         pb_backupbuddy::status('details', '`' . self::$_state['stats']['files_pending_send'] . '` files and `' . self::$_state['stats']['tables_pending_send'] . '` database tables are still pending transfer. Waiting for transfers to finish before creating Snapshot.');
         self::$_state['stats']['wait_on_transfers_start'] = microtime(true);
         backupbuddy_live::queue_step($step = 'wait_on_transfers', $args = array(), $skip_run_now = true);
         return true;
     }
     if (0 == self::$_state['stats']['files_total_count'] || 0 == self::$_state['stats']['tables_total_count']) {
         $error = 'Error #3489349834: Made it to the snapshot stage but there are zero files and/or tables. Halting to protect backup integrity. Files: `' . self::$_state['stats']['files_total_count'] . '`. Tables: `' . self::$_state['stats']['tables_total_count'] . '`.';
         backupbuddy_core::addNotification('live_error', 'BackupBuddy Stash Live Error', $error);
         return $error;
     }
     if (false !== self::$_state['stats']['manual_snapshot']) {
         pb_backupbuddy::status('details', 'Manual snapshot requested at `' . pb_backupbuddy::$format->date(pb_backupbuddy::$format->localize_time(self::$_state['stats']['manual_snapshot'])) . '` (' . pb_backupbuddy::$format->time_ago(self::$_state['stats']['manual_snapshot']) . ' ago). Triggering remote snapshot now.');
         $trigger = 'manual';
     } else {
         $trigger = 'automatic';
         $destination_settings = self::get_destination_settings();
         $schedule_times = wp_get_schedules();
         if (!isset($schedule_times[$destination_settings['remote_snapshot_period']])) {
             pb_backupbuddy::status('error', 'Error #383927494: Invalid schedule interval/period `' . $destination_settings['remote_snapshot_period'] . '`. Not found in wp_get_schedules().');
             return false;
         }
         $delay_between_runs = $schedule_times[$destination_settings['remote_snapshot_period']]['interval'];
         $adjusted_delay_between_runs = $delay_between_runs - self::REMOTE_SNAPSHOT_PERIOD_WIGGLE_ROOM;
         $time_since_last_run = microtime(true) - self::$_state['stats']['last_remote_snapshot'];
         pb_backupbuddy::status('details', 'Period between remote snapshots: `' . $destination_settings['remote_snapshot_period'] . '` (`' . $delay_between_runs . '` seconds). Time since last run: `' . $time_since_last_run . '`. Allowed to run `' . self::REMOTE_SNAPSHOT_PERIOD_WIGGLE_ROOM . '` secs early. Adjusted min delay between runs: `' . $adjusted_delay_between_runs . '`.');
         if ($time_since_last_run < $adjusted_delay_between_runs) {
             pb_backupbuddy::status('details', 'Not enough time has passed since last remote snapshot. Skipping this pass.');
             return true;
         }
         // Made it here so trigger remote snapshot.
         pb_backupbuddy::status('details', 'Enough time has passed since last remote snapshot. Triggering remote snapshot now.');
     }
     $response = backupbuddy_live_periodic::_run_remote_snapshot($trigger);
     if (!is_array($response)) {
         $error = 'Error #2397734: Unable to initiate Live snapshot. See log above for details or here: `' . $response . '`.';
         pb_backupbuddy::status('error', $error);
         backupbuddy_core::addNotification('live_error', 'BackupBuddy Stash Live Error', $error);
         return false;
     } else {
         // Either triggered snapshot or one already running.
         if (true === $response['success']) {
             // Triggered new snapshot.
             $snapshot_id = $response['snapshot'];
             backupbuddy_live_periodic::update_last_remote_snapshot_time($snapshot_id);
             pb_backupbuddy::status('details', 'Triggered new remote snapshot with ID `' . $snapshot_id . '`.');
             // TODO: Keeping in place until new tmtrim-settings and passing tmtrim data with snapshot trigger is verified. Deprecating as of 7.0.5.5.
             // Schedule to run trim cleanup.
             $cronArgs = array();
             $schedule_result = backupbuddy_core::schedule_single_event(time() + 60 * 60, 'live_after_snapshot', $cronArgs);
             // 1hr
             if (true === $schedule_result) {
                 pb_backupbuddy::status('details', 'Next Live trim cron event scheduled.');
             } else {
                 pb_backupbuddy::status('error', 'Next Live trim cron event FAILED to be scheduled.');
             }
             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.
             }
             return true;
         } elseif (false === $response['success']) {
             // Failed to trigger new snapshot. Most likely one is already in progress.
             if (isset($response['snapshot'])) {
                 pb_backupbuddy::status('details', 'Did NOT trigger a new snapshot. One is already in progress with ID `' . $response['snapshot'] . '`.');
                 return true;
             } else {
                 pb_backupbuddy::status('error', 'Error #2898923: Something went wrong triggering snapshot. Details: `' . print_r($response) . '`.');
                 return false;
             }
         } else {
             pb_backupbuddy::status('error', 'Error #3832792397: Something went wrong triggering snapshot. Details: `' . print_r($response) . '`.');
             return false;
         }
     }
     pb_backupbuddy::status('error', 'Error #8028434. This should never happen. This code should not be reached.');
     return false;
 }