Example #1
0
 function backup_create_dat_file($trigger)
 {
     pb_backupbuddy::status('details', __('Creating DAT (data) file snapshotting site & backup information.', 'it-l10n-backupbuddy'));
     global $wpdb, $current_blog;
     $is_multisite = $is_multisite_export = false;
     //$from_multisite is from a site within a network
     $upload_url_rewrite = $upload_url = '';
     if (is_multisite() && $trigger == 'scheduled' || is_multisite() && is_network_admin()) {
         // MS Network Export IF ( in a network and triggered by a schedule ) OR ( in a network and logged in as network admin)
         $is_multisite = true;
     } elseif (is_multisite()) {
         // MS Export (individual site)
         $is_multisite_export = true;
         $uploads = wp_upload_dir();
         $upload_url_rewrite = site_url(str_replace(ABSPATH, '', $uploads['basedir']));
         // URL we rewrite uploads to. REAL direct url.
         $upload_url = $uploads['baseurl'];
         // Pretty virtual path to uploads directory.
     }
     // Handle wp-config.php file in a parent directory.
     if ($this->_backup['type'] == 'full') {
         $wp_config_parent = false;
         if (file_exists(ABSPATH . 'wp-config.php')) {
             // wp-config in normal place.
             pb_backupbuddy::status('details', 'wp-config.php found in normal location.');
         } else {
             // wp-config not in normal place.
             pb_backupbuddy::status('message', 'wp-config.php not found in normal location; checking parent directory.');
             if (file_exists(dirname(ABSPATH) . '/wp-config.php')) {
                 // Config in parent.
                 $wp_config_parent = true;
                 pb_backupbuddy::status('message', 'wp-config.php found in parent directory. Copying wp-config.php to temporary location for backing up.');
                 $this->_backup['wp-config_in_parent'] = true;
                 copy(dirname(ABSPATH) . '/wp-config.php', $this->_backup['temp_directory'] . 'wp-config.php');
             } else {
                 pb_backupbuddy::status('error', 'wp-config.php not found in normal location NOR parent directory. This will result in an incomplete backup which will be marked as bad.');
             }
         }
     } else {
         $wp_config_parent = false;
     }
     global $wp_version;
     $totalPosts = 0;
     foreach (wp_count_posts('post') as $counttype => $count) {
         $totalPosts += $count;
     }
     $totalPages = 0;
     foreach (wp_count_posts('page') as $counttype => $count) {
         $totalPages += $count;
     }
     $totalComments = 0;
     foreach (wp_count_comments() as $counttype => $count) {
         $totalComments += $count;
     }
     $totalUsers = count_users();
     $totalUsers = $totalUsers['total_users'];
     pb_backupbuddy::status('startSubFunction', json_encode(array('function' => 'post_count', 'title' => 'Found ' . $totalPosts . ' posts, ' . $totalPages . ' pages, and ' . $totalComments . ' comments.')));
     pb_backupbuddy::status('startSubFunction', json_encode(array('function' => 'post_count', 'title' => 'Found ' . $totalUsers . ' user accounts.')));
     $dat_content = array('backupbuddy_version' => pb_backupbuddy::settings('version'), 'wordpress_version' => $wp_version, 'backup_time' => $this->_backup['start_time'], 'backup_type' => $this->_backup['type'], 'profile' => $this->_backup['profile'], 'default_profile' => pb_backupbuddy::$options['profiles'][0], 'serial' => $this->_backup['serial'], 'trigger' => $trigger, 'wp-config_in_parent' => $wp_config_parent, 'deployment_direction' => $this->_backup['deployment_direction'], 'abspath' => ABSPATH, 'siteurl' => site_url(), 'homeurl' => home_url(), 'blogname' => get_option('blogname'), 'blogdescription' => get_option('blogdescription'), 'active_plugins' => implode(', ', get_option('active_plugins')), 'posts' => $totalPosts, 'pages' => $totalPages, 'comments' => $totalComments, 'users' => $totalUsers, 'wp_content_url' => WP_CONTENT_URL, 'wp_content_dir' => WP_CONTENT_DIR, 'db_charset' => $wpdb->charset, 'db_collate' => $wpdb->collate, 'db_prefix' => $wpdb->prefix, 'db_server' => DB_HOST, 'db_name' => DB_NAME, 'db_user' => '', 'db_password' => '', 'db_exclusions' => implode(',', backupbuddy_core::get_mysqldump_additional('excludes', $this->_backup['profile'])), 'db_inclusions' => implode(',', backupbuddy_core::get_mysqldump_additional('includes', $this->_backup['profile'])), 'db_version' => $wpdb->db_version(), 'breakout_tables' => $this->_backup['breakout_tables'], 'tables_sizes' => $this->_backup['table_sizes'], 'force_single_db_file' => $this->_backup['force_single_db_file'], 'is_multisite' => $is_multisite, 'is_multisite_export' => $is_multisite_export, 'domain' => is_object($current_blog) ? $current_blog->domain : '', 'path' => is_object($current_blog) ? $current_blog->path : '', 'upload_url' => $upload_url, 'upload_url_rewrite' => $upload_url_rewrite);
     // End setting $dat_content.
     // If currently using SSL or forcing admin SSL then we will check the hardcoded defined URL to make sure it matches.
     if (is_ssl() or defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN == true) {
         $dat_content['siteurl'] = get_option('siteurl');
         pb_backupbuddy::status('details', __('Compensating for SSL in siteurl.', 'it-l10n-backupbuddy'));
     }
     // Output for troubleshooting.
     pb_backupbuddy::status('details', 'DAT file contents (sans database user/pass): ' . str_replace("\n", '; ', print_r($dat_content, true)));
     // Remaining DB settings.
     $dat_content['db_user'] = DB_USER;
     $dat_content['db_password'] = DB_PASSWORD;
     // Serialize .dat file array.
     $dat_content = base64_encode(serialize($dat_content));
     // Write data to the dat file.
     $dat_file = $this->_backup['temp_directory'] . 'backupbuddy_dat.php';
     if (false === ($file_handle = fopen($dat_file, 'w'))) {
         pb_backupbuddy::status('details', sprintf(__('Error #9017: Temp data file is not creatable/writable. Check your permissions. (%s)', 'it-l10n-backupbuddy'), $dat_file));
         pb_backupbuddy::status('error', 'Temp data file is not creatable/writable. Check your permissions. (' . $dat_file . ')', '9017');
         return false;
     }
     fwrite($file_handle, "<?php die('Access Denied.'); // <!-- ?>\n" . $dat_content);
     fclose($file_handle);
     pb_backupbuddy::status('details', __('Finished creating DAT (data) file.', 'it-l10n-backupbuddy'));
     return true;
 }
Example #2
0
 public static function get_database_size($profile_id = 0)
 {
     global $wpdb;
     $prefix = $wpdb->prefix;
     $prefix_length = strlen($wpdb->prefix);
     $additional_includes = backupbuddy_core::get_mysqldump_additional('includes', pb_backupbuddy::$options['profiles'][$profile_id]);
     $additional_excludes = backupbuddy_core::get_mysqldump_additional('excludes', pb_backupbuddy::$options['profiles'][$profile_id]);
     $total_size = 0;
     $total_size_with_exclusions = 0;
     $rows = $wpdb->get_results("SHOW TABLE STATUS", ARRAY_A);
     foreach ($rows as $row) {
         $excluded = true;
         // Default.
         // TABLE STATUS.
         $rowsb = $wpdb->get_results("CHECK TABLE `{$row['Name']}`", ARRAY_A);
         foreach ($rowsb as $rowb) {
             if ($rowb['Msg_type'] == 'status') {
                 $status = $rowb['Msg_text'];
             }
         }
         unset($rowsb);
         // TABLE SIZE.
         $size = $row['Data_length'] + $row['Index_length'];
         $total_size += $size;
         // HANDLE EXCLUSIONS.
         if (pb_backupbuddy::$options['profiles'][$profile_id]['backup_nonwp_tables'] == 0) {
             // Only matching prefix.
             if (substr($row['Name'], 0, $prefix_length) == $prefix or in_array($row['Name'], $additional_includes)) {
                 if (!in_array($row['Name'], $additional_excludes)) {
                     $total_size_with_exclusions += $size;
                     $excluded = false;
                 }
             }
         } else {
             // All tables.
             if (!in_array($row['Name'], $additional_excludes)) {
                 $total_size_with_exclusions += $size;
                 $excluded = false;
             }
         }
     }
     pb_backupbuddy::$options['stats']['db_size'] = $total_size;
     pb_backupbuddy::$options['stats']['db_size_excluded'] = $total_size_with_exclusions;
     pb_backupbuddy::$options['stats']['db_size_updated'] = time();
     pb_backupbuddy::save();
     unset($rows);
     return array($total_size, $total_size_with_exclusions);
 }
Example #3
0
		</tr>
	</thead>
	<tfoot>
		<tr class="thead">
			<?php 
echo '<th>', __('Database Table', 'it-l10n-backupbuddy'), '</th>', '<th>', __('Status', 'it-l10n-backupbuddy'), '</th>', '<th>', __('Settings', 'it-l10n-backupbuddy'), '</th>', '<th>', __('Updated / Checked', 'it-l10n-backupbuddy'), '</th>', '<th>', __('Rows', 'it-l10n-backupbuddy'), '</th>', '<th>', __('Size', 'it-l10n-backupbuddy'), '</th>', '<th>', __('Excluded Size', 'it-l10n-backupbuddy'), '</th>';
?>
		</tr>
	</tfoot>
	<tbody>
		<?php 
global $wpdb;
$prefix = $wpdb->prefix;
$prefix_length = strlen($wpdb->prefix);
$additional_includes = backupbuddy_core::get_mysqldump_additional('includes', $profile);
$additional_excludes = backupbuddy_core::get_mysqldump_additional('excludes', $profile);
$total_size = 0;
$total_size_with_exclusions = 0;
$total_rows = 0;
$rows = $wpdb->get_results("SHOW TABLE STATUS", ARRAY_A);
foreach ($rows as $row) {
    $excluded = true;
    // Default.
    // TABLE STATUS.
    $rowsb = $wpdb->get_results("CHECK TABLE `{$row['Name']}`", ARRAY_A);
    foreach ($rowsb as $rowb) {
        if ($rowb['Msg_type'] == 'status') {
            $status = $rowb['Msg_text'];
        }
    }
    unset($rowsb);