Esempio n. 1
0
    backupbuddy_core::verify_directories();
    require_once pb_backupbuddy::plugin_path() . '/controllers/activation.php';
}
unset($options);
// Check if data version is behind & run activation upgrades if needed.
$default_options = pb_backupbuddy::settings('default_options');
if (pb_backupbuddy::$options['data_version'] < $default_options['data_version']) {
    backupbuddy_core::verify_directories();
    pb_backupbuddy::status('details', 'Data structure version of `' . pb_backupbuddy::$options['data_version'] . '` behind current version of `' . $default_options['data_version'] . '`. Running activation upgrade.');
    require_once pb_backupbuddy::plugin_path() . '/controllers/activation.php';
}
/* END HANDLING DATA STRUCTURE UPGRADE */
// Schedule daily housekeeping.
if (false === wp_next_scheduled(pb_backupbuddy::cron_tag('housekeeping'))) {
    // if schedule does not exist...
    backupbuddy_core::schedule_event(time() + 60 * 60 * 2, 'daily', pb_backupbuddy::cron_tag('housekeeping'), array());
    // Add schedule.
}
/********** ACTIONS (admin) **********/
// Set up reminders if enabled.
if (pb_backupbuddy::$options['backup_reminders'] == '1') {
    pb_backupbuddy::add_action(array('load-update-core.php', 'wp_update_backup_reminder'));
    pb_backupbuddy::add_action(array('post_updated_messages', 'content_editor_backup_reminder_on_update'));
}
// Display warning to network activate if running in normal mode on a MultiSite Network.
if (is_multisite() && !backupbuddy_core::is_network_activated()) {
    pb_backupbuddy::add_action(array('all_admin_notices', 'multisite_network_warning'));
    // BB should be network activated while on Multisite.
}
/********** AJAX (admin) **********/
// Backup process.
 function pre_backup($serial, $archiveFile, $profile, $trigger, $pre_backup = array(), $post_backup = array(), $schedule_title = '', $export_plugins = array(), $deployDirection, $deployDestinationSettings)
 {
     pb_backupbuddy::status('startFunction', json_encode(array('function' => 'pre_backup', 'title' => 'Getting ready to backup')));
     $type = $profile['type'];
     // Log some status information.
     pb_backupbuddy::status('details', __('Performing pre-backup procedures.', 'it-l10n-backupbuddy'));
     if ($type == 'full') {
         pb_backupbuddy::status('message', __('Full backup mode.', 'it-l10n-backupbuddy'));
     } elseif ($type == 'db') {
         pb_backupbuddy::status('message', __('Database only backup mode.', 'it-l10n-backupbuddy'));
     } elseif ($type == 'files') {
         pb_backupbuddy::status('message', __('Files only backup mode.', 'it-l10n-backupbuddy'));
         //$profile['skip_database_dump'] = '1';
     } elseif ($type == 'export') {
         pb_backupbuddy::status('message', __('Multisite subsite export mode.', 'it-l10n-backupbuddy'));
     } else {
         pb_backupbuddy::status('error', 'Error #8587383: Unknown backup mode `' . htmlentities($type) . '`.');
     }
     if ('' != $deployDirection) {
         pb_backupbuddy::status('details', 'Deployment direction: `' . $deployDirection . '`.');
     }
     if ('1' == pb_backupbuddy::$options['prevent_flush']) {
         pb_backupbuddy::status('details', 'Flushing will be skipped based on advanced settings.');
     } else {
         pb_backupbuddy::status('details', 'Flushing will not be skipped (default).');
     }
     // Schedule daily housekeeping.
     if (false === wp_next_scheduled(pb_backupbuddy::cron_tag('housekeeping'))) {
         // if schedule does not exist...
         backupbuddy_core::schedule_event(time() + 60 * 60 * 2, 'daily', pb_backupbuddy::cron_tag('housekeeping'), array());
         // Add schedule.
     }
     // Verify directories.
     pb_backupbuddy::status('details', 'Verifying directories ...');
     if (false === backupbuddy_core::verify_directories()) {
         pb_backupbuddy::status('error', 'Error #18573. Error verifying directories. See details above. Backup halted.');
         pb_backupbuddy::status('haltScript', '');
         // Halt JS on page.
         die;
     } else {
         pb_backupbuddy::status('details', 'Directories verified.');
     }
     // Delete all backup archives if this troubleshooting option is enabled.
     if (pb_backupbuddy::$options['delete_archives_pre_backup'] == '1') {
         pb_backupbuddy::status('message', 'Deleting all existing backups prior to backup as configured on the settings page.');
         $file_list = glob(backupbuddy_core::getBackupDirectory() . 'backup*.zip');
         if (is_array($file_list) && !empty($file_list)) {
             foreach ($file_list as $file) {
                 if (@unlink($file) === true) {
                     pb_backupbuddy::status('details', 'Deleted backup archive `' . basename($file) . '` based on settings to delete all backups.');
                 } else {
                     pb_backupbuddy::status('details', 'Unable to delete backup archive `' . basename($file) . '` based on settings to delete all backups. Verify permissions.');
                 }
             }
         }
     }
     // Generate unique serial ID.
     pb_backupbuddy::status('details', 'Backup serial generated: `' . $serial . '`.');
     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 #9034 A. 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.
     // Cleanup internal stats. Deployments should not impact stats.
     if ('' == $deployDirection) {
         pb_backupbuddy::status('details', 'Updating statistics for last backup start.');
         pb_backupbuddy::$options['last_backup_start'] = time();
         // Reset time since last backup.
         pb_backupbuddy::$options['last_backup_serial'] = $serial;
         pb_backupbuddy::save();
     }
     // Output active plugins list for debugging...
     $activePlugins = get_option('active_plugins');
     pb_backupbuddy::status('details', 'Active WordPress plugins: `' . implode('; ', $activePlugins) . '`.');
     pb_backupbuddy::status('startSubFunction', json_encode(array('function' => 'wp_plugins_found', 'title' => 'Found ' . count($activePlugins) . ' active WordPress plugins.')));
     unset($activePlugins);
     // Compression to bool.
     /*
     if ( $profile['compression'] == '1' ) {
     	$profile['compression'] = true;
     } else {
     	$profile['compression'] = false;
     }
     */
     if (pb_backupbuddy::$options['compression'] == '1') {
         $compression = true;
     } else {
         $compression = false;
     }
     $archiveURL = '';
     $abspath = str_replace('\\', '/', ABSPATH);
     // Change slashes to handle Windows as we store backup_directory with Linux-style slashes even on Windows.
     $backup_dir = str_replace('\\', '/', backupbuddy_core::getBackupDirectory());
     if (FALSE !== stristr($backup_dir, $abspath)) {
         // Make sure file to download is in a publicly accessible location (beneath WP web root technically).
         $sitepath = str_replace($abspath, '', $backup_dir);
         $archiveURL = rtrim(site_url(), '/\\') . '/' . trim($sitepath, '/\\') . '/' . basename($archiveFile);
     }
     $forceSingleDatabaseFile = false;
     if ('1' == pb_backupbuddy::$options['force_single_db_file']) {
         $forceSingleDatabaseFile = true;
     }
     // Set up the backup data.
     $this->_backup = array('data_version' => 1, 'backupbuddy_version' => pb_backupbuddy::settings('version'), 'serial' => $serial, 'init_complete' => false, 'backup_mode' => $profile['backup_mode'], 'type' => $type, 'profile' => $profile, 'default_profile' => pb_backupbuddy::$options['profiles'][0], 'start_time' => time(), 'finish_time' => 0, 'updated_time' => time(), 'status' => array(), 'max_execution_time' => backupbuddy_core::adjustedMaxExecutionTime(), 'archive_size' => 0, 'schedule_title' => $schedule_title, 'backup_directory' => backupbuddy_core::getBackupDirectory(), 'archive_file' => $archiveFile, 'archive_url' => $archiveURL, 'trigger' => $trigger, 'zip_method_strategy' => pb_backupbuddy::$options['zip_method_strategy'], 'compression' => $compression, 'ignore_zip_warnings' => pb_backupbuddy::$options['ignore_zip_warnings'], 'ignore_zip_symlinks' => pb_backupbuddy::$options['ignore_zip_symlinks'], 'steps' => array(), 'integrity' => array(), 'temp_directory' => '', 'backup_root' => '', 'export_plugins' => array(), 'additional_table_includes' => array(), 'additional_table_excludes' => array(), 'directory_exclusions' => backupbuddy_core::get_directory_exclusions($profile, false, $serial), 'table_sizes' => array(), 'breakout_tables' => array(), 'force_single_db_file' => $forceSingleDatabaseFile, 'deployment_log' => '', 'deployment_direction' => $deployDirection, 'deployment_destination' => $deployDestinationSettings, 'runnerUID' => get_current_user_id());
     pb_backupbuddy::status('startSubFunction', json_encode(array('function' => 'file_excludes', 'title' => 'Found ' . count($this->_backup['directory_exclusions']) . ' file or directory exclusions.')));
     // Warn if excluding key paths.
     $alertFileExcludes = backupbuddy_core::alert_core_file_excludes($this->_backup['directory_exclusions']);
     foreach ($alertFileExcludes as $alertFileExcludeId => $alertFileExclude) {
         pb_backupbuddy::status('warning', $alertFileExclude);
     }
     pb_backupbuddy::anti_directory_browsing(backupbuddy_core::getTempDirectory(), $die = false);
     // Figure out paths.
     if ($this->_backup['type'] == 'full' || $this->_backup['type'] == 'files') {
         $this->_backup['temp_directory'] = backupbuddy_core::getTempDirectory() . $serial . '/';
         $this->_backup['backup_root'] = ABSPATH;
         // ABSPATH contains trailing slash.
     } elseif ($this->_backup['type'] == 'db') {
         $this->_backup['temp_directory'] = backupbuddy_core::getTempDirectory() . $serial . '/';
         $this->_backup['backup_root'] = $this->_backup['temp_directory'];
     } elseif ($this->_backup['type'] == 'export') {
         // WordPress unzips into wordpress subdirectory by default so must include that in path.
         $this->_backup['temp_directory'] = backupbuddy_core::getTempDirectory() . $serial . '/wordpress/wp-content/uploads/backupbuddy_temp/' . $serial . '/';
         // We store temp data for export within the temporary WordPress installation within the temp directory. A bit confusing; sorry about that.
         $this->_backup['backup_root'] = backupbuddy_core::getTempDirectory() . $serial . '/wordpress/';
     } else {
         pb_backupbuddy::status('error', __('Backup FAILED. Unknown backup type.', 'it-l10n-backupbuddy'));
         pb_backupbuddy::status('haltScript', '');
         // Halt JS on page.
     }
     pb_backupbuddy::status('details', 'Temp directory: `' . $this->_backup['temp_directory'] . '`.');
     pb_backupbuddy::status('details', 'Backup root: `' . $this->_backup['backup_root'] . '`.');
     // Plugins to export (only for MS exports).
     if (count($export_plugins) > 0) {
         $this->_backup['export_plugins'] = $export_plugins;
     }
     // Calculate additional database table inclusion/exclusion.
     $additional_includes = explode("\n", $profile['mysqldump_additional_includes']);
     array_walk($additional_includes, create_function('&$val', '$val = trim($val);'));
     $this->_backup['additional_table_includes'] = array_unique($additional_includes);
     // removes duplicates.
     $additional_excludes = explode("\n", $profile['mysqldump_additional_excludes']);
     array_walk($additional_excludes, create_function('&$val', '$val = trim($val);'));
     $this->_backup['additional_table_excludes'] = array_unique($additional_excludes);
     // removes duplicates.
     unset($additional_includes);
     unset($additional_excludes);
     /********* Begin setting up steps array. *********/
     if ($type == 'export') {
         pb_backupbuddy::status('details', 'Setting up export-specific steps.');
         $this->_backup['steps'][] = array('function' => 'ms_download_extract_wordpress', 'args' => array(), 'start_time' => 0, 'finish_time' => 0, 'attempts' => 0);
         $this->_backup['steps'][] = array('function' => 'ms_create_wp_config', 'args' => array(), 'start_time' => 0, 'finish_time' => 0, 'attempts' => 0);
         $this->_backup['steps'][] = array('function' => 'ms_copy_plugins', 'args' => array(), 'start_time' => 0, 'finish_time' => 0, 'attempts' => 0);
         $this->_backup['steps'][] = array('function' => 'ms_copy_themes', 'args' => array(), 'start_time' => 0, 'finish_time' => 0, 'attempts' => 0);
         $this->_backup['steps'][] = array('function' => 'ms_copy_media', 'args' => array(), 'start_time' => 0, 'finish_time' => 0, 'attempts' => 0);
         $this->_backup['steps'][] = array('function' => 'ms_copy_users_table', 'args' => array(), 'start_time' => 0, 'finish_time' => 0, 'attempts' => 0);
     }
     if ('pull' != $deployDirection && '1' != $profile['skip_database_dump'] && $profile['type'] != 'files') {
         // Backup database if not skipping AND not a files only backup.
         global $wpdb;
         // Default tables to backup.
         if ($type == 'export') {
             // Multisite Subsite export only dumps tables specific to this subsite prefix.
             $base_dump_mode = 'prefix';
         } else {
             // Non-multisite export so use profile to determine tables to backup.
             if ($profile['backup_nonwp_tables'] == '1') {
                 // Backup all tables.
                 $base_dump_mode = 'all';
             } elseif ($profile['backup_nonwp_tables'] == '2') {
                 // Backup no tables by default. Relies on listed additional tables.
                 $base_dump_mode = 'none';
             } else {
                 // Only backup matching prefix.
                 $base_dump_mode = 'prefix';
             }
         }
         $additional_tables = $this->_backup['additional_table_includes'];
         if ($type == 'export') {
             global $wpdb;
             array_push($additional_tables, $wpdb->prefix . "users");
             array_push($additional_tables, $wpdb->prefix . "usermeta");
         }
         // Warn if excluding key WP tables.
         $tableExcludes = backupbuddy_core::alert_core_table_excludes($this->_backup['additional_table_excludes']);
         foreach ($tableExcludes as $tableExcludeId => $tableExclude) {
             pb_backupbuddy::status('warning', $tableExclude);
         }
         // Calculate tables to dump based on the provided information. $tables will be an array of tables.
         $tables = $this->_calculate_tables($base_dump_mode, $additional_tables, $this->_backup['additional_table_excludes']);
         pb_backupbuddy::status('startSubFunction', json_encode(array('function' => 'calculate_tables', 'title' => 'Found ' . count($tables) . ' tables to backup based on settings.', 'more' => 'Tables: ' . implode(', ', $tables))));
         // If calculations show NO database tables should be backed up then change mode to skip database dump.
         if (0 == count($tables)) {
             pb_backupbuddy::status('warning', 'WARNING #857272: No database tables will be backed up based on current settings. This will not be a complete backup. Adjust settings if this is not intended and use with caution. Skipping database dump step.');
             $profile['skip_database_dump'] = '1';
             $this->_backup['profile']['skip_database_dump'] = '1';
         } else {
             // One or more tables set to backup.
             // Obtain tables sizes. Surround each table name by a single quote and implode with commas for SQL query to get sizes.
             $tables_formatted = $tables;
             foreach ($tables_formatted as &$table_formatted) {
                 $table_formatted = "'{$table_formatted}'";
             }
             $tables_formatted = implode(',', $tables_formatted);
             $sql = "SHOW TABLE STATUS WHERE Name IN({$tables_formatted});";
             $rows = $wpdb->get_results($sql, ARRAY_A);
             if (false === $rows) {
                 pb_backupbuddy::alert('Error #85473474: Unable to retrieve table status. Query: `' . $sql . '`.', true);
                 return false;
             }
             $totalDatabaseSize = 0;
             foreach ($rows as $row) {
                 $this->_backup['table_sizes'][$row['Name']] = $row['Data_length'] + $row['Index_length'];
                 $totalDatabaseSize += $this->_backup['table_sizes'][$row['Name']];
             }
             unset($rows);
             unset($tables_formatted);
             $databaseSize = pb_backupbuddy::$format->file_size($totalDatabaseSize);
             pb_backupbuddy::status('details', 'Total calculated database size: `' . $databaseSize . '`.');
             // Step through tables we want to break out and figure out which ones were indeed set to be backed up and break them out.
             if (pb_backupbuddy::$options['breakout_tables'] == '0') {
                 // Breaking out DISABLED.
                 pb_backupbuddy::status('details', 'Breaking out tables DISABLED based on settings.');
             } else {
                 // Breaking out ENABLED.
                 // Tables we will try to break out into standalone steps if possible.
                 $breakout_tables_defaults = array($wpdb->prefix . 'posts', $wpdb->prefix . 'postmeta');
                 pb_backupbuddy::status('details', 'Breaking out tables ENABLED based on settings. Tables to be broken out into individual steps: `' . implode(', ', $breakout_tables_defaults) . '`.');
                 foreach ((array) $breakout_tables_defaults as $breakout_tables_default) {
                     if (in_array($breakout_tables_default, $tables)) {
                         $this->_backup['breakout_tables'][] = $breakout_tables_default;
                         $tables = array_diff($tables, array($breakout_tables_default));
                         // Remove from main table backup list.
                     }
                 }
                 unset($breakout_tables_defaults);
                 // No longer needed.
             }
             $this->_backup['steps'][] = array('function' => 'backup_create_database_dump', 'args' => array($tables), 'start_time' => 0, 'finish_time' => 0, 'attempts' => 0);
             // Set up backup steps for additional broken out tables.
             foreach ((array) $this->_backup['breakout_tables'] as $breakout_table) {
                 $this->_backup['steps'][] = array('function' => 'backup_create_database_dump', 'args' => array(array($breakout_table)), 'start_time' => 0, 'finish_time' => 0, 'attempts' => 0);
             }
         }
         // end there being tables to backup.
     } else {
         pb_backupbuddy::status('message', __('Skipping database dump based on settings / profile type.', 'it-l10n-backupbuddy') . ' Backup type: `' . $type . '`.');
     }
     if ('pull' != $deployDirection) {
         $this->_backup['steps'][] = array('function' => 'backup_zip_files', 'args' => array(), 'start_time' => 0, 'finish_time' => 0, 'attempts' => 0);
         if ($type == 'export') {
             $this->_backup['steps'][] = array('function' => 'ms_cleanup', 'args' => array(), 'start_time' => 0, 'finish_time' => 0, 'attempts' => 0);
         }
         if ($profile['integrity_check'] == '1') {
             pb_backupbuddy::status('details', __('Integrity check will be performed based on settings for this profile.', 'it-l10n-backupbuddy'));
             $this->_backup['steps'][] = array('function' => 'integrity_check', 'args' => array(), 'start_time' => 0, 'finish_time' => 0, 'attempts' => 0);
         } else {
             pb_backupbuddy::status('details', __('Skipping integrity check step based on settings for this profile.', 'it-l10n-backupbuddy'));
         }
     }
     $this->_backup['steps'][] = array('function' => 'post_backup', 'args' => array(), 'start_time' => 0, 'finish_time' => 0, 'attempts' => 0);
     // Prepend and append pre backup and post backup steps.
     $this->_backup['steps'] = array_merge($pre_backup, $this->_backup['steps'], $post_backup);
     /********* End setting up steps array. *********/
     // Save what we have so far so that any errors below will end up displayed to user.
     $this->_backup_options->save();
     /********* Begin directory creation and security. *********/
     pb_backupbuddy::anti_directory_browsing(backupbuddy_core::getBackupDirectory());
     // Prepare temporary directory for holding SQL and data file.
     if (backupbuddy_core::getTempDirectory() == '') {
         pb_backupbuddy::status('error', 'Error #54534344. Temp directory blank. Please deactivate then reactivate plugin to reset.');
         return false;
     }
     if (!file_exists($this->_backup['temp_directory'])) {
         if (pb_backupbuddy::$filesystem->mkdir($this->_backup['temp_directory']) === false) {
             pb_backupbuddy::status('error', 'Error #9002b. Unable to create temporary storage directory (' . $this->_backup['temp_directory'] . ')');
             return false;
         }
     }
     if (!is_writable($this->_backup['temp_directory'])) {
         pb_backupbuddy::status('error', 'Error #9015. Temp data directory is not writable. Check your permissions. (' . $this->_backup['temp_directory'] . ')');
         return false;
     }
     pb_backupbuddy::anti_directory_browsing(ABSPATH . 'wp-content/uploads/backupbuddy_temp/');
     // Prepare temporary directory for holding ZIP file while it is being generated.
     $this->_backup['temporary_zip_directory'] = backupbuddy_core::getBackupDirectory() . 'temp_zip_' . $this->_backup['serial'] . '/';
     if (!file_exists($this->_backup['temporary_zip_directory'])) {
         if (pb_backupbuddy::$filesystem->mkdir($this->_backup['temporary_zip_directory']) === false) {
             pb_backupbuddy::status('details', 'Error #9002c. Unable to create temporary ZIP storage directory (' . $this->_backup['temporary_zip_directory'] . ')');
             return false;
         }
     }
     if (!is_writable($this->_backup['temporary_zip_directory'])) {
         pb_backupbuddy::status('error', 'Error #9015. Temp data directory is not writable. Check your permissions. (' . $this->_backup['temporary_zip_directory'] . ')');
         return false;
     }
     /********* End directory creation and security *********/
     // Generate backup DAT (data) file containing details about the backup.
     if ($this->backup_create_dat_file($trigger) !== true) {
         pb_backupbuddy::status('details', __('Problem creating DAT file.', 'it-l10n-backupbuddy'));
         return false;
     }
     // Generating ImportBuddy file to include in the backup for FULL BACKUPS ONLY currently. Cannot put in DB because it would be in root and be excluded or conflict on extraction.
     if ($type == 'full') {
         if (pb_backupbuddy::$options['include_importbuddy'] == '1') {
             pb_backupbuddy::status('details', 'Generating ImportBuddy tool to include in backup archive: `' . $this->_backup['temp_directory'] . 'importbuddy.php`.');
             pb_backupbuddy::status('startAction', 'importbuddyCreation');
             backupbuddy_core::importbuddy($this->_backup['temp_directory'] . 'importbuddy.php');
             pb_backupbuddy::status('finishAction', 'importbuddyCreation');
             pb_backupbuddy::status('details', 'ImportBuddy generation complete.');
         } else {
             // dont include importbuddy.
             pb_backupbuddy::status('details', 'ImportBuddy tool inclusion in ZIP backup archive skipped based on settings or backup type.');
         }
     }
     // Save all of this.
     $this->_backup['init_complete'] = true;
     // pre_backup() completed.
     $this->_backup_options->save();
     pb_backupbuddy::status('details', __('Finished pre-backup procedures.', 'it-l10n-backupbuddy'));
     pb_backupbuddy::status('milestone', 'finish_settings');
     pb_backupbuddy::status('finishFunction', json_encode(array('function' => 'pre_backup')));
     return true;
 }
Esempio n. 3
0
 public static function validateSchedules()
 {
     foreach (pb_backupbuddy::$options['schedules'] as $schedule_id => $schedule) {
         // Retrieve current interval WordPress cron thinks the schedule is at.
         $cron_inverval = wp_get_schedule('pb_backupbuddy-cron_scheduled_backup', array((int) $schedule_id));
         $intervals = wp_get_schedules();
         if (FALSE === $cron_inverval) {
             // Schedule MISSING. Re-schedule.
             $result = backupbuddy_core::schedule_event($schedule['first_run'], $schedule['interval'], 'pb_backupbuddy-cron_scheduled_backup', array((int) $schedule_id));
             // Add new schedule.
             if ($result === FALSE) {
                 $message = 'Error #83443784: A missing schedule was identified but unable to be re-created. Your schedule may not work properly & need manual attention.';
                 pb_backupbuddy::alert($message, true);
             } else {
                 pb_backupbuddy::alert('Warning #2389373: A missing schedule was identified and re-created. This should have corrected any problem with this schedule.', true);
             }
             continue;
         }
         if ($cron_inverval != $schedule['interval']) {
             // Schedule exists BUT interval is WRONG. Fix it.
             $cron_run = wp_next_scheduled('pb_backupbuddy-cron_scheduled_backup', array((int) $schedule_id));
             $result = backupbuddy_core::unschedule_event($cron_run, 'pb_backupbuddy-cron_scheduled_backup', array((int) $schedule_id));
             // Delete existing schedule.
             if ($result === FALSE) {
                 $message = 'Error removing invalid event from WordPress. Your schedule may not work properly. Please try again. Error #38279343. Check your BackupBuddy error log for details.';
                 pb_backupbuddy::alert($message, true);
                 continue;
             }
             // Determine when the next run time SHOULD be.
             if (0 == $schedule['last_run']) {
                 $next_run = $schedule['first_run'];
             } else {
                 $next_run = (int) $schedule['last_run'] + (int) $intervals[$schedule['interval']]['interval'];
             }
             $result = backupbuddy_core::schedule_event($next_run, $schedule['interval'], 'pb_backupbuddy-cron_scheduled_backup', array((int) $schedule_id));
             // Add new schedule.
             if ($result === FALSE) {
                 $message = 'Error #237836464: An invalid schedule with the incorrect interval was identified & deleted but unable to be re-created. Your schedule may not work properly & need manual attention.';
                 pb_backupbuddy::alert($message, true);
                 continue;
             } else {
                 pb_backupbuddy::alert('Warning #2423484: An invalid schedule with the incorrect interval was identified and updated. This should have corrected any problem with this schedule.', true);
             }
         }
     }
     // end foreach.
     //wp_get_schedule($hook, $args = array())
 }
Esempio n. 4
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;
}
Esempio n. 5
0
    } else {
        // EDIT SCHEDULE. Form handles saving; just need to update timestamp.
        $first_run = pb_backupbuddy::$format->unlocalize_time(strtotime($submitted_schedule['data']['first_run']));
        if ($first_run == 0 || $first_run == 18000) {
            pb_backupbuddy::alert(sprintf(__('Invalid time format. Please use the specified format / example %s', 'it-l10n-backupbuddy'), $date_format_example));
            $error = true;
        }
        pb_backupbuddy::$options['schedules'][pb_backupbuddy::_GET('edit')]['first_run'] = $first_run;
        //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']) . '`.');
    }
} elseif (count($submitted_schedule['errors']) > 0) {
    foreach ($submitted_schedule['errors'] as $error) {
        pb_backupbuddy::alert($error);
    }
}
$data['schedule_form'] = $schedule_form;
$schedules = array();
foreach (pb_backupbuddy::$options['schedules'] as $schedule_id => $schedule) {
Esempio n. 6
0
 public static function verifyHousekeeping()
 {
     if (false === wp_next_scheduled('backupbuddy_cron', array('housekeeping', array()))) {
         // if schedule does not exist...
         backupbuddy_core::schedule_event(time() + 60 * 60 * 2, 'daily', 'housekeeping', array());
         // Add schedule.
     }
 }
Esempio n. 7
0
 public static function add_backup_schedule($title, $profile, $interval, $first_run, $remote_destinations = array(), $delete_after = false, $enabled = true)
 {
     $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();
         return true;
     }
 }
Esempio n. 8
0
 public static function remove_wp_schedules_with_no_bb_schedule()
 {
     $cron = get_option('cron');
     foreach ((array) $cron as $time => $cron_item) {
         // Times
         if (is_numeric($time)) {
             // Loop through each schedule for this time
             foreach ((array) $cron_item as $hook_name => $event) {
                 // Methods
                 foreach ((array) $event as $item_name => $item) {
                     // Full args for method
                     if ('backupbuddy_cron' == $hook_name && 'run_scheduled_backup' == $item['args'][0]) {
                         // scheduled backup
                         if (!empty($item['args'])) {
                             if (!isset(pb_backupbuddy::$options['schedules'][$item['args'][1][0]])) {
                                 // BB schedule does not exist so delete this cron item.
                                 if (FALSE === backupbuddy_core::unschedule_event($time, $hook_name, $item['args'])) {
                                     // Delete the scheduled cron.
                                     pb_backupbuddy::status('error', 'Error #5657667675b. Unable to delete CRON job. Please see your BackupBuddy error log for details.');
                                 } else {
                                     pb_backupbuddy::status('warning', 'Removed stale cron scheduled backup.');
                                 }
                             }
                         } else {
                             // No args, something wrong so delete it.
                             if (FALSE === backupbuddy_core::unschedule_event($time, $hook_name, $item['args'])) {
                                 // Delete the scheduled cron.
                                 pb_backupbuddy::status('error', 'Error #5657667675c. Unable to delete CRON job. Please see your BackupBuddy error log for details.');
                             } else {
                                 pb_backupbuddy::status('warning', 'Removed stale cron scheduled backup which had no arguments.');
                             }
                         }
                     } elseif ('pb_backupbuddy-cron_scheduled_backup' == $hook_name) {
                         // Upgrade hook name to 'backupbuddy_cron'.
                         if (FALSE === wp_unschedule_event($time, $hook_name, $item['args'])) {
                             // Delete the scheduled cron.
                             pb_backupbuddy::status('error', 'Error #327237. Unable to delete CRON job for migration to new tag. Please see your BackupBuddy error log for details.');
                         } else {
                             pb_backupbuddy::status('details', 'Removed cron with old tag format.');
                         }
                         if (isset(pb_backupbuddy::$options['schedules'][$item['args'][0]])) {
                             // BB schedule exists so recreate.
                             $result = backupbuddy_core::schedule_event($time, pb_backupbuddy::$options['schedules'][$item['args'][0]]['interval'], 'run_scheduled_backup', $item['args']);
                             if ($result === false) {
                                 pb_backupbuddy::status('error', 'Error #8923832: Unable to reschedule with new cron tag.');
                             } else {
                                 pb_backupbuddy::status('details', 'Replaced cron with old tag format with new format.');
                             }
                         } else {
                             pb_backupbuddy::status('warning', 'Stale schedule found with WordPress without corresponding BackupBuddy schedule. Not keeping when migrating to new cron tag.');
                         }
                     } elseif ('pb_backupbuddy_cron' == $hook_name) {
                         // Remove.
                         wp_unschedule_event($time, $hook_name, $item['args']);
                     } elseif ('pb_backupbuddy_corn' == $hook_name) {
                         // Remove.
                         wp_unschedule_event($time, $hook_name, $item['args']);
                     } elseif ('pb_backupbuddy_housekeeping' == $hook_name) {
                         // Remove.
                         wp_unschedule_event($time, $hook_name, $item['args']);
                     }
                 }
                 // End foreach.
                 unset($item);
                 unset($item_name);
             }
             // End foreach.
             unset($event);
             unset($hook_name);
         }
         // End if is_numeric.
     }
     // End foreach.
     unset($cron_item);
     unset($time);
 }