*
 * Display site site listing on Server Info page.
 *
 */
$profile_id = 0;
if (is_numeric(pb_backupbuddy::_GET('profile'))) {
    if (isset(pb_backupbuddy::$options['profiles'][pb_backupbuddy::_GET('profile')])) {
        $profile_id = pb_backupbuddy::_GET('profile');
        pb_backupbuddy::$options['profiles'][pb_backupbuddy::_GET('profile')] = array_merge(pb_backupbuddy::settings('profile_defaults'), pb_backupbuddy::$options['profiles'][pb_backupbuddy::_GET('profile')]);
        // Set defaults if not set.
    } else {
        pb_backupbuddy::alert('Error #45849458b: Invalid profile ID number `' . htmlentities(pb_backupbuddy::_GET('profile')) . '`. Displaying with default profile.', true);
    }
}
echo '<!-- profile: ' . $profile_id . ' -->';
$exclusions = backupbuddy_core::get_directory_exclusions(pb_backupbuddy::$options['profiles'][$profile_id]);
$result = pb_backupbuddy::$filesystem->dir_size_map(ABSPATH, ABSPATH, $exclusions, $dir_array);
if (0 == $result) {
    pb_backupbuddy::alert('Error #5656653. Unable to access directory map listing for directory `' . ABSPATH . '`.');
    die;
}
$total_size = pb_backupbuddy::$options['stats']['site_size'] = $result[0];
$total_size_excluded = pb_backupbuddy::$options['stats']['site_size_excluded'] = $result[1];
pb_backupbuddy::$options['stats']['site_size_updated'] = time();
pb_backupbuddy::save();
arsort($dir_array);
if (pb_backupbuddy::_GET('text') == 'true') {
    pb_backupbuddy::$ui->ajax_header();
    echo '<h3>' . __('Site Size Listing & Exclusions', 'it-l10n-backupbuddy') . '</h3>';
    echo '<textarea style="width:100%; height: 300px; font-family: monospace;" wrap="off">';
    echo __('Size + Children', 'it-l10n-backupbuddy') . "\t";
Пример #2
0
 public static function get_site_size()
 {
     $exclusions = backupbuddy_core::get_directory_exclusions(pb_backupbuddy::$options['profiles'][0]);
     $dir_array = array();
     $result = pb_backupbuddy::$filesystem->dir_size_map(ABSPATH, ABSPATH, $exclusions, $dir_array);
     unset($dir_array);
     // Free this large chunk of memory.
     $total_size = pb_backupbuddy::$options['stats']['site_size'] = $result[0];
     $total_size_excluded = pb_backupbuddy::$options['stats']['site_size_excluded'] = $result[1];
     $total_objects = pb_backupbuddy::$options['stats']['site_objects'] = $result[2];
     $total_objects_excluded = pb_backupbuddy::$options['stats']['site_objects_excluded'] = $result[3];
     pb_backupbuddy::$options['stats']['site_size_updated'] = time();
     pb_backupbuddy::save();
     return array($total_size, $total_size_excluded, $total_objects, $total_objects_excluded);
 }
Пример #3
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;
 }
Пример #4
0
    public function site_size_listing()
    {
        $profile_id = 0;
        if (is_numeric(pb_backupbuddy::_GET('profile'))) {
            if (isset(pb_backupbuddy::$options['profiles'][pb_backupbuddy::_GET('profile')])) {
                $profile_id = pb_backupbuddy::_GET('profile');
                pb_backupbuddy::$options['profiles'][pb_backupbuddy::_GET('profile')] = array_merge(pb_backupbuddy::settings('profile_defaults'), pb_backupbuddy::$options['profiles'][pb_backupbuddy::_GET('profile')]);
                // Set defaults if not set.
            } else {
                pb_backupbuddy::alert('Error #45849458b: Invalid profile ID number `' . htmlentities(pb_backupbuddy::_GET('profile')) . '`. Displaying with default profile.', true);
            }
        }
        echo '<!-- profile: ' . $profile_id . ' -->';
        $exclusions = backupbuddy_core::get_directory_exclusions(pb_backupbuddy::$options['profiles'][$profile_id]);
        $result = pb_backupbuddy::$filesystem->dir_size_map(ABSPATH, ABSPATH, $exclusions, $dir_array);
        if (0 == $result) {
            pb_backupbuddy::alert('Error #5656653. Unable to access directory map listing for directory `' . ABSPATH . '`.');
            die;
        }
        $total_size = pb_backupbuddy::$options['stats']['site_size'] = $result[0];
        $total_size_excluded = pb_backupbuddy::$options['stats']['site_size_excluded'] = $result[1];
        pb_backupbuddy::$options['stats']['site_size_updated'] = time();
        pb_backupbuddy::save();
        arsort($dir_array);
        if (pb_backupbuddy::_GET('text') == 'true') {
            pb_backupbuddy::$ui->ajax_header();
            echo '<h3>' . __('Site Size Listing & Exclusions', 'it-l10n-backupbuddy') . '</h3>';
            echo '<textarea style="width:100%; height: 300px; font-family: monospace;" wrap="off">';
            echo __('Size + Children', 'it-l10n-backupbuddy') . "\t";
            echo __('- Exclusions', 'it-l10n-backupbuddy') . "\t";
            echo __('Directory', 'it-l10n-backupbuddy') . "\n";
        } else {
            ?>
			<style>
				.backupbuddy_sizemap_table th {
					white-space: nowrap;
				}
				.backupbuddy_sizemap_table td {
					word-break: break-all;
				}
			</style>
			<table class="widefat backupbuddy_sizemap_table">
				<thead>
					<tr class="thead">
						<?php 
            echo '<th>', __('Directory', 'it-l10n-backupbuddy'), '</th>', '<th>', __('Size with Children', 'it-l10n-backupbuddy'), '</th>', '<th>', __('Size with Exclusions', 'it-l10n-backupbuddy'), '<br><span class="description">Global defaults profile</span></th>';
            ?>
					</tr>
				</thead>
				<tfoot>
					<tr class="thead">
						<?php 
            echo '<th>', __('Directory', 'it-l10n-backupbuddy'), '</th>', '<th>', __('Size with Children', 'it-l10n-backupbuddy'), '</th>', '<th>', __('Size with Exclusions', 'it-l10n-backupbuddy'), '<br><span class="description">Global defaults profile</span></th>';
            ?>
					</tr>
				</tfoot>
				<tbody>
			<?php 
        }
        if (pb_backupbuddy::_GET('text') == 'true') {
            echo str_pad(pb_backupbuddy::$format->file_size($total_size), 10, ' ', STR_PAD_RIGHT) . "\t" . str_pad(pb_backupbuddy::$format->file_size($total_size_excluded), 10, ' ', STR_PAD_RIGHT) . "\t" . __('TOTALS', 'it-l10n-backupbuddy') . "\n";
        } else {
            echo '<tr><td align="right"><b>' . __('TOTALS', 'it-l10n-backupbuddy') . ':</b></td><td><b>' . pb_backupbuddy::$format->file_size($total_size) . '</b></td><td><b>' . pb_backupbuddy::$format->file_size($total_size_excluded) . '</b></td></tr>';
        }
        $item_count = 0;
        foreach ($dir_array as $id => $item) {
            // Each $item is in format array( TOTAL_SIZE, TOTAL_SIZE_TAKING_EXCLUSIONS_INTO_ACCOUNT );
            $item_count++;
            if ($item_count > 100) {
                flush();
                $item_count = 0;
            }
            if ($item[1] === false) {
                if (pb_backupbuddy::_GET('text') == 'true') {
                    $excluded_size = 'EXCLUDED';
                    echo '**';
                } else {
                    $excluded_size = '<span class="pb_label pb_label-important">Excluded</span>';
                    echo '<tr style="background: #fcc9c9;">';
                }
            } else {
                $excluded_size = pb_backupbuddy::$format->file_size($item[1]);
                if (pb_backupbuddy::_GET('text') != 'true') {
                    echo '<tr>';
                }
            }
            if (pb_backupbuddy::_GET('text') == 'true') {
                echo str_pad(pb_backupbuddy::$format->file_size($item[0]), 10, ' ', STR_PAD_RIGHT) . "\t" . str_pad($excluded_size, 10, ' ', STR_PAD_RIGHT) . "\t" . $id . "\n";
            } else {
                echo '<td>' . $id . '</td><td>' . pb_backupbuddy::$format->file_size($item[0]) . '</td><td>' . $excluded_size . '</td></tr>';
            }
        }
        if (pb_backupbuddy::_GET('text') == 'true') {
            echo str_pad(pb_backupbuddy::$format->file_size($total_size), 10, ' ', STR_PAD_RIGHT) . "\t" . str_pad(pb_backupbuddy::$format->file_size($total_size_excluded), 10, ' ', STR_PAD_RIGHT) . "\t" . __('TOTALS', 'it-l10n-backupbuddy') . "\n";
        } else {
            echo '<tr><td align="right"><b>' . __('TOTALS', 'it-l10n-backupbuddy') . ':</b></td><td><b>' . pb_backupbuddy::$format->file_size($total_size) . '</b></td><td><b>' . pb_backupbuddy::$format->file_size($total_size_excluded) . '</b></td></tr>';
        }
        if (pb_backupbuddy::_GET('text') == 'true') {
            echo "\n\nEXCLUSIONS (" . count($exclusions) . "):" . "\n" . implode("\n", $exclusions);
            echo '</textarea>';
            pb_backupbuddy::$ui->ajax_footer();
        } else {
            echo '</tbody>';
            echo '</table>';
            echo '<br>';
            echo 'Exclusions (' . count($exclusions) . ')';
            pb_backupbuddy::tip('List of directories that will be excluded in an actual backup. This includes user-defined directories and BackupBuddy directories such as the archive directory and temporary directories.');
            echo '<div id="pb_backupbuddy_serverinfo_exclusions" style="background-color: #EEEEEE; padding: 4px; float: right; white-space: nowrap; height: 90px; width: 70%; min-width: 400px; overflow: auto;"><i>' . implode("<br>", $exclusions) . '</i></div>';
            echo '<br style="clear: both;">';
            echo '<br><br><center>';
            echo '<a href="' . pb_backupbuddy::ajax_url('site_size_listing') . '&text=true&#038;TB_iframe=1&#038;width=640&#038;height=600" class="thickbox button secondary-button">' . __('Display Directory Size Listing in Text Format', 'it-l10n-backupbuddy') . '</a>';
            echo '</center>';
        }
        die;
    }
Пример #5
0
 private static function _step_update_files_list($custom_root = '', $startAt = 0, $items = array())
 {
     $start_time = microtime(true);
     pb_backupbuddy::status('details', 'Starting to process files; updating files list.');
     if (false === self::_load_catalog()) {
         return false;
     }
     if ('' != $custom_root) {
         pb_backupbuddy::status('details', 'Scanning custom directory: `' . $custom_root . '`.');
         sleep(3);
         // Give WordPress time to make thumbnails, etc.
     }
     if (0 == $startAt && '' == $custom_root) {
         // Reset stats when starting from the beginning of a full file scan (not for custom roots).
         self::$_state['stats']['files_pending_delete'] = 0;
         self::$_state['stats']['files_pending_send'] = 0;
         self::$_state['stats']['files_total_count'] = 0;
         self::$_state['stats']['files_total_size'] = 0;
     }
     // Get Live-specific excludes.
     $excludes = backupbuddy_live::getOption('file_excludes', true);
     // Add standard BB excludes we always apply.
     $excludes = array_unique(array_merge(self::$_default_excludes, backupbuddy_core::get_directory_exclusions(pb_backupbuddy::$options['profiles'][0], $trim_suffix = false, $serial = ''), backupbuddy_core::get_directory_exclusions(array('excludes' => $excludes), $trim_suffix = false, $serial = '')));
     pb_backupbuddy::status('details', 'Excluding directories: `' . implode(', ', $excludes) . '`.');
     // Generate list of files.
     if ('' != $custom_root) {
         $root = $custom_root;
     } else {
         $root = ABSPATH;
     }
     $root = rtrim($root, '/\\');
     // Make sure no trailing slash.
     $root_len = strlen($root);
     $custom_root_diff = '';
     if ('' != $custom_root) {
         $custom_root_diff = substr($root, strlen(ABSPATH) - 1);
     }
     $destination_settings = self::get_destination_settings();
     pb_backupbuddy::status('details', 'Starting deep file scan.');
     $max_time = $destination_settings['max_time'] - self::TIME_WIGGLE_ROOM;
     $files = pb_backupbuddy::$filesystem->deepscandir($root, $excludes, $startAt, $items, $start_time, $max_time - 8);
     // Additional 5 seconds so that we can add files into catalog after this completes.
     if (!is_array($files)) {
         backupbuddy_core::addNotification('live_error', 'BackupBuddy Stash Live Error', $files);
         pb_backupbuddy::status('error', 'Error #84393434: Halting Stash Live due to error returned by deepscandir: `' . $files . '`.');
         return $files;
     }
     if (false === $files[0]) {
         // Format when chunking: array( $finished = false, array( $startAt, $items ) )
         pb_backupbuddy::status('details', 'Deep file scan requires chunking.');
         return array('File scanning', array($custom_root, $files[1][0], $files[1][1]));
     } else {
         pb_backupbuddy::status('details', 'Deep file scan complete.');
     }
     // Remove root from path AND remote directories..
     foreach ($files as $i => &$file) {
         if (is_dir($file)) {
             // Don't track directories, only actual files.
             unset($files[$i]);
             continue 1;
         }
         $file = substr($file, $root_len);
     }
     // Flip array.
     $files = array_flip($files);
     // Check if this file is already in the list or not.
     $filesAdded = 0;
     //$addedSinceOutput = 0;
     //$outputEvery = 20; // Log every X number of files added into catalog.
     foreach ($files as $file => $ignoreID) {
         if ('' == $custom_root) {
             // Only increment existing files if scanning from root (because stats were reset for fresh count).
             self::$_state['stats']['files_total_count']++;
         }
         $pathed_file = $custom_root_diff . $file;
         // Applies custom root portion if applicable.
         if (!isset(self::$_catalog[$pathed_file])) {
             // File not already in signature list. Add it in with initial values.
             if ('' != $custom_root) {
                 // Was not added earlier yet.
                 self::$_state['stats']['files_total_count']++;
             }
             self::$_catalog[$pathed_file] = self::$_signatureDefaults;
             self::$_catalog[$pathed_file]['a'] = microtime(true);
             $filesAdded++;
             self::$_state['stats']['files_pending_send']++;
             //$addedSinceOutput++;
             /*
             if ( ( pb_backupbuddy::$options['log_level'] == '3' ) || ( $addedSinceOutput > $outputEvery ) ) { // Full logging enabled.
             	pb_backupbuddy::status( 'details', 'Added `' . $addedSinceOutput . '` more files. Last file: `' . $pathed_file . '`.' );
             	if ( $addedSinceOutput > $outputEvery ) {
             		$addedSinceOutput = 0;
             	}
             }
             */
             if ($filesAdded % 2000 == 0) {
                 self::$_state['stats']['files_to_catalog_percentage'] = round(number_format($filesAdded / count($files) * 100, 2));
                 self::$_stateObj->save();
             }
             if ('3' == pb_backupbuddy::$options['log_level']) {
                 // Full logging enabled.
                 pb_backupbuddy::status('details', 'Add to catalog: `' . $pathed_file . '`.');
             }
         } else {
             // Already exists in catalog.
             if (0 == self::$_catalog[$pathed_file]['b']) {
                 // File not backed up to server yet (pending send).
                 if (true !== self::$_catalog[$pathed_file]['d']) {
                     // Not pending deletion already.
                     if ('' == $custom_root) {
                         // Only increment existing files if scanning from root (because stats were reset for fresh count).
                         self::$_state['stats']['files_pending_send']++;
                     }
                 }
             } else {
                 // Local file already exists in catalog and on server. Make sure not marked for deletion.
                 if (true === self::$_catalog[$pathed_file]['d']) {
                     // Was marked to delete. Remove deltion mark BUT do rescan in case this is a new version of the file since it was for some reason marked to delete.
                     self::$_catalog[$pathed_file]['d'] = false;
                     // Don't immediately delete.
                     self::$_catalog[$pathed_file]['r'] = 0;
                     // Reset last scan time so it gets re-checked.
                 }
             }
         }
     }
     // Checking existing catalog files with new scan to see if anything needs deletion.
     $filesDeleted = 0;
     //$sinceLogTrim = 0;
     foreach (self::$_catalog as $signatureFile => &$signatureDetails) {
         if (true === $signatureDetails['d']) {
             // Already marked for deletion.
             continue;
         }
         if ('' != $custom_root) {
             // Custom root. Ignore removing any files not within the custom root since we did not scan those so they are not in the $files array.
             if ($root != substr($signatureFile, 0, $root_len)) {
                 // Beginning of filename does not match root so not applicable for this scan. Skip.
                 continue;
             }
         }
         if (!isset($files[$signatureFile])) {
             // File no longer exists in new scan. Mark for deletion.
             //$sinceLogTrim++;
             $filesDeleted++;
             $signatureDetails['d'] = true;
             self::$_state['stats']['files_pending_delete']++;
             // If it was not yet backed up, decrease pending count.
             if (0 == $signatureDetails['b']) {
                 self::$_state['stats']['files_pending_send']--;
                 if (self::$_state['stats']['files_pending_send'] < 0) {
                     self::$_state['stats']['files_pending_send'] = 0;
                 }
             }
             self::$_state['stats']['files_total_count']--;
             if (self::$_state['stats']['files_total_count'] < 0) {
                 self::$_state['stats']['files_total_count'] = 0;
             }
             pb_backupbuddy::status('details', 'Remove file that no longer exists locally. Flagging `' . $signatureFile . '` for deletion.');
             /*
             if ( $sinceLogTrim > 1000 ) {
             	$sinceLogTrim = 0;
             	self::$_catalogObj->save(); // In case it dies.
             	self::_truncate_log();
             }
             */
         }
     }
     self::$_catalogObj->save();
     pb_backupbuddy::status('details', 'Signatures saved. Added `' . $filesAdded++ . '` files to local catalog. Marked `' . $filesDeleted . '` files deleted. Took `' . (microtime(true) - $start_time) . '` seconds.');
     return true;
 }