public/wordpress/wp-content/plugins/backupbuddy/classes/backup.php
/*	backup_zip_files_standard()
	 *	
	 *	Create ZIP file containing everything.
	 *	
	 *	@return		boolean			True on success; false otherwise.
	 */


Create ZIP file containing everything.

@return         boolean                 True on success; false otherwise.
Create ZIP file containing everything . @return boolean True on success ; false otherwise .
protected function backup_zip_files_standard() {
		pb_backupbuddy::status( 'milestone', 'start_files' );
		pb_backupbuddy::status( 'details', 'Backup root: `' . $this->_backup['backup_root'] . '`.' );
		$totalPosts = 0;
		foreach( wp_count_posts( 'post' ) as $type => $count ) {
			$totalPosts += $count;
		}
		$totalPages = 0;
		foreach( wp_count_posts( 'page' ) as $type => $count ) {
			$totalPages += $count;
		}
		$totalComments = 0;
		foreach( wp_count_comments() as $type => $count ) {
			$totalComments += $count;
		}
		$totalUsers = count_users();
		$totalUsers = $totalUsers['total_users'];
		global $wpdb;
		$db_prefix = $wpdb->prefix;
		$zip_response = pb_backupbuddy::$classes['zipbuddy']->add_directory_to_zip(
			$this->_backup['archive_file'],									
			$this->_backup['backup_root'],									
			$this->_backup['directory_exclusions'],							
			$this->_backup['temporary_zip_directory']						
		);
		if ( $zip_response === true ) { 
			pb_backupbuddy::status( 'message', __('Backup ZIP file successfully created.', 'it-l10n-backupbuddy' ) );
			if ( chmod( $this->_backup['archive_file'], 0644) ) {
				pb_backupbuddy::status( 'details', __('Chmod of ZIP file to 0644 succeeded.', 'it-l10n-backupbuddy' ) );
			} else {
				pb_backupbuddy::status( 'details', __('Chmod of ZIP file to 0644 failed.', 'it-l10n-backupbuddy' ) );
			}
			if ( '0' == pb_backupbuddy::$options['save_comment_meta'] ) {
				pb_backupbuddy::status( 'details', 'Skipping saving meta data to zip comment based on settings.' );
			} else {
				pb_backupbuddy::status( 'details', 'Saving meta data to zip comment.' );
				global $wp_version;
				$meta = array(
						'serial'		=>	$this->_backup['serial'],
						'siteurl'		=>	site_url(),
						'type'			=>	$this->_backup['type'],
						'profile'		=>	$this->_backup['profile']['title'],
						'created'		=>	$this->_backup['start_time'],
						'generator'		=>	'backupbuddy',
						'db_prefix'		=>	$db_prefix,
						'bb_version'	=>	pb_backupbuddy::settings( 'version' ),
						'wp_version'	=>	$wp_version,
						'dat_path'		=>	str_replace( $this->_backup['backup_root'], '', $this->_backup['temp_directory'] . 'backupbuddy_dat.php' ),
						'posts'			=>	$totalPosts,
						'pages'			=>	$totalPages,
						'comments'		=>	$totalComments,
						'users'			=>	$totalUsers,
						'note'			=>	'',
					);
				$comment = backupbuddy_core::normalize_comment_data( $meta );
				pb_backupbuddy::status( 'startAction', 'zipCommentMeta' );
				$comment_result = pb_backupbuddy::$classes['zipbuddy']->set_comment( $this->_backup['archive_file'], $comment );
				pb_backupbuddy::status( 'finishAction', 'zipCommentMeta' );
				if ( $comment_result !== true ) {
					pb_backupbuddy::status( 'warning', 'Unable to save meta data to zip comment. This is not a fatal warning & will not impact the backup itself.' );
				} else {
					pb_backupbuddy::status( 'details', 'Saved meta data to zip comment.' );
				}
			}
		} else { 
			if ( file_exists( $this->_backup['temp_directory'] ) ) {
				pb_backupbuddy::status( 'details', __('Removing temp data directory.', 'it-l10n-backupbuddy' ) );
				pb_backupbuddy::$filesystem->unlink_recursive( $this->_backup['temp_directory'] );
			}
			if ( file_exists( $this->_backup['temporary_zip_directory'] ) ) {
				pb_backupbuddy::status( 'details', __('Removing temp zip directory.', 'it-l10n-backupbuddy' ) );
				pb_backupbuddy::$filesystem->unlink_recursive( $this->_backup['temporary_zip_directory'] );
			}
			pb_backupbuddy::status( 'error', __('Error #4001: Unable to successfully generate ZIP archive. Backup FAILED. See logs above for more information.', 'it-l10n-backupbuddy' ) );
			pb_backupbuddy::status( 'haltScript', '' ); 
			return false;
		} 
		@include_once( pb_backupbuddy::plugin_path() . '/lib/wpdbutils/wpdbutils.php' );
		if ( class_exists( 'pluginbuddy_wpdbutils' ) ) {
			global $wpdb;
			$dbhelper = new pluginbuddy_wpdbutils( $wpdb );
			if ( !$dbhelper->kick() ) {
				pb_backupbuddy::status( 'error', __('Backup FAILED. Backup file produced but Database Server has gone away, unable to schedule next backup step', 'it-l10n-backupbuddy' ) );
				return false;
			} else {
			}
		} else {
			pb_backupbuddy::status( 'details', __('Database Server connection status unverified.', 'it-l10n-backupbuddy' ) );
		}
		return true;
	}
protected function backup_zip_files_standard ( ) { pb_backupbuddy :: status ( 'milestone' , 'start_files' ) ; pb_backupbuddy :: status ( 'details' , 'Backup root: `' . $ this -> _backup [ 'backup_root' ] . '`.' ) ; $ totalPosts = 0 ; foreach ( wp_count_posts ( 'post' ) as $ type => $ count ) { $ totalPosts += $ count ; } $ totalPages = 0 ; foreach ( wp_count_posts ( 'page' ) as $ type => $ count ) { $ totalPages += $ count ; } $ totalComments = 0 ; foreach ( wp_count_comments ( ) as $ type => $ count ) { $ totalComments += $ count ; } $ totalUsers = count_users ( ) ; $ totalUsers = $ totalUsers [ 'total_users' ] ; global $ wpdb ; $ db_prefix = $ wpdb -> prefix ; $ zip_response = pb_backupbuddy :: $ classes [ 'zipbuddy' ] -> add_directory_to_zip ( $ this -> _backup [ 'archive_file' ] , $ this -> _backup [ 'backup_root' ] , $ this -> _backup [ 'directory_exclusions' ] , $ this -> _backup [ 'temporary_zip_directory' ] ) ; if ( $ zip_response === true ) { pb_backupbuddy :: status ( 'message' , __ ( 'Backup ZIP file successfully created.' , 'it-l10n-backupbuddy' ) ) ; if ( chmod ( $ this -> _backup [ 'archive_file' ] , 0644 ) ) { pb_backupbuddy :: status ( 'details' , __ ( 'Chmod of ZIP file to 0644 succeeded.' , 'it-l10n-backupbuddy' ) ) ; } else { pb_backupbuddy :: status ( 'details' , __ ( 'Chmod of ZIP file to 0644 failed.' , 'it-l10n-backupbuddy' ) ) ; } if ( '0' == pb_backupbuddy :: $ options [ 'save_comment_meta' ] ) { pb_backupbuddy :: status ( 'details' , 'Skipping saving meta data to zip comment based on settings.' ) ; } else { pb_backupbuddy :: status ( 'details' , 'Saving meta data to zip comment.' ) ; global $ wp_version ; $ meta = array ( 'serial' => $ this -> _backup [ 'serial' ] , 'siteurl' => site_url ( ) , 'type' => $ this -> _backup [ 'type' ] , 'profile' => $ this -> _backup [ 'profile' ] [ 'title' ] , 'created' => $ this -> _backup [ 'start_time' ] , 'generator' => 'backupbuddy' , 'db_prefix' => $ db_prefix , 'bb_version' => pb_backupbuddy :: settings ( 'version' ) , 'wp_version' => $ wp_version , 'dat_path' => str_replace ( $ this -> _backup [ 'backup_root' ] , '' , $ this -> _backup [ 'temp_directory' ] . 'backupbuddy_dat.php' ) , 'posts' => $ totalPosts , 'pages' => $ totalPages , 'comments' => $ totalComments , 'users' => $ totalUsers , 'note' => '' , ) ; $ comment = backupbuddy_core :: normalize_comment_data ( $ meta ) ; pb_backupbuddy :: status ( 'startAction' , 'zipCommentMeta' ) ; $ comment_result = pb_backupbuddy :: $ classes [ 'zipbuddy' ] -> set_comment ( $ this -> _backup [ 'archive_file' ] , $ comment ) ; pb_backupbuddy :: status ( 'finishAction' , 'zipCommentMeta' ) ; if ( $ comment_result !== true ) { pb_backupbuddy :: status ( 'warning' , 'Unable to save meta data to zip comment. This is not a fatal warning & will not impact the backup itself.' ) ; } else { pb_backupbuddy :: status ( 'details' , 'Saved meta data to zip comment.' ) ; } } } else { if ( file_exists ( $ this -> _backup [ 'temp_directory' ] ) ) { pb_backupbuddy :: status ( 'details' , __ ( 'Removing temp data directory.' , 'it-l10n-backupbuddy' ) ) ; pb_backupbuddy :: $ filesystem -> unlink_recursive ( $ this -> _backup [ 'temp_directory' ] ) ; } if ( file_exists ( $ this -> _backup [ 'temporary_zip_directory' ] ) ) { pb_backupbuddy :: status ( 'details' , __ ( 'Removing temp zip directory.' , 'it-l10n-backupbuddy' ) ) ; pb_backupbuddy :: $ filesystem -> unlink_recursive ( $ this -> _backup [ 'temporary_zip_directory' ] ) ; } pb_backupbuddy :: status ( 'error' , __ ( 'Error #4001: Unable to successfully generate ZIP archive. Backup FAILED. See logs above for more information.' , 'it-l10n-backupbuddy' ) ) ; pb_backupbuddy :: status ( 'haltScript' , '' ) ; return false ; } @ include_once ( pb_backupbuddy :: plugin_path ( ) . '/lib/wpdbutils/wpdbutils.php' ) ; if ( class_exists ( 'pluginbuddy_wpdbutils' ) ) { global $ wpdb ; $ dbhelper = new pluginbuddy_wpdbutils ( $ wpdb ) ; if ( ! $ dbhelper -> kick ( ) ) { pb_backupbuddy :: status ( 'error' , __ ( 'Backup FAILED. Backup file produced but Database Server has gone away, unable to schedule next backup step' , 'it-l10n-backupbuddy' ) ) ; return false ; } else { } } else { pb_backupbuddy :: status ( 'details' , __ ( 'Database Server connection status unverified.' , 'it-l10n-backupbuddy' ) ) ; } return true ; }
backup_zip_files_standard()
backup_zip_files_standard ()
// Set compression on / off. //pb_backupbuddy::$classes['zipbuddy']->set_compression( $this->_backup['compression'] ); // Calculate some statistics to store in meta later. These need to be calculated before zipping in case the DB goes away later to prevent a possible failure. // Create zip file! // string	Zip file to create. // string	Directory to zip up (root). // array	Files/directories to exclude. (array of strings). // string	Temp directory location to store zip file in. // Zip results. // Zip success. // Save meta information in comment. // Zip failure. // Delete temporary data directory. // Delete temporary ZIP directory. // Halt JS on page. // end zip failure. // Need to make sure the database connection is active. Sometimes it goes away during long bouts doing other things -- sigh. // This is not essential so use include and not require (suppress any warning) // This is the database object we want to use // Get our helper object and let it use us to output status messages // If we cannot kick the database into life then signal the error and return false which will stop the backup // Otherwise all is ok and we can just fall through and let the function return true //pb_backupbuddy::status( 'details', 'Database seems to still be connected.' ); // Utils not available so cannot verify database connection status - just notify