Пример #1
0
 public static function run_periodic($backup_age_limit = 172800, $die_on_fail = true)
 {
     if (is_multisite()) {
         // For Multisite only run on main Network site.
         if (!is_main_site()) {
             return;
         }
     }
     pb_backupbuddy::status('message', 'Starting periodic housekeeeping procedure for BackupBuddy v' . pb_backupbuddy::settings('version') . '.');
     require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
     require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
     if (!isset(pb_backupbuddy::$options)) {
         pb_backupbuddy::load();
     }
     // Top priority. Security related or otherwise crucial to run first.
     self::no_recent_backup_reminder();
     backupbuddy_core::verify_directories($skipTempGeneration = true);
     // Verify directory existance and anti-directory browsing is in place everywhere.
     self::check_high_security_mode($die_on_fail);
     self::remove_importbuddy_file();
     self::remove_importbuddy_dir();
     self::remove_rollback_files();
     // Potential large file/dir cleanup. May bog down site.
     self::cleanup_temp_dir($backup_age_limit);
     self::remove_temp_zip_dirs($backup_age_limit);
     // Robustness -- handle re-processing timeouts, verifying schedules, etc.
     self::process_timed_out_backups();
     self::process_timed_out_sends();
     self::validate_bb_schedules_in_wp();
     // More minor cleanup.
     self::remove_temp_tables();
     self::remove_wp_schedules_with_no_bb_schedule();
     self::trim_old_notifications();
     self::trim_remote_send_stats();
     self::s3_cancel_multipart_pieces();
     self::s32_cancel_multipart_pieces();
     self::cleanup_local_destination_temp();
     self::purge_logs();
     self::purge_large_logs();
     self::clear_cron_send();
     // PHP tests.
     self::schedule_php_runtime_tests();
     self::schedule_php_memory_tests();
     @clearstatcache();
     // Clears file info stat cache.
     pb_backupbuddy::status('message', 'Finished periodic housekeeping cleanup procedure.');
 }
Пример #2
0
    if ($multisite_option) {
        $options = $multisite_option;
    }
    unset($multisite_option);
}
if ($options !== false) {
    // If options is not false then we need to upgrade.
    pb_backupbuddy::status('details', 'Migrating data structure. 2.x data discovered.');
    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'));
Пример #3
0
foreach (pb_backupbuddy::$options['remote_destinations'] as $destination_id => $destination) {
    if ($destination['type'] == 'local' && (isset($destination['temporary']) && $destination['temporary'] === true)) {
        // If local and temporary.
        if (time() - $destination['created'] > $backup_age_limit) {
            // Older than 12 hours; clear out!
            pb_backupbuddy::status('details', 'Cleaned up stale local destination `' . $destination_id . '`.');
            unset(pb_backupbuddy::$options['remote_destinations'][$destination_id]);
            pb_backupbuddy::save();
        }
    }
}
// Cleanup excess remote sending stats.
pb_backupbuddy::status('details', 'Cleaning up remote send stats.');
backupbuddy_core::trim_remote_send_stats();
// Verify directory existance and anti-directory browsing is in place everywhere.
backupbuddy_core::verify_directories($skipTempGeneration = true);
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
// Mark any backups noted as in progress to timed out if taking too long. Send error email is scheduled and failed or timed out.
// Also, Purge fileoptions files without matching backup file in existance that are older than 30 days.
pb_backupbuddy::status('details', 'Cleaning up old backup fileoptions option files.');
$fileoptions_directory = backupbuddy_core::getLogDirectory() . 'fileoptions/';
$files = glob($fileoptions_directory . '*.txt');
if (!is_array($files)) {
    $files = array();
}
foreach ($files as $file) {
    pb_backupbuddy::status('details', 'Fileoptions instance #43.');
    $backup_options = new pb_backupbuddy_fileoptions($file, $read_only = false);
    if (true !== ($result = $backup_options->is_ok())) {
        pb_backupbuddy::status('error', 'Error retrieving fileoptions file `' . $file . '`. Err 335353266.');
    } else {
Пример #4
0
 function process_scheduled_backup($cron_id)
 {
     if (!class_exists('backupbuddy_core')) {
         require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
     }
     if (!isset(pb_backupbuddy::$options)) {
         $this->load();
     }
     // Verify directories.
     backupbuddy_core::verify_directories($skipTempGeneration = true);
     pb_backupbuddy::status('details', 'cron_process_scheduled_backup: ' . $cron_id);
     $preflight_message = '';
     $preflight_checks = backupbuddy_core::preflight_check();
     foreach ($preflight_checks as $preflight_check) {
         if ($preflight_check['success'] !== true) {
             pb_backupbuddy::status('warning', $preflight_check['message']);
         }
     }
     if (isset(pb_backupbuddy::$options['schedules'][$cron_id]) && is_array(pb_backupbuddy::$options['schedules'][$cron_id])) {
         // If schedule is disabled then just return. Bail out!
         if (isset(pb_backupbuddy::$options['schedules'][$cron_id]['on_off']) && pb_backupbuddy::$options['schedules'][$cron_id]['on_off'] == '0') {
             pb_backupbuddy::status('message', 'Schedule `' . $cron_id . '` NOT run due to being disabled based on this schedule\'s settings.');
             return;
         }
         pb_backupbuddy::$options['schedules'][$cron_id]['last_run'] = time();
         // update last run time.
         pb_backupbuddy::save();
         if (!isset(pb_backupbuddy::$classes['backup'])) {
             require_once pb_backupbuddy::plugin_path() . '/classes/backup.php';
             pb_backupbuddy::$classes['backup'] = new pb_backupbuddy_backup();
         }
         if (pb_backupbuddy::$options['schedules'][$cron_id]['delete_after'] == '1') {
             $delete_after = true;
             pb_backupbuddy::status('details', 'Option to delete file after successful transfer enabled.');
         } else {
             $delete_after = false;
             pb_backupbuddy::status('details', 'Option to delete file after successful transfer disabled.');
         }
         // If any remote destinations are set then add these to the steps to perform after the backup.
         $post_backup_steps = array();
         $destinations = explode('|', pb_backupbuddy::$options['schedules'][$cron_id]['remote_destinations']);
         $found_valid_destination = false;
         // Remove any invalid destinations from this run.
         foreach ($destinations as $destination_index => $destination) {
             if (!isset($destination) || $destination == '') {
                 // Remove.
                 unset($destinations[$destination_index]);
             }
             if (!isset(pb_backupbuddy::$options['remote_destinations'][$destination])) {
                 // Destination ID is invalid; remove.
                 unset($destinations[$destination_index]);
             }
         }
         $destination_count = count($destinations);
         $i = 0;
         foreach ($destinations as $destination) {
             $i++;
             if ($i >= $destination_count) {
                 // Last destination. Delete after if enabled.
                 $this_delete_after = $delete_after;
                 pb_backupbuddy::status('details', 'Last destination set to send to so this file deletion will be determined by settings.');
             } else {
                 // More destinations to send to. Only delete after final send.
                 $this_delete_after = false;
                 pb_backupbuddy::status('details', 'More destinations are set to send to so this file will not be deleted after send.');
             }
             $args = array($destination, $this_delete_after);
             pb_backupbuddy::status('details', 'Adding send step with args `' . implode(',', $args) . '`.');
             array_push($post_backup_steps, array('function' => 'send_remote_destination', 'args' => $args, 'start_time' => 0, 'finish_time' => 0, 'attempts' => 0));
             $found_valid_destination = true;
             pb_backupbuddy::status('details', 'Found valid destination.');
         }
         $profile_array = pb_backupbuddy::$options['profiles'][pb_backupbuddy::$options['schedules'][$cron_id]['profile']];
         if (pb_backupbuddy::$classes['backup']->start_backup_process($profile_array, 'scheduled', array(), $post_backup_steps, pb_backupbuddy::$options['schedules'][$cron_id]['title']) !== true) {
             pb_backupbuddy::status('error', 'Error #4564658344443: Backup failure. See earlier logging details for more information.');
         }
     }
     pb_backupbuddy::status('details', 'Finished cron_process_scheduled_backup.');
 }
Пример #5
0
 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;
 }
Пример #6
0
 function admin_notices()
 {
     backupbuddy_core::verify_directories($skipTempGeneration = true);
 }