public/wordpress/wp-content/plugins/backupbuddy/classes/backup.php
/*	start_backup_process()
	 *	
	 *	Initializes the entire backup process.
	 *	
	 *	@param		array		$profile			Backup profile array. Previously (pre-4.0): Valid values: db, full, export.
	 *	@param		string		$trigger			What triggered this backup. Valid values: ::d, manual.
	 *	@param		array		$pre_backup			Array of functions to prepend to the backup steps array.
	 *	@param		array		$post_backup		Array of functions to append to the backup steps array. Ie. sending to remote destination.
	 *	@param		string		$schedule_title		Title name of schedule. Used for tracking what triggered this in logging. For debugging.
	 *	@param		string		$serial_override	If provided then this serial will be used instead of an auto-generated one.
	 *	@param		array		$export_plugins		For use in export backup type. List of plugins to export.
	 *	@param		string		$deployDirection	blank for not deploy, push, or pull.
	 @	@param		array|''	$deploySettings		Destination settings for the deployment. Empty string when not deployment.
	 *	@return		boolean							True on success; false otherwise.
	 */


Initializes the entire backup process.

@param          array           $profile                        Backup profile array. Previously (pre-4.0): Valid values: db, full, export.
@param          string          $trigger                        What triggered this backup. Valid values: ::d, manual.
@param          array           $pre_backup                     Array of functions to prepend to the backup steps array.
@param          array           $post_backup            Array of functions to append to the backup steps array. Ie. sending to remote destination.
@param          string          $schedule_title         Title name of schedule. Used for tracking what triggered this in logging. For debugging.
@param          string          $serial_override        If provided then this serial will be used instead of an auto-generated one.
@param          array           $export_plugins         For use in export backup type. List of plugins to export.
@param          string          $deployDirection        blank for not deploy, push, or pull.
Initializes the entire backup process . @param array $profile Backup profile array . Previously ( pre - 4 . 0 ) : Valid values : db full export . @param string $trigger What triggered this backup . Valid values : :: d manual . @param array $pre_backup Array of functions to prepend to the backup steps array . @param array $post_backup Array of functions to append to the backup steps array . Ie . sending to remote destination . @param string $schedule_title Title name of schedule . Used for tracking what triggered this in logging . For debugging . @param string $serial_override If provided then this serial will be used instead of an auto - generated one . @param array $export_plugins For use in export backup type . List of plugins to export . @param string $deployDirection blank for not deploy push or pull .
function start_backup_process( $profile, $trigger = 'manual', $pre_backup = array(), $post_backup = array(), $schedule_title = '', $serial_override = '', $export_plugins = array(), $deployDirection = '', $deployDestinationSettings = '' ) {
		if ( $serial_override != '' ) {
			$serial = $serial_override;
		} else {
			$serial = pb_backupbuddy::random_string( 10 );
		}
		pb_backupbuddy::set_status_serial( $serial ); 
		$originalExcludes = $profile['excludes'];
		$default_global_profile = pb_backupbuddy::settings( 'default_options' );
		$default_global_profile = $default_global_profile['profiles'][0];
		$default_global_profile = array_merge( $default_global_profile, pb_backupbuddy::$options['profiles'][0] );
		if ( $default_global_profile != pb_backupbuddy::$options['profiles'][0] ) {
			pb_backupbuddy::$options['profiles'][0] = $default_global_profile;
			pb_backupbuddy::save();
			pb_backupbuddy::status( 'details', 'Default global profile needed updated with merged defaults. Updated and saved.' );
		}
		$profile = array_merge( pb_backupbuddy::settings( 'profile_defaults' ), $profile );
		foreach( $profile as $profile_item_name => &$profile_item ) { 
			if ( '-1' == $profile_item ) { 
				if ( isset( pb_backupbuddy::$options['profiles'][0][ $profile_item_name ] ) ) {
					$profile_item = pb_backupbuddy::$options['profiles'][0][ $profile_item_name ]; 
				}
			}
		}
		$profile['excludes'] = $originalExcludes;
		global $wp_version;
		pb_backupbuddy::status( 'details', 'BackupBuddy v' . pb_backupbuddy::settings( 'version' ) . ' using WordPress v' . $wp_version . ' with PHP v' . PHP_VERSION . ' on ' . PHP_OS . ' operating system.' );
		if ( '1' == $profile['backup_mode'] ) { 
			$backup_mode = '1';
		} elseif ( '2' == $profile['backup_mode'] ) { 
			$backup_mode = '2';
		} else {
			pb_backupbuddy::status( 'warning', 'Warning #38984984: Unknown backup mode `' . $profile['backup_mode'] . '`. Defaulting to modern mode (2).' );
			$backup_mode = '2';
		}
		pb_backupbuddy::status( 'details', 'Backup mode value setting to: `' . $backup_mode . '`. Profile was: `' . $profile['backup_mode'] . '`. Global default is: `' . (string)pb_backupbuddy::$options['profiles'][0]['backup_mode'] . '`.' );
		$profile['backup_mode'] = $backup_mode;
		unset( $backup_mode );
		if ( '1' == $profile['backup_mode'] ) {
		}
		$type = $profile['type'];
		$archiveFile = backupbuddy_core::calculateArchiveFilename( $serial, $type, $profile );
			if ( $this->pre_backup( $serial, $archiveFile, $profile, $trigger, $pre_backup, $post_backup, $schedule_title, $export_plugins, $deployDirection, $deployDestinationSettings ) === false ) {
				pb_backupbuddy::status( 'details', 'pre_backup() function failed.' );
				return false;
			}
		if ( ( $trigger == 'scheduled' ) && ( pb_backupbuddy::$options['email_notify_scheduled_start'] != '' ) ) {
			pb_backupbuddy::status( 'details', __('Sending scheduled backup start email notification if applicable.', 'it-l10n-backupbuddy' ) );
			backupbuddy_core::mail_notify_scheduled( $serial, 'start', __('Scheduled backup', 'it-l10n-backupbuddy' ) . ' (' . $this->_backup['schedule_title'] . ') has begun.' );
		}
		if ( $profile['backup_mode'] == '2' ) { 
			pb_backupbuddy::status( 'message', 'Running in modern backup mode based on settings. Mode value: `' . $profile['backup_mode'] . '`. Trigger: `' . $trigger . '`.' );
			unset( $this->_backup_options ); 
			if ( ( $trigger != 'manual' ) || ( defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON ) ) {
				pb_backupbuddy::status( 'details', 'IMPORTANT NOTE: ALTERNATE_WP_CRON defined AND enabled!' );
				$this->cron_next_step( $this->_backup['serial'], false );
			} else {
				$this->cron_next_step( $this->_backup['serial'], false ); 
			}
		} else { 
			pb_backupbuddy::status( 'message', 'Running in classic backup mode based on settings. Mode code: `' . $profile['backup_mode'] . '`.' );
			$this->process_backup( $this->_backup['serial'], $trigger );
		}
		return true;
	}
function start_backup_process ( $ profile , $ trigger = 'manual' , $ pre_backup = array ( ) , $ post_backup = array ( ) , $ schedule_title = '' , $ serial_override = '' , $ export_plugins = array ( ) , $ deployDirection = '' , $ deployDestinationSettings = '' ) { if ( $ serial_override != '' ) { $ serial = $ serial_override ; } else { $ serial = pb_backupbuddy :: random_string ( 10 ) ; } pb_backupbuddy :: set_status_serial ( $ serial ) ; $ originalExcludes = $ profile [ 'excludes' ] ; $ default_global_profile = pb_backupbuddy :: settings ( 'default_options' ) ; $ default_global_profile = $ default_global_profile [ 'profiles' ] [ 0 ] ; $ default_global_profile = array_merge ( $ default_global_profile , pb_backupbuddy :: $ options [ 'profiles' ] [ 0 ] ) ; if ( $ default_global_profile != pb_backupbuddy :: $ options [ 'profiles' ] [ 0 ] ) { pb_backupbuddy :: $ options [ 'profiles' ] [ 0 ] = $ default_global_profile ; pb_backupbuddy :: save ( ) ; pb_backupbuddy :: status ( 'details' , 'Default global profile needed updated with merged defaults. Updated and saved.' ) ; } $ profile = array_merge ( pb_backupbuddy :: settings ( 'profile_defaults' ) , $ profile ) ; foreach ( $ profile as $ profile_item_name => & $ profile_item ) { if ( '-1' == $ profile_item ) { if ( isset ( pb_backupbuddy :: $ options [ 'profiles' ] [ 0 ] [ $ profile_item_name ] ) ) { $ profile_item = pb_backupbuddy :: $ options [ 'profiles' ] [ 0 ] [ $ profile_item_name ] ; } } } $ profile [ 'excludes' ] = $ originalExcludes ; global $ wp_version ; pb_backupbuddy :: status ( 'details' , 'BackupBuddy v' . pb_backupbuddy :: settings ( 'version' ) . ' using WordPress v' . $ wp_version . ' with PHP v' . PHP_VERSION . ' on ' . PHP_OS . ' operating system.' ) ; if ( '1' == $ profile [ 'backup_mode' ] ) { $ backup_mode = '1' ; } elseif ( '2' == $ profile [ 'backup_mode' ] ) { $ backup_mode = '2' ; } else { pb_backupbuddy :: status ( 'warning' , 'Warning #38984984: Unknown backup mode `' . $ profile [ 'backup_mode' ] . '`. Defaulting to modern mode (2).' ) ; $ backup_mode = '2' ; } pb_backupbuddy :: status ( 'details' , 'Backup mode value setting to: `' . $ backup_mode . '`. Profile was: `' . $ profile [ 'backup_mode' ] . '`. Global default is: `' . ( string ) pb_backupbuddy :: $ options [ 'profiles' ] [ 0 ] [ 'backup_mode' ] . '`.' ) ; $ profile [ 'backup_mode' ] = $ backup_mode ; unset ( $ backup_mode ) ; if ( '1' == $ profile [ 'backup_mode' ] ) { } $ type = $ profile [ 'type' ] ; $ archiveFile = backupbuddy_core :: calculateArchiveFilename ( $ serial , $ type , $ profile ) ; if ( $ this -> pre_backup ( $ serial , $ archiveFile , $ profile , $ trigger , $ pre_backup , $ post_backup , $ schedule_title , $ export_plugins , $ deployDirection , $ deployDestinationSettings ) === false ) { pb_backupbuddy :: status ( 'details' , 'pre_backup() function failed.' ) ; return false ; } if ( ( $ trigger == 'scheduled' ) && ( pb_backupbuddy :: $ options [ 'email_notify_scheduled_start' ] != '' ) ) { pb_backupbuddy :: status ( 'details' , __ ( 'Sending scheduled backup start email notification if applicable.' , 'it-l10n-backupbuddy' ) ) ; backupbuddy_core :: mail_notify_scheduled ( $ serial , 'start' , __ ( 'Scheduled backup' , 'it-l10n-backupbuddy' ) . ' (' . $ this -> _backup [ 'schedule_title' ] . ') has begun.' ) ; } if ( $ profile [ 'backup_mode' ] == '2' ) { pb_backupbuddy :: status ( 'message' , 'Running in modern backup mode based on settings. Mode value: `' . $ profile [ 'backup_mode' ] . '`. Trigger: `' . $ trigger . '`.' ) ; unset ( $ this -> _backup_options ) ; if ( ( $ trigger != 'manual' ) || ( defined ( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) ) { pb_backupbuddy :: status ( 'details' , 'IMPORTANT NOTE: ALTERNATE_WP_CRON defined AND enabled!' ) ; $ this -> cron_next_step ( $ this -> _backup [ 'serial' ] , false ) ; } else { $ this -> cron_next_step ( $ this -> _backup [ 'serial' ] , false ) ; } } else { pb_backupbuddy :: status ( 'message' , 'Running in classic backup mode based on settings. Mode code: `' . $ profile [ 'backup_mode' ] . '`.' ) ; $ this -> process_backup ( $ this -> _backup [ 'serial' ] , $ trigger ) ; } return true ; }
start_backup_process()
start_backup_process ()
// Default logging serial. // Temporarily hold excludes so we can put them back later after merging defaults. // Merge global profile defaults array. Save if merging added anything. // Load profile defaults. // replace non-overridden defaults with actual default value. // Set to use default so go grab default. // Grab value from defaults profile and replace with it. // Re-apply original excludes without defaults merged (handle these in get_directory_exclusions(). //pb_backupbuddy::status( 'details', __('Peak memory usage', 'it-l10n-backupbuddy' ) . ': ' . round( memory_get_peak_usage() / 1048576, 3 ) . ' MB' ); // Profile forces classic. // Profiles forces modern. // If classic mode then we need to redirect output to displaying inline via JS instead of AJAX-based. //global $pb_backupbuddy_js_status; //$pb_backupbuddy_js_status = true; //if ( 'pull' != $deployDirection ) { /*
		} else { // PULL deployment.
			
			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 #38293. 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.
			$this->_backup['serial'] = $serial;
		}
		*/ // Modern mode with crons. // File unlocking is handled on deconstruction.  Make sure unlocked before firing off another cron spawn. // If using alternate cron on a manually triggered backup then skip running the cron on this pageload to avoid header already sent warnings. //$this->cron_next_step( true ); // as of Aug 9, 2013 no longer spawn the cron. Caused very odd issue of double code runs. // Classic mode; everything runs in this single PHP page load.