public static function test($settings) { $email = $settings['address']; pb_backupbuddy::status('details', 'Testing email destination. Sending ImportBuddy.php.'); $importbuddy_temp = backupbuddy_core::getTempDirectory() . 'importbuddy_' . pb_backupbuddy::random_string(10) . '.php.tmp'; // Full path & filename to temporary importbuddy backupbuddy_core::importbuddy($importbuddy_temp); // Create temporary importbuddy. $files = array($importbuddy_temp); if (pb_backupbuddy::$options['email_return'] != '') { $email_return = pb_backupbuddy::$options['email_return']; } else { $email_return = get_option('admin_email'); } $headers = 'From: BackupBuddy <' . $email_return . '>' . "\r\n"; $wp_mail_result = wp_mail($email, 'BackupBuddy Test', 'BackupBuddy destination test for ' . site_url(), $headers, $files); pb_backupbuddy::status('details', 'Sent test email.'); @unlink($importbuddy_temp); if ($wp_mail_result === true) { // WP sent. Hopefully it makes it! return true; } else { // WP couldn't try to send. echo 'WordPress was unable to attempt to send email. Check your WordPress & server settings.'; return false; } }
public function run($arguments) { $arguments = Ithemes_Sync_Functions::merge_defaults($arguments, $this->default_arguments); $profile = $arguments['profile']; if ('db' == $profile) { // db profile is always index 1. $profile = '1'; } elseif ('full' == $profile) { // full profile is always index 2. $profile = '2'; } if (is_numeric($profile)) { if (isset(pb_backupbuddy::$options['profiles'][$profile])) { $profileArray = pb_backupbuddy::$options['profiles'][$profile]; } else { return array('api' => '0', 'status' => 'error', 'message' => 'Error #2332904: Invalid profile ID `' . htmlentities($profile) . '`. Profile with this number was not found. Try deactivating then reactivating the plugin. If this fails please reset the plugin Settings back to Defaults from the Settings page.'); } } else { return array('api' => '0', 'status' => 'error', 'message' => 'Error #85489548955. Invalid profile ID not numeric: `' . htmlentities($profile) . '`.'); } require_once pb_backupbuddy::plugin_path() . '/classes/backup.php'; pb_backupbuddy::$classes['backup'] = new pb_backupbuddy_backup(); // Set serial ahead of time so can be used by AJAX before backup procedure actually begins. $serial = pb_backupbuddy::random_string(10); $profileArray['backup_mode'] = '2'; // Force modern mode when running under sync. // Run the backup! if (pb_backupbuddy::$classes['backup']->start_backup_process($profileArray, 'manual', array(), array(), 'it-sync', $serial, array()) !== true) { return array('api' => '0', 'status' => 'error', 'message' => 'Error #435832: Backup failed. See BackupBuddy log for details.'); } return array('api' => '0', 'status' => 'ok', 'message' => 'Backup initiated successfully.'); }
public static function test($settings) { /* if ( ( $settings['address'] == '' ) || ( $settings['username'] == '' ) || ( $settings['password'] == '' ) ) { return __('Missing required input.', 'it-l10n-backupbuddy' ); } */ // Try sending a file. return pb_backupbuddy_destinations::send($settings, dirname(dirname(__FILE__)) . '/remote-send-test.php', $send_id = 'TEST-' . pb_backupbuddy::random_string(12)); // 3rd param true forces clearing of any current uploads. }
/** * Run a BackupBuddy backup. http://getbackupbuddy.com * * ## OPTIONS * * <profile> * : Profile may either specify the profile ID number, "full" to run the first defined Full backup profile, or "db" to run the first defined Database-only backup profile. The first Full and Database-only profiles are always available as they are not user-deletable. To find the profile number, run a backup inside BackupBuddy in WordPress and note the number at the end of the URL (3 in this case): http://...&backupbuddy_backup=3 * * [--quiet] * : Suppresses display of status log information from being output to the screen. * * ## EXAMPLES * * RUN FULL BACKUP: wp backupbuddy backup full * RUN PROFILE #3: wp backupbuddy backup 3 * * @synopsis <profile> [--quiet] */ public function backup($args, $assoc_args) { $profile = $args[0]; if ('db' == $profile) { // db profile is always index 1. $profile = '1'; } elseif ('full' == $profile) { // full profile is always index 2. $profile = '2'; } if (is_numeric($profile)) { if (isset(pb_backupbuddy::$options['profiles'][$profile])) { $profileArray = pb_backupbuddy::$options['profiles'][$profile]; } else { WP_CLI::error('Error #2332904: Invalid profile ID `' . htmlentities($profile) . '`. Profile with this number was not found. Try deactivating then reactivating the plugin. If this fails please reset the plugin Settings back to Defaults from the Settings page.'); return; } } else { WP_CLI::error('Error #85489548955. Invalid profile ID not numeric: `' . htmlentities($profile) . '`.'); return; } require_once pb_backupbuddy::plugin_path() . '/classes/backup.php'; pb_backupbuddy::$classes['backup'] = new pb_backupbuddy_backup(); // Set serial ahead of time so can be used by AJAX before backup procedure actually begins. $serial = pb_backupbuddy::random_string(10); $profileArray['backup_mode'] = '1'; // Force classic mode when running under command line. if (!isset($assoc_args['quiet'])) { define('BACKUPBUDDY_WP_CLI', true); } // Run the backup! if (pb_backupbuddy::$classes['backup']->start_backup_process($profileArray, 'manual', array(), array(), 'wp-cli', $serial, array()) !== true) { WP_CLI::error('Error #435832: Backup failed. See BackupBuddy log for details.'); return; } WP_CLI::success('Backup completed successfully.'); return; }
function start_backup_process($profile, $trigger = 'manual', $pre_backup = array(), $post_backup = array(), $schedule_title = '', $serial_override = '', $export_plugins = array()) { // Load profile defaults. $profile = array_merge(pb_backupbuddy::settings('profile_defaults'), $profile); foreach ($profile as $profile_item_name => &$profile_item) { // replace non-overridden defaults with actual default value. if ('-1' == $profile_item) { // Set to use default so go grab default. if (isset(pb_backupbuddy::$options['profiles'][0][$profile_item_name])) { $profile_item = pb_backupbuddy::$options['profiles'][0][$profile_item_name]; // Grab value from defaults profile and replace with it. } } } // Handle backup mode. $backup_mode = pb_backupbuddy::$options['backup_mode']; // Load global default mode. if ('1' == $profile['backup_mode']) { // Profile forces classic. $backup_mode = '1'; } elseif ('2' == $profile['backup_mode']) { // Profiles forces modern. $backup_mode = '2'; } $profile['backup_mode'] = $backup_mode; unset($backup_mode); // If classic mode then we need to redirect output to displaying inline via JS instead of AJAX-based. if ('1' == $profile['backup_mode']) { //global $pb_backupbuddy_js_status; //$pb_backupbuddy_js_status = true; } if ($serial_override != '') { $serial = $serial_override; } else { $serial = pb_backupbuddy::random_string(10); } pb_backupbuddy::set_status_serial($serial); // Default logging serial. global $wp_version; pb_backupbuddy::status('details', 'BackupBuddy v' . pb_backupbuddy::settings('version') . ' using WordPress v' . $wp_version . ' on ' . PHP_OS . '.'); //pb_backupbuddy::status( 'details', __('Peak memory usage', 'it-l10n-backupbuddy' ) . ': ' . round( memory_get_peak_usage() / 1048576, 3 ) . ' MB' ); if ($this->pre_backup($serial, $profile, $trigger, $pre_backup, $post_backup, $schedule_title, $export_plugins) === 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') { // Modern mode with crons. pb_backupbuddy::status('message', 'Running in modern backup mode based on settings. Mode value: `' . $profile['backup_mode'] . '`. Trigger: `' . $trigger . '`.'); unset($this->_backup_options); // 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. if ($trigger != 'manual' || defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) { $this->cron_next_step(false); } else { //$this->cron_next_step( true ); $this->cron_next_step(false); // as of Aug 9, 2013 no longer spawn the cron. Caused very odd issue of double code runs. } } else { // Classic mode; everything runs in this single PHP page load. pb_backupbuddy::status('message', 'Running in classic backup mode based on settings.'); $this->process_backup($this->_backup['serial'], $trigger); } return true; }
function remote_test() { if (defined('PB_DEMO_MODE')) { die('Access denied in demo mode.'); } if (!isset(pb_backupbuddy::$classes['core'])) { require_once pb_backupbuddy::plugin_path() . '/classes/core.php'; pb_backupbuddy::$classes['core'] = new pb_backupbuddy_core(); } if ($_POST['#type'] == 's3') { if ($_POST['#ssl'] == '1') { $s3_ssl = true; } else { $s3_ssl = false; } if (true === ($response = pb_backupbuddy::$classes['core']->test_s3($_POST['#accesskey'], $_POST['#secretkey'], $_POST['#bucket'], $_POST['#directory'], $s3_ssl))) { echo __('Test completed successfully.', 'it-l10n-backupbuddy'); } else { echo __('Failure', 'it-l10n-backupbuddy') . '; ' . $response; } } elseif ($_POST['#type'] == 'rackspace') { if (true === ($response = pb_backupbuddy::$classes['core']->test_rackspace($_POST['#username'], $_POST['#api_key'], $_POST['#container'], $_POST['#server']))) { echo __('Test completed successfully.', 'it-l10n-backupbuddy'); } else { echo __('Failure', 'it-l10n-backupbuddy') . '; ' . $response; } } elseif ($_POST['#type'] == 'ftp') { if ($_POST['#ftps'] == '0') { $ftp_type = 'ftp'; } else { $ftp_type = 'ftps'; } if (true === ($response = pb_backupbuddy::$classes['core']->test_ftp($_POST['#address'], $_POST['#username'], $_POST['#password'], $_POST['#path'], $ftp_type))) { echo __('Test completed successfully.', 'it-l10n-backupbuddy'); } else { echo __('Failure', 'it-l10n-backupbuddy') . '; ' . $response; } } elseif (pb_backupbuddy::_POST('#type') == 'local') { // Used for automatic migration currently. if (!file_exists(pb_backupbuddy::_POST('path'))) { pb_backupbuddy::$filesystem->mkdir(pb_backupbuddy::_POST('path')); } if (is_writable(pb_backupbuddy::_POST('path')) === true) { if (pb_backupbuddy::_POST('url') == '') { // No URL provided. echo __('Test completed successfully without URL. You may enter it on the next page.', 'it-l10n-backupbuddy'); } else { // URL provided. if (file_exists(rtrim(pb_backupbuddy::_POST('path'), '/\\') . '/wp-login.php')) { echo 'Warning: WordPress appears to already exist in this location. '; } $test_filename = 'migrate_test_' . pb_backupbuddy::random_string(10) . '.php'; $test_file_path = rtrim(pb_backupbuddy::_POST('path'), '/\\') . '/' . $test_filename; file_put_contents($test_file_path, "<?php die( '1' ); ?>"); $response = wp_remote_get(rtrim(pb_backupbuddy::_POST('url'), '/\\') . '/' . $test_filename, array('method' => 'GET', 'timeout' => 45, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => null, 'cookies' => array())); unlink($test_file_path); if (is_wp_error($response)) { die(__('Failure. Unable to connect to the provided URL.', 'it-l10n-backupbuddy')); } if (trim($response['body']) == '1') { echo __('Test completed successfully. Path and URL appear valid and match.', 'it-l10n-backupbuddy'); } else { echo __('Failure. The path appears valid but the URL does not correspond to it.', 'it-l10n-backupbuddy'); } } } else { echo __('Failure', 'it-l10n-backupbuddy') . '; The path does not allow writing. Please verify write file permissions.'; } } else { echo 'Error #4343489. There is not an automated test available for this service `' . $_POST['#type'] . '` at this time.'; } die; }
function __construct($save_point, $default_options_point) { $this->_save_point = $save_point; $this->_default_options_point = $default_options_point; $this->_instance = pb_backupbuddy::random_string(); }
public static function test($settings) { $settings = self::_init($settings); // Try sending a file. $send_response = pb_backupbuddy_destinations::send($settings, dirname(dirname(__FILE__)) . '/remote-send-test.php', $send_id = 'TEST-' . pb_backupbuddy::random_string(12)); // 3rd param true forces clearing of any current uploads. if (false === $send_response) { $send_response = 'Error sending test file to S3.'; } else { $send_response = 'Success.'; } // Delete sent file. $delete_response = 'Success.'; try { $delete_response = self::$_client->delete_object(array('Bucket' => $settings['bucket'], 'Key' => $settings['directory'] . 'remote-send-test.php')); $delete_response = 'Success.'; } catch (Exception $e) { pb_backupbuddy::status('details', 'Unable to delete test S3 file `remote-send-test.php`. Details: `' . $e->getMessage() . '`.'); } // Load destination fileoptions. pb_backupbuddy::status('details', 'About to load fileoptions data.'); require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php'; pb_backupbuddy::status('details', 'Fileoptions instance #7.'); $fileoptions_obj = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $send_id . '.txt', $read_only = false, $ignore_lock = false, $create_file = false); if (true !== ($result = $fileoptions_obj->is_ok())) { return self::_error(__('Fatal Error #9034.84838. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result); } pb_backupbuddy::status('details', 'Fileoptions data loaded.'); $fileoptions =& $fileoptions_obj->options; if ('Success.' != $send_response || 'Success.' != $delete_response) { $fileoptions['status'] = 'failure'; $fileoptions_obj->save(); unset($fileoptions_obj); return 'Send details: `' . $send_response . '`. Delete details: `' . $delete_response . '`.'; } else { $fileoptions['status'] = 'success'; $fileoptions['finish_time'] = time(); } $fileoptions_obj->save(); unset($fileoptions_obj); return true; }
public static function generate_key() { if (!defined('BACKUPBUDDY_API_ENABLE') || TRUE != BACKUPBUDDY_API_ENABLE) { return false; } /* if ( ! defined( 'BACKUPBUDDY_API_SALT' ) || ( 'CHANGEME' == BACKUPBUDDY_API_SALT ) || ( strlen( BACKUPBUDDY_API_SALT ) < 5 ) ) { return false; } */ $siteurl = site_url(); $homeurl = home_url(); $rand = pb_backupbuddy::random_string(12); $rand2 = pb_backupbuddy::random_string(12); $key = array('key_version' => 1, 'key_public' => md5($rand . pb_backupbuddy::$options['log_serial'] . $siteurl . $homeurl . time()), 'key_secret' => md5($rand2 . pb_backupbuddy::$options['log_serial'] . $siteurl . $homeurl . time()), 'key_created' => time(), 'siteurl' => $siteurl, 'homeurl' => $homeurl); return base64_encode(json_encode($key)); }
_e('Deployment', 'it-l10n-backupbuddy'); ?> </h3> Remote API Access allows other sites with your API access key entered to push to or pull data from this site. <br><br> <button class="button button-primary" style="vertical-align: 1px;" onClick="jQuery('.backupbuddy_api_wpconfig-hide').toggle(); jQuery(this).hide(); return false;"><?php _e('Enable Deployment', 'it-l10n-backupbuddy'); ?> </button> <span class="backupbuddy_api_wpconfig-hide" style="display: none;"> <b>For added security you must manually <i>add the following to your wp-config.php</i> file to enable. <i>Refresh this page after adding</i> the following:</b> <br> <textarea style="width: 100%; padding: 15px;" readonly="readonly" onClick="this.focus();this.select();"> define( 'BACKUPBUDDY_API_ENABLE', true ); // Enable BackupBuddy Deployment access. </textarea><!-- define( 'BACKUPBUDDY_API_SALT', '<?php echo pb_backupbuddy::random_string(32); ?> ' ); // Random security identifier. 5+ characters. --> </span> <br> <?php } } echo '</div>'; echo '<div class="backupbuddy-destination-sends" style="display: none;"><br>'; require_once 'server_info/remote_sends.php'; echo '<br></div>'; echo '<iframe id="pb_backupbuddy_iframe-dest-wrap" src="' . pb_backupbuddy::ajax_url('destinationTabs') . '&tab=' . $default_tab . '&action_verb=to%20manage%20files" width="100%" height="4000" frameBorder="0">Error #4584594579. Browser not compatible with iframes.</iframe>'; ?> <br style="clear: both;"><br style="clear: both;">
function send_remote_destination($destination_id, $file, $trigger = '', $send_importbuddy = false) { pb_backupbuddy::status('details', 'Sending file `' . $file . '` to remote destination `' . $destination_id . '` triggered by `' . $trigger . '`.'); if (defined('PB_DEMO_MODE')) { return false; } // Record some statistics. $identifier = pb_backupbuddy::random_string(12); pb_backupbuddy::$options['remote_sends'][$identifier] = array('destination' => $destination_id, 'file' => $file, 'file_size' => filesize($file), 'trigger' => $trigger, 'send_importbuddy' => $send_importbuddy, 'start_time' => time(), 'finish_time' => 0, 'status' => 'timeout'); pb_backupbuddy::save(); // Prepare variables to pass to remote destination handler. $files = array($file); $destination_settings =& pb_backupbuddy::$options['remote_destinations'][$destination_id]; // For Stash we will check the quota prior to initiating send. if (pb_backupbuddy::$options['remote_destinations'][$destination_id]['type'] == 'stash') { // Pass off to destination handler. require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php'; $send_result = pb_backupbuddy_destinations::get_info('stash'); // Used to kick the Stash destination into life. $stash_quota = pb_backupbuddy_destination_stash::get_quota(pb_backupbuddy::$options['remote_destinations'][$destination_id], true); if ($file != '') { $backup_file_size = filesize($file); } else { $backip_file_size = 50000; } if ($backup_file_size + $stash_quota['quota_used'] > $stash_quota['quota_total']) { $message = ''; $message .= "You do not have enough Stash storage space to send this file. Please upgrade your Stash storage at http://ithemes.com/member/stash.php or delete files to make space.\n\n"; $message .= 'Attempting to send file of size ' . pb_backupbuddy::$format->file_size($backup_file_size) . ' but you only have ' . $stash_quota['quota_available_nice'] . ' available. '; $message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).'; pb_backupbuddy::status('error', $message); pb_backupbuddy::$classes['core']->mail_error($message); pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'Failure. Insufficient destination space.'; pb_backupbuddy::save(); return false; } else { if (isset($stash_quota['quota_warning']) && $stash_quota['quota_warning'] != '') { // We log warning of usage but dont send error email. $message = ''; $message .= 'WARNING: ' . $stash_quota['quota_warning'] . "\n\nPlease upgrade your Stash storage at http://ithemes.com/member/stash.php or delete files to make space.\n\n"; $message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).'; pb_backupbuddy::status('details', $message); //pb_backupbuddy::$classes['core']->mail_error( $message ); } } } if ($send_importbuddy === true) { pb_backupbuddy::status('details', 'Generating temporary importbuddy.php file for remote send.'); $importbuddy_temp = pb_backupbuddy::$options['temp_directory'] . 'importbuddy.php'; // Full path & filename to temporary importbuddy $this->importbuddy($importbuddy_temp); // Create temporary importbuddy. pb_backupbuddy::status('details', 'Generated temporary importbuddy.'); $files[] = $importbuddy_temp; // Add importbuddy file to the list of files to send. $send_importbuddy = true; // Track to delete after finished. } else { pb_backupbuddy::status('details', 'Not sending importbuddy.'); } // Pass off to destination handler. require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php'; $send_result = pb_backupbuddy_destinations::send($destination_settings, $files); $this->kick_db(); // Kick the database to make sure it didn't go away, preventing options saving. // Update stats. pb_backupbuddy::$options['remote_sends'][$identifier]['finish_time'] = time(); if ($send_result === true) { // succeeded. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'success'; pb_backupbuddy::status('details', 'Remote send SUCCESS.'); } elseif ($send_result === false) { // failed. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'failure'; pb_backupbuddy::status('details', 'Remote send FAILURE.'); } elseif (is_array($send_result)) { // Array so multipart. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'multipart'; pb_backupbuddy::$options['remote_sends'][$identifier]['finish_time'] = 0; pb_backupbuddy::$options['remote_sends'][$identifier]['_multipart_id'] = $send_result[0]; pb_backupbuddy::$options['remote_sends'][$identifier]['_multipart_status'] = $send_result[1]; pb_backupbuddy::status('details', 'Multipart send in progress.'); } else { pb_backupbuddy::status('error', 'Error #5485785576463. Invalid status send result: `' . $send_result . '`.'); } pb_backupbuddy::save(); // If we sent importbuddy then delete the local copy to clean up. if ($send_importbuddy !== false) { @unlink($importbuddy_temp); // Delete temporary importbuddy. } return $send_result; }
public static function test($settings) { if ($settings['address'] == '' || $settings['username'] == '' || $settings['password'] == '') { return __('Missing required input.', 'it-l10n-backupbuddy'); } // Try sending a file. $send_response = pb_backupbuddy_destinations::send($settings, dirname(dirname(__FILE__)) . '/remote-send-test.php', $send_id = 'TEST-' . pb_backupbuddy::random_string(12)); // 3rd param true forces clearing of any current uploads. if (false === $send_response) { $send_response = 'Error sending test file to FTP.'; } else { $send_response = 'Success.'; } // Now we will need to go and cleanup this potentially uploaded file. $delete_response = 'Error deleting test file from FTP.'; // Default. // Settings. $server = $settings['address']; $username = $settings['username']; $password = $settings['password']; $path = $settings['path']; $ftps = $settings['ftps']; if ($settings['active_mode'] == '0') { $active_mode = false; } else { $active_mode = true; } $url = $settings['url']; // optional url for using with migration. $port = '21'; if (strstr($server, ':')) { $server_params = explode(':', $server); $server = $server_params[0]; $port = $server_params[1]; } // Connect. if ($ftps == '0') { $conn_id = @ftp_connect($server, $port, 10); // timeout of 10 seconds. if ($conn_id === false) { $error = __('Unable to connect to FTP address `' . $server . '` on port `' . $port . '`.', 'it-l10n-backupbuddy'); $error .= "\n" . __('Verify the server address and port (default 21). Verify your host allows outgoing FTP connections.', 'it-l10n-backupbuddy'); return $send_response . ' ' . $error; } } else { if (function_exists('ftp_ssl_connect')) { $conn_id = @ftp_ssl_connect($server, $port); if ($conn_id === false) { return $send_response . ' ' . __('Destination server does not support FTPS?', 'it-l10n-backupbuddy'); } } else { return $send_response . ' ' . __('Your web server doesnt support FTPS.', 'it-l10n-backupbuddy'); } } $login_result = @ftp_login($conn_id, $username, $password); if (!$conn_id || !$login_result) { pb_backupbuddy::status('details', 'FTP test: Invalid user/pass.'); $response = __('Unable to login. Bad user/pass.', 'it-l10n-backupbuddy'); if ($ftps != '0') { $response .= "\n\nNote: You have FTPs enabled. You may get this error if your host does not support encryption at this address/port."; } return $send_response . ' ' . $response; } pb_backupbuddy::status('details', 'FTP test: Success logging in.'); // Handle active/pasive mode. if ($active_mode === true) { // do nothing, active is default. pb_backupbuddy::status('details', 'Active FTP mode based on settings.'); } elseif ($active_mode === false) { // Turn passive mode on. pb_backupbuddy::status('details', 'Passive FTP mode based on settings.'); ftp_pasv($conn_id, true); } else { pb_backupbuddy::status('error', 'Unknown FTP active/passive mode: `' . $active_mode . '`.'); } // Delete test file. pb_backupbuddy::status('details', 'FTP test: Deleting temp test file.'); if (true === ftp_delete($conn_id, $path . '/remote-send-test.php')) { $delete_response = 'Success.'; } // Close FTP connection. pb_backupbuddy::status('details', 'FTP test: Closing FTP connection.'); @ftp_close($conn_id); // Load destination fileoptions. pb_backupbuddy::status('details', 'About to load fileoptions data.'); require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php'; pb_backupbuddy::status('details', 'Fileoptions instance #12.'); $fileoptions_obj = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $send_id . '.txt', $read_only = false, $ignore_lock = false, $create_file = false); if (true !== ($result = $fileoptions_obj->is_ok())) { pb_backupbuddy::status('error', __('Fatal Error #9034.72373. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result); return false; } pb_backupbuddy::status('details', 'Fileoptions data loaded.'); $fileoptions =& $fileoptions_obj->options; if ('Success.' != $send_response || 'Success.' != $delete_response) { $fileoptions['status'] = 'failure'; $fileoptions_obj->save(); unset($fileoptions_obj); return 'Send details: `' . $send_response . '`. Delete details: `' . $delete_response . '`.'; } else { $fileoptions['status'] = 'success'; $fileoptions['finish_time'] = time(); } $fileoptions_obj->save(); unset($fileoptions_obj); return true; }
function process_backup($serial, $trigger = 'manual') { pb_backupbuddy::status('details', 'Running process_backup() for serial `' . $serial . '`.'); // Assign reference to backup data structure for this backup. $this->_backup =& pb_backupbuddy::$options['backups'][$serial]; $found_next_step = false; foreach ($this->_backup['steps'] as &$step) { // Loop through steps finding first step that has not run. if ($step['start_time'] != 0 && $step['finish_time'] == 0) { // A step has begun but has not finished. This should not happen but the WP cron is funky. Wait a while before continuing. $step['attempts']++; // Increment this as an attempt. pb_backupbuddy::save(); if ($step['attempts'] < 6) { $wait_time = 60 * $step['attempts']; // Each attempt adds a minute of wait time. pb_backupbuddy::status('message', 'A scheduled step attempted to run before the previous step completed. Waiting `' . $wait_time . '` seconds before continuining for it to catch up. Attempt number `' . $step['attempts'] . '`.'); $this->cron_next_step(false, $wait_time); return false; } else { // Too many attempts to run this step. pb_backupbuddy::status('error', 'A scheduled step attempted to run before the previous step completed. After several attempts (`' . $step['attempts'] . '`) of failure BackupBuddy has given up. Halting backup.'); return false; } break; } elseif ($step['start_time'] == 0) { // Step that has not started yet. $found_next_step = true; $step['start_time'] = time(); // Set this step time to now. $step['attempts']++; // Increment this as an attempt. pb_backupbuddy::save(); pb_backupbuddy::status('details', 'Found next step to run: `' . $step['function'] . '`.'); break; } else { // Last case: Finished. Skip. // Do nothing for completed steps. } } // End foreach(). if ($found_next_step === false) { // No more steps to perform; return. return false; } pb_backupbuddy::save(); pb_backupbuddy::status('details', __('Peak memory usage', 'it-l10n-backupbuddy') . ': ' . round(memory_get_peak_usage() / 1048576, 3) . ' MB'); /********* Begin Running Step Function **********/ if (method_exists($this, $step['function'])) { pb_backupbuddy::status('details', 'Starting function `' . $step['function'] . '` now (' . time() . ').'); $response = call_user_func_array(array(&$this, $step['function']), $step['args']); } else { pb_backupbuddy::status('error', __('Error #82783745: Invalid function `' . $step['function'] . '`')); $response = false; } /********* End Running Step Function **********/ if ($response === false) { // Function finished but reported failure. pb_backupbuddy::status('error', 'Failed function `' . $step['function'] . '`. Backup terminated.'); pb_backupbuddy::status('details', __('Peak memory usage', 'it-l10n-backupbuddy') . ': ' . round(memory_get_peak_usage() / 1048576, 3) . ' MB'); pb_backupbuddy::status('action', 'halt_script'); // Halt JS on page. if (pb_backupbuddy::$options['log_level'] == '3') { $debugging = "\n\n\n\n\n\nDebugging information sent due to error logging set to high debugging mode: \n\n" . pb_backupbuddy::random_string(10) . base64_encode(print_r(debug_backtrace(), true)) . "\n\n"; } else { $debugging = ''; } pb_backupbuddy::$classes['core']->mail_error('One or more backup steps reported a failure. Backup failure running function `' . $step['function'] . '` with the arguments `' . implode(',', $step['args']) . '` with backup serial `' . $serial . '`. Please run a manual backup of the same type to verify backups are working properly.' . $debugging); return false; } else { // Function finished successfully. $step['finish_time'] = time(); $this->_backup['updated_time'] = time(); pb_backupbuddy::save(); pb_backupbuddy::status('details', sprintf(__('Finished function `%s`.', 'it-l10n-backupbuddy'), $step['function'])); pb_backupbuddy::status('details', __('Peak memory usage', 'it-l10n-backupbuddy') . ': ' . round(memory_get_peak_usage() / 1048576, 3) . ' MB'); $found_another_step = false; foreach ($this->_backup['steps'] as $next_step) { // Loop through each step and see if any have not started yet. if ($next_step['start_time'] == 0) { // Another unstarted step exists. Schedule it. $found_another_step = true; if (pb_backupbuddy::$options['backup_mode'] == '2' || $trigger == 'scheduled') { $this->cron_next_step(); } else { // classic mode $this->process_backup($this->_backup['serial'], $trigger); } break; } } // End foreach(). if ($found_another_step == false) { pb_backupbuddy::status('details', 'Finished backup at ' . pb_backupbuddy::$format->date(time()) . ' (' . time() . ').'); $this->_backup['finish_time'] = time(); pb_backupbuddy::save(); } return true; } }
public static function send_remote_destination($destination_id, $file, $trigger = '', $send_importbuddy = false, $delete_after = false, $identifier = '', $destination_settings = '') { if (defined('PB_DEMO_MODE')) { return false; } if (!file_exists($file)) { pb_backupbuddy::status('error', 'Error #8583489734: Unable to send file `' . $file . '` to remote destination as it no longer exists. It may have been deleted or permissions are invalid.'); return false; } $migrationkey_transient_time = 60 * 60 * 24; if ('' == $file) { $backup_file_size = 50000; // not sure why anything current would be sending importbuddy but NOT sending a backup but just in case... } else { $backup_file_size = filesize($file); } // Generate remote send ID for reference and add it as a new logging serial for better recording details. if ('' == $identifier) { $identifier = pb_backupbuddy::random_string(12); } // Set migration key for later determining last initiated migration. if ('migration' == $trigger) { set_transient('pb_backupbuddy_migrationkey', $identifier, $migrationkey_transient_time); } pb_backupbuddy::status('details', 'Sending file `' . $file . '` to remote destination `' . $destination_id . '` triggered by `' . $trigger . '`.'); //pb_backupbuddy::status( 'details', 'About to create initial fileoptions data.' ); require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php'; pb_backupbuddy::status('details', 'Fileoptions instance #35.'); $fileoptions_obj = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $identifier . '.txt', $read_only = false, $ignore_lock = true, $create_file = true); if (true !== ($result = $fileoptions_obj->is_ok())) { pb_backupbuddy::status('error', __('Fatal Error #9034 A. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result); return false; } //pb_backupbuddy::status( 'details', 'Fileoptions data loaded.' ); $fileoptions =& $fileoptions_obj->options; // Set reference. // Record some statistics. $fileoptions = array_merge(self::get_remote_send_defaults(), array('destination' => $destination_id, 'file' => $file, 'file_size' => $backup_file_size, 'trigger' => $trigger, 'send_importbuddy' => $send_importbuddy, 'start_time' => time(), 'finish_time' => 0, 'status' => 'timeout', 'write_speed' => 0)); pb_backupbuddy::save(); // Prepare variables to pass to remote destination handler. if ('' == $file) { // No file to send (blank string file typically happens when just sending importbuddy). $files = array(); } else { $files = array($file); } // Destination settings were not passed so get them based on the destination ID provided. if (!is_array($destination_settings)) { $destination_settings =& pb_backupbuddy::$options['remote_destinations'][$destination_id]; } // For Stash we will check the quota prior to initiating send. if (pb_backupbuddy::$options['remote_destinations'][$destination_id]['type'] == 'stash') { // Pass off to destination handler. require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php'; $send_result = pb_backupbuddy_destinations::get_info('stash'); // Used to kick the Stash destination into life. $stash_quota = pb_backupbuddy_destination_stash::get_quota(pb_backupbuddy::$options['remote_destinations'][$destination_id], true); if ($file != '') { $backup_file_size = filesize($file); } else { $backup_file_size = 50000; } if ($backup_file_size + $stash_quota['quota_used'] > $stash_quota['quota_total']) { $message = ''; $message .= "You do not have enough Stash storage space to send this file. Please upgrade your Stash storage at http://ithemes.com/member/panel/stash.php or delete files to make space.\n\n"; $message .= 'Attempting to send file of size ' . pb_backupbuddy::$format->file_size($backup_file_size) . ' but you only have ' . $stash_quota['quota_available_nice'] . ' available. '; $message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).'; pb_backupbuddy::status('error', $message); backupbuddy_core::mail_error($message); $fileoptions['status'] = 'Failure. Insufficient destination space.'; $fileoptions_obj->save(); return false; } else { if (isset($stash_quota['quota_warning']) && $stash_quota['quota_warning'] != '') { // We log warning of usage but dont send error email. $message = ''; $message .= 'WARNING: ' . $stash_quota['quota_warning'] . "\n\nPlease upgrade your Stash storage at http://ithemes.com/member/panel/stash.php or delete files to make space.\n\n"; $message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).'; pb_backupbuddy::status('details', $message); //backupbuddy_core::mail_error( $message ); } } } if ($send_importbuddy === true) { pb_backupbuddy::status('details', 'Generating temporary importbuddy.php file for remote send.'); pb_backupbuddy::anti_directory_browsing(backupbuddy_core::getTempDirectory(), $die = false); $importbuddy_temp = backupbuddy_core::getTempDirectory() . 'importbuddy.php'; // Full path & filename to temporary importbuddy self::importbuddy($importbuddy_temp); // Create temporary importbuddy. pb_backupbuddy::status('details', 'Generated temporary importbuddy.'); $files[] = $importbuddy_temp; // Add importbuddy file to the list of files to send. $send_importbuddy = true; // Track to delete after finished. } else { pb_backupbuddy::status('details', 'Not sending importbuddy.'); } // Clear fileoptions so other stuff can access it if needed. $fileoptions_obj->save(); $fileoptions_obj->unlock(); unset($fileoptions_obj); // Pass off to destination handler. require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php'; $send_result = pb_backupbuddy_destinations::send($destination_settings, $files, $identifier, $delete_after); self::kick_db(); // Kick the database to make sure it didn't go away, preventing options saving. // Reload fileoptions. pb_backupbuddy::status('details', 'About to load fileoptions data for saving send status.'); require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php'; pb_backupbuddy::status('details', 'Fileoptions instance #34.'); $fileoptions_obj = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $identifier . '.txt', $read_only = false, $ignore_lock = false, $create_file = false); if (true !== ($result = $fileoptions_obj->is_ok())) { pb_backupbuddy::status('error', __('Fatal Error #9034 G. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result); return false; } pb_backupbuddy::status('details', 'Fileoptions data loaded.'); $fileoptions =& $fileoptions_obj->options; // Set reference. // Update stats. $fileoptions[$identifier]['finish_time'] = time(); if ($send_result === true) { // succeeded. $fileoptions['status'] = 'success'; $fileoptions['finish_time'] = time(); pb_backupbuddy::status('details', 'Remote send SUCCESS.'); } elseif ($send_result === false) { // failed. $fileoptions['status'] = 'failure'; pb_backupbuddy::status('details', 'Remote send FAILURE.'); } elseif (is_array($send_result)) { // Array so multipart. $fileoptions['status'] = 'multipart'; $fileoptions['finish_time'] = 0; $fileoptions['_multipart_id'] = $send_result[0]; $fileoptions['_multipart_status'] = $send_result[1]; pb_backupbuddy::status('details', 'Multipart send in progress.'); } else { pb_backupbuddy::status('error', 'Error #5485785576463. Invalid status send result: `' . $send_result . '`.'); } $fileoptions_obj->save(); // If we sent importbuddy then delete the local copy to clean up. if ($send_importbuddy !== false) { @unlink($importbuddy_temp); // Delete temporary importbuddy. } // As of v5.0: Post-send deletion now handled within destinations/bootstrap.php send() to support chunked sends. return $send_result; }
public static function test($settings) { $settings = self::_normalizeSettings($settings); if (false === ($settings = self::_connect($settings))) { $error = 'Unable to connect with Google Drive. See log for details.'; echo $error; pb_backupbuddy::status('error', $error); return false; } pb_backupbuddy::status('details', 'Testing Google Drive destination. Sending ImportBuddy.php.'); pb_backupbuddy::anti_directory_browsing(backupbuddy_core::getTempDirectory(), $die = false); $importbuddy_temp = backupbuddy_core::getTempDirectory() . 'importbuddy_' . pb_backupbuddy::random_string(10) . '.php.tmp'; // Full path & filename to temporary importbuddy backupbuddy_core::importbuddy($importbuddy_temp); // Create temporary importbuddy. $files = array($importbuddy_temp); $results = self::send($settings, $files, '', $delete_remote_after = true); @unlink($importbuddy_temp); if (true === $results) { echo 'Success sending test file to Google Drive. '; return true; } else { global $pb_backupbuddy_destination_errors; echo 'Failure sending test file to Google Drive. Details: `' . implode(', ', $pb_backupbuddy_destination_errors) . '`.'; return false; } }
if ('stash' == $destination['type']) { if ('0' == $destination['disable_file_management']) { $stashDestination = $destination_id; break; } else { pb_backupbuddy::alert('A Stash destination was found but deployment functionality has been disabled for it. It is not available for deployment features.'); } } } $deployments = array(array('siteurl' => 'http://destsite.com/', 'destination' => 0, 'importSettings' => array())); if ('' != pb_backupbuddy::_GET('deploy')) { if (!wp_verify_nonce(pb_backupbuddy::_GET('_wpnonce'), 'backupbuddy_deploy_toggle')) { die('Access Denied. Invalid NONCE.'); } if ('enable' == pb_backupbuddy::_GET('deploy')) { $identifier = pb_backupbuddy::random_string(12); $deployFile = backupbuddy_core::getTempDirectory() . 'deploy-' . backupbuddy_core::backup_prefix() . '.dat'; // . '-' . $identifier . $meta = array('siteurl' => site_url(), 'deployEnabled' => time()); $deployFileContents = json_encode($meta); pb_backupbuddy::anti_directory_browsing(backupbuddy_core::getTempDirectory(), $die = false); if (false === file_put_contents($deployFile, $deployFileContents)) { pb_backupbuddy::alert('Error #848383: Unable to write temporary deployment file `' . $deployFile . '`. Verify permissions on the directory.'); } else { $destinationSettings = pb_backupbuddy::$options['remote_destinations'][$stashDestination]; $destinationSettings['meta'] = $meta; $destinationSettings['forceRootUpload'] = true; require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php'; $send_result = pb_backupbuddy_destinations::send($destinationSettings, array($deployFile), $identifier, $delete_after = true); if (true === $send_result) { pb_backupbuddy::$options['deployment_allowed'] = '1';
public static function test($settings, $files = array()) { $path = rtrim($settings['path'], '/\\'); $url = rtrim($settings['url'], '/\\'); if (!file_exists($path)) { pb_backupbuddy::$filesystem->mkdir($path); } if (is_writable($path) !== true) { return __('Failure', 'it-l10n-backupbuddy') . '; The path does not allow writing. Please verify write file permissions.'; } if ($url != '') { $test_filename = 'migrate_test_' . pb_backupbuddy::random_string(10) . '.php'; $test_file_path = $path . '/' . $test_filename; $test_file_url = $url . '/' . $test_filename; // Make file. file_put_contents($test_file_path, "<?php die( '1' ); ?>"); pb_backupbuddy::status('details', 'Local test: Veryifing `' . $test_file_url . '` points to `' . $test_file_path . '`.'); // Test URL points to file. $response = wp_remote_get($test_file_url, array('method' => 'GET', 'timeout' => 45, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => null, 'cookies' => array())); unlink($test_file_path); if (is_wp_error($response)) { return __('Failure. Unable to connect to the provided URL.', 'it-l10n-backupbuddy'); } if (trim($response['body']) != '1') { return __('Failure. The path appears valid but the URL does not correspond to it. Leave the URL blank if not using this destination for migrations.', 'it-l10n-backupbuddy'); } } // Made it this far so success. return true; }
function send_remote_destination($destination_id, $file, $trigger = '', $send_importbuddy = false, $delete_after = false) { if (defined('PB_DEMO_MODE')) { return false; } if ('' == $file) { $backup_file_size = 50000; // not sure why anything current would be sending importbuddy but NOT sending a backup but just in case... } else { $backup_file_size = filesize($file); } pb_backupbuddy::status('details', 'Sending file `' . $file . '` (size: `' . $backup_file_size . '`) to remote destination `' . $destination_id . '` triggered by `' . $trigger . '`.'); // Record some statistics. $identifier = pb_backupbuddy::random_string(12); pb_backupbuddy::$options['remote_sends'][$identifier] = array('destination' => $destination_id, 'file' => $file, 'file_size' => $backup_file_size, 'trigger' => $trigger, 'send_importbuddy' => $send_importbuddy, 'start_time' => time(), 'finish_time' => 0, 'status' => 'timeout'); pb_backupbuddy::save(); // Prepare variables to pass to remote destination handler. if ('' == $file) { // No file to send (blank string file typically happens when just sending importbuddy). $files = array(); } else { $files = array($file); } $destination_settings =& pb_backupbuddy::$options['remote_destinations'][$destination_id]; // For Stash we will check the quota prior to initiating send. if (pb_backupbuddy::$options['remote_destinations'][$destination_id]['type'] == 'stash') { // Pass off to destination handler. require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php'; $send_result = pb_backupbuddy_destinations::get_info('stash'); // Used to kick the Stash destination into life. $stash_quota = pb_backupbuddy_destination_stash::get_quota(pb_backupbuddy::$options['remote_destinations'][$destination_id], true); if ($file != '') { $backup_file_size = filesize($file); } else { $backup_file_size = 50000; } if ($backup_file_size + $stash_quota['quota_used'] > $stash_quota['quota_total']) { $message = ''; $message .= "You do not have enough Stash storage space to send this file. Please upgrade your Stash storage at http://ithemes.com/member/stash.php or delete files to make space.\n\n"; $message .= 'Attempting to send file of size ' . pb_backupbuddy::$format->file_size($backup_file_size) . ' but you only have ' . $stash_quota['quota_available_nice'] . ' available. '; $message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).'; pb_backupbuddy::status('error', $message); pb_backupbuddy::$classes['core']->mail_error($message); pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'Failure. Insufficient destination space.'; pb_backupbuddy::save(); return false; } else { if (isset($stash_quota['quota_warning']) && $stash_quota['quota_warning'] != '') { // We log warning of usage but dont send error email. $message = ''; $message .= 'WARNING: ' . $stash_quota['quota_warning'] . "\n\nPlease upgrade your Stash storage at http://ithemes.com/member/stash.php or delete files to make space.\n\n"; $message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).'; pb_backupbuddy::status('details', $message); //pb_backupbuddy::$classes['core']->mail_error( $message ); } } } if ($send_importbuddy === true) { pb_backupbuddy::status('details', 'Generating temporary importbuddy.php file for remote send.'); $importbuddy_temp = pb_backupbuddy::$options['temp_directory'] . 'importbuddy.php'; // Full path & filename to temporary importbuddy $this->importbuddy($importbuddy_temp); // Create temporary importbuddy. pb_backupbuddy::status('details', 'Generated temporary importbuddy.'); $files[] = $importbuddy_temp; // Add importbuddy file to the list of files to send. $send_importbuddy = true; // Track to delete after finished. } else { pb_backupbuddy::status('details', 'Not sending importbuddy.'); } // Pass off to destination handler. require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php'; $send_result = pb_backupbuddy_destinations::send($destination_settings, $files); $this->kick_db(); // Kick the database to make sure it didn't go away, preventing options saving. // Update stats. pb_backupbuddy::$options['remote_sends'][$identifier]['finish_time'] = time(); if ($send_result === true) { // succeeded. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'success'; pb_backupbuddy::status('details', 'Remote send SUCCESS.'); } elseif ($send_result === false) { // failed. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'failure'; pb_backupbuddy::status('details', 'Remote send FAILURE.'); } elseif (is_array($send_result)) { // Array so multipart. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'multipart'; pb_backupbuddy::$options['remote_sends'][$identifier]['finish_time'] = 0; pb_backupbuddy::$options['remote_sends'][$identifier]['_multipart_id'] = $send_result[0]; pb_backupbuddy::$options['remote_sends'][$identifier]['_multipart_status'] = $send_result[1]; pb_backupbuddy::status('details', 'Multipart send in progress.'); } else { pb_backupbuddy::status('error', 'Error #5485785576463. Invalid status send result: `' . $send_result . '`.'); } pb_backupbuddy::save(); // If we sent importbuddy then delete the local copy to clean up. if ($send_importbuddy !== false) { @unlink($importbuddy_temp); // Delete temporary importbuddy. } // Handle post-send deletion on success. pb_backupbuddy::status('details', 'Checking if local file should be deleted after remote send based on settings.'); if (true === $send_result) { // Success; only continue on bool true. false indicates failure, array chunking. if (true == $delete_after) { // Delete enabled so delete file. pb_backupbuddy::status('details', 'Local file should be deleted based on settings & success. Deleting local copy of file sent to destination.'); if (file_exists($file)) { $unlink_result = @unlink($file); if (true !== $unlink_result) { pb_backupbuddy::status('error', 'Unable to unlink local file `' . $file . '`.'); } } if (file_exists($file)) { // File still exists. pb_backupbuddy::status('details', __('Error. Unable to delete local file `' . $file . '` after send as set in settings.', 'it-l10n-backupbuddy')); $this->mail_error('BackupBuddy was unable to delete local file `' . $file . '` after successful remove transfer though post-remote send deletion is enabled. You may want to delete it manually. This can be caused by permission problems or improper server configuration.'); } else { // Deleted. pb_backupbuddy::status('details', __('Deleted local archive after successful remote destination send based on settings.', 'it-l10n-backupbuddy')); pb_backupbuddy::status('action', 'archive_deleted'); } } else { // Delete after disabled. pb_backupbuddy::status('details', 'Post-send local file deletion disabled so skipping.'); } } else { // Send failed or not complete (chunking). pb_backupbuddy::status('details', 'Remote send not completed so skipping post-send deletion check.'); } return $send_result; }
public static function test($settings) { $settings = self::_init($settings); $sendOK = false; $deleteOK = false; $send_id = 'TEST-' . pb_backupbuddy::random_string(12); // Try sending a file. if ('1' == $settings['stash_mode']) { // Stash mode. $settings['type'] = 'stash2'; } $send_response = pb_backupbuddy_destinations::send($settings, dirname(dirname(__FILE__)) . '/remote-send-test.php', $send_id); // 3rd param true forces clearing of any current uploads. if (true === $send_response) { $send_response = __('Success.', 'it-l10n-backupbuddy'); $sendOK = true; } else { global $pb_backupbuddy_destination_errors; $send_response = 'Error sending test file to S3 (v2). Details: `' . implode(', ', $pb_backupbuddy_destination_errors) . '`.'; } pb_backupbuddy::add_status_serial('remote_send-' . $send_id); // Delete sent file if it was sent. $delete_response = 'n/a'; if (true === $sendOK) { pb_backupbuddy::status('details', 'Preparing to delete sent test file.'); if ('1' == $settings['stash_mode']) { // Stash mode. if (true === ($delete_response = pb_backupbuddy_destination_stash2::deleteFile($settings, 'remote-send-test.php'))) { // success $delete_response = __('Success.', 'it-l10n-backupbuddy'); $deleteOK = true; } else { // error $error = 'Unable to delete Stash test file `remote-send-test.php`. Details: `' . $delete_response . '`.'; $delete_response = $error; $deleteOK = false; } } else { // S3 mode. if (true === ($delete_response = self::deleteFile($settings, 'remote-send-test.php'))) { $delete_response = __('Success.', 'it-l10n-backupbuddy'); $deleteOK = true; } else { $error = 'Unable to delete test file `remote-send-test.php`. Details: `' . $delete_response . '`.'; pb_backupbuddy::status('details', $error); $delete_response = $error; $deleteOK = false; } } } else { // end if $sendOK. pb_backupbuddy::status('details', 'Skipping test delete due to failed send.'); } // Load destination fileoptions. pb_backupbuddy::status('details', 'About to load fileoptions data.'); require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php'; pb_backupbuddy::status('details', 'Fileoptions instance #7.'); $fileoptions_obj = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $send_id . '.txt', $read_only = false, $ignore_lock = false, $create_file = false); if (true !== ($result = $fileoptions_obj->is_ok())) { return self::_error(__('Fatal Error #9034.84838. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result); } pb_backupbuddy::status('details', 'Fileoptions data loaded.'); $fileoptions =& $fileoptions_obj->options; if (true !== $sendOK || true !== $deleteOK) { $fileoptions['status'] = 'failure'; $fileoptions_obj->save(); unset($fileoptions_obj); return 'Send details: `' . $send_response . '`. Delete details: `' . $delete_response . '`.'; } else { $fileoptions['status'] = 'success'; $fileoptions['finish_time'] = time(); } $fileoptions_obj->save(); unset($fileoptions_obj); pb_backupbuddy::status('details', 'Finished test function.'); return true; }
function process_backup($serial, $trigger = 'manual') { pb_backupbuddy::status('details', 'Running process_backup() for serial `' . $serial . '`.'); // Assign reference to backup data structure for this backup. if (!isset($this->_backup_options) || pb_backupbuddy::$options['backup_mode'] != '1') { // Load fileoptions if it is not loaded yet OR if normal mode always load. pb_backupbuddy::status('details', 'About to load fileoptions data.'); $attempt_transient_prefix = 'pb_backupbuddy_lock_attempts-'; require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php'; $this->_backup_options = new pb_backupbuddy_fileoptions(pb_backupbuddy::$options['log_directory'] . 'fileoptions/' . $serial . '.txt'); if (true !== ($result = $this->_backup_options->is_ok())) { // Unable to access fileoptions. $attempt_delay_base = 5; // Base number of seconds to delay. Each subsequent attempt increases this delay by a multiple of the attempt number. $max_attempts = 5; // Max number of attempts to try to delay around a file lock. Delay increases each time. $this->_backup['serial'] = $serial; // Needs to be populated for use by cron schedule step. pb_backupbuddy::status('warning', __('Warning #9034 B. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Warning: ' . $result, $serial); // Track lock attempts in transient system. This is not vital & since locks may be having issues track this elsewhere. $lock_attempts = get_transient($attempt_transient_prefix . $serial); if (false === $lock_attempts) { $lock_attempts = 0; } $lock_attempts++; set_transient($attempt_transient_prefix . $serial, $lock_attempts, 60 * 60 * 24); // Increment lock attempts. Hold attempt count for 24 hours to help make sure we don't lose attempt count if very low site activity, etc. if ($lock_attempts > $max_attempts) { pb_backupbuddy::status('error', 'Backup halted. Maximum number of attempts made attempting to access locked fileoptions file. This may be caused by something causing backup steps to run out of order or file permission issues on the temporary directory holding the file `' . $fileoptions_file . '`. Verify correct permissions.', $serial); pb_backupbuddy::status('action', 'halt_script', $serial); // Halt JS on page. delete_transient($attempt_transient_prefix . $serial); return false; } $wait_time = $attempt_delay_base * $lock_attempts; pb_backupbuddy::status('message', 'A scheduled step attempted to run before the previous step completed. The previous step may have failed or two steps may be attempting to run simultaneously.', $serial); pb_backupbuddy::status('message', 'Waiting `' . $wait_time . '` seconds before continuing. Attempt #' . $lock_attempts . ' of ' . $max_attempts . ' max allowed before giving up.', $serial); $this->cron_next_step(false, $wait_time); return false; //pb_backupbuddy::status( 'action', 'halt_script' ); // Halt JS on page. //return false; } else { // Accessed fileoptions. Clear/reset any attempt count. delete_transient($attempt_transient_prefix . $serial); } pb_backupbuddy::status('details', 'Fileoptions data loaded.'); $this->_backup =& $this->_backup_options->options; } // Handle cancelled backups (stop button). if (true == get_transient('pb_backupbuddy_stop_backup-' . $serial)) { // Backup flagged for stoppage. Proceed directly to cleanup. pb_backupbuddy::status('message', 'Backup STOPPED. Post backup cleanup step has been scheduled to clean up any temporary files.'); foreach ($this->_backup['steps'] as $step_id => $step) { if ($step['function'] != 'post_backup') { if ($step['start_time'] == 0) { $this->_backup['steps'][$step_id]['start_time'] = -1; // Flag for skipping. } } else { // Post backup step. $this->_backup['steps'][$step_id]['args'] = array(true, true); // Run post_backup in fail mode & delete backup file. } } //pb_backupbuddy::save(); $this->_backup_options->save(); pb_backupbuddy::status('action', 'halt_script'); // Halt JS on page. } $found_next_step = false; foreach ((array) $this->_backup['steps'] as $step_index => $step) { // Loop through steps finding first step that has not run. //pb_backupbuddy::status( 'details', 'step: ' . $step['function'] . 'start: ' . $step['start_time'] ); if ($step['start_time'] != -1 && $step['start_time'] != 0 && $step['finish_time'] == 0) { // A step is not marked for skippage, has begun but has not finished. This should not happen but the WP cron is funky. Wait a while before continuing. $this->_backup['steps'][$step_index]['attempts']++; // Increment this as an attempt. $this->_backup_options->save(); if ($step['attempts'] < 6) { $wait_time = 60 * $step['attempts']; // Each attempt adds a minute of wait time. pb_backupbuddy::status('message', 'A scheduled step attempted to run before the previous step completed. Waiting `' . $wait_time . '` seconds before continuing for it to catch up. Attempt number `' . $step['attempts'] . '`.'); $this->cron_next_step(false, $wait_time); return false; } else { // Too many attempts to run this step. pb_backupbuddy::status('error', 'A scheduled step attempted to run before the previous step completed. After several attempts (`' . $step['attempts'] . '`) of failure BackupBuddy has given up. Halting backup.'); return false; } break; } elseif ($step['start_time'] == 0) { // Step that is not marked for skippage and has not started yet. $found_next_step = true; $this->_backup['steps'][$step_index]['start_time'] = time(); // Set this step time to now. $this->_backup['steps'][$step_index]['attempts']++; // Increment this as an attempt. $this->_backup_options->save(); pb_backupbuddy::status('details', 'Found next step to run: `' . $step['function'] . '`.'); break; // Break out of foreach loop to continue. } elseif ($step['start_time'] == -1) { // Step flagged for skipping. Do not run. pb_backupbuddy::status('details', 'Step `' . $step['function'] . '` flagged for skipping. Skipping.'); } else { // Last case: Finished. Skip. // Do nothing for completed steps. //pb_backupbuddy::status( 'details', 'Step `' . $step['function'] . '` doing nothing with start `' . $step['start_time'] . '`.' ); } } // End foreach(). if ($found_next_step === false) { // No more steps to perform; return. pb_backupbuddy::status('details', 'No more steps found.'); return false; } //pb_backupbuddy::save(); pb_backupbuddy::status('details', __('Peak memory usage', 'it-l10n-backupbuddy') . ': ' . round(memory_get_peak_usage() / 1048576, 3) . ' MB'); /********* Begin Running Step Function **********/ if (method_exists($this, $step['function'])) { $args = ''; foreach ($step['args'] as $arg) { if (is_array($arg)) { $args .= '{' . implode(',', $arg) . '},'; } else { $args .= implode(',', $step['args']) . ','; } } pb_backupbuddy::status('details', '-----'); pb_backupbuddy::status('details', 'Starting step function `' . $step['function'] . '` with args `' . $args . '`. Attempt #' . ($step['attempts'] + 1) . '.'); // attempts 0-indexed. $response = call_user_func_array(array(&$this, $step['function']), $step['args']); } else { pb_backupbuddy::status('error', __('Error #82783745: Invalid function `' . $step['function'] . '`')); $response = false; } /********* End Running Step Function **********/ //unset( $step ); if ($response === false) { // Function finished but reported failure. // Failure caused by backup cancellation. if (true == get_transient('pb_backupbuddy_stop_backup-' . $serial)) { pb_backupbuddy::status('action', 'halt_script'); // Halt JS on page. return false; } pb_backupbuddy::status('error', 'Failed function `' . $this->_backup['steps'][$step_index]['function'] . '`. Backup terminated.'); pb_backupbuddy::status('details', __('Peak memory usage', 'it-l10n-backupbuddy') . ': ' . round(memory_get_peak_usage() / 1048576, 3) . ' MB'); pb_backupbuddy::status('action', 'halt_script'); // Halt JS on page. if (pb_backupbuddy::$options['log_level'] == '3') { $debugging = "\n\n\n\n\n\nDebugging information sent due to error logging set to high debugging mode: \n\n" . pb_backupbuddy::random_string(10) . base64_encode(print_r(debug_backtrace(), true)) . "\n\n"; } else { $debugging = ''; } pb_backupbuddy::$classes['core']->mail_error('One or more backup steps reported a failure. Backup failure running function `' . $this->_backup['steps'][$step_index]['function'] . '` with the arguments `' . implode(',', $this->_backup['steps'][$step_index]['args']) . '` with backup serial `' . $serial . '`. Please run a manual backup of the same type to verify backups are working properly.' . $debugging); return false; } else { // Function finished successfully. $this->_backup['steps'][$step_index]['finish_time'] = time(); $this->_backup['updated_time'] = time(); $this->_backup_options->save(); pb_backupbuddy::status('details', sprintf(__('Finished function `%s`. Peak memory usage', 'it-l10n-backupbuddy') . ': ' . round(memory_get_peak_usage() / 1048576, 3) . ' MB', $this->_backup['steps'][$step_index]['function'])); pb_backupbuddy::status('details', '-----'); $found_another_step = false; foreach ($this->_backup['steps'] as $next_step) { // Loop through each step and see if any have not started yet. if ($next_step['start_time'] == 0) { // Another unstarted step exists. Schedule it. $found_another_step = true; if (pb_backupbuddy::$options['backup_mode'] == '2' || $trigger == 'scheduled') { $this->cron_next_step(); } else { // classic mode $this->process_backup($this->_backup['serial'], $trigger); } break; } } // End foreach(). if ($found_another_step == false) { pb_backupbuddy::status('details', __('No more backup steps remain. Finishing...', 'it-l10n-backupbuddy')); $this->_backup['finish_time'] = time(); $this->_backup_options->save(); } else { pb_backupbuddy::status('details', 'Completed step function `' . $step['function'] . '`.'); pb_backupbuddy::status('details', 'The next should run in a moment. If it does not please check for plugin conflicts and that the next step is scheduled in the cron on the Server Information page.'); } return true; } }
function start_backup_process($profile, $trigger = 'manual', $pre_backup = array(), $post_backup = array(), $schedule_title = '', $serial_override = '', $export_plugins = array(), $deployDirection = '', $deployDestinationSettings = '') { // Load profile defaults. $profile = array_merge(pb_backupbuddy::settings('profile_defaults'), $profile); foreach ($profile as $profile_item_name => &$profile_item) { // replace non-overridden defaults with actual default value. if ('-1' == $profile_item) { // Set to use default so go grab default. if (isset(pb_backupbuddy::$options['profiles'][0][$profile_item_name])) { $profile_item = pb_backupbuddy::$options['profiles'][0][$profile_item_name]; // Grab value from defaults profile and replace with it. } } } // Handle backup mode. $backup_mode = pb_backupbuddy::$options['backup_mode']; // Load global default mode. if ('1' == $profile['backup_mode']) { // Profile forces classic. $backup_mode = '1'; } elseif ('2' == $profile['backup_mode']) { // Profiles forces modern. $backup_mode = '2'; } $profile['backup_mode'] = $backup_mode; unset($backup_mode); // If classic mode then we need to redirect output to displaying inline via JS instead of AJAX-based. if ('1' == $profile['backup_mode']) { //global $pb_backupbuddy_js_status; //$pb_backupbuddy_js_status = true; } if ($serial_override != '') { $serial = $serial_override; } else { $serial = pb_backupbuddy::random_string(10); } pb_backupbuddy::set_status_serial($serial); // Default logging serial. global $wp_version; pb_backupbuddy::status('details', 'BackupBuddy v' . pb_backupbuddy::settings('version') . ' using WordPress v' . $wp_version . ' on ' . PHP_OS . '.'); //pb_backupbuddy::status( 'details', __('Peak memory usage', 'it-l10n-backupbuddy' ) . ': ' . round( memory_get_peak_usage() / 1048576, 3 ) . ' MB' ); $type = $profile['type']; $archiveFile = $this->calculateArchiveFilename($serial, $type); //if ( 'pull' != $deployDirection ) { 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; } /* } 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; } */ 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') { // Modern mode with crons. pb_backupbuddy::status('message', 'Running in modern backup mode based on settings. Mode value: `' . $profile['backup_mode'] . '`. Trigger: `' . $trigger . '`.'); unset($this->_backup_options); // 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. if ($trigger != 'manual' || defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) { $this->cron_next_step(false); } else { //$this->cron_next_step( true ); $this->cron_next_step(false); // as of Aug 9, 2013 no longer spawn the cron. Caused very odd issue of double code runs. } } else { // Classic mode; everything runs in this single PHP page load. pb_backupbuddy::status('message', 'Running in classic backup mode based on settings.'); $this->process_backup($this->_backup['serial'], $trigger); } return true; }
function process_ftp_copy($backup, $ftp_server, $ftp_username, $ftp_password, $ftp_directory) { pb_backupbuddy::set_greedy_script_limits(); // connect to server $conn_id = ftp_connect($ftp_server) or die('Could not connect to ' . $ftp_server); // login with username and password $login_result = ftp_login($conn_id, $ftp_username, $ftp_password); // try to download $server_file and save to $local_file $destination_file = ABSPATH . 'wp-content/uploads/backupbuddy_backups/' . $backup; if (file_exists($destination_file)) { $destination_file = str_replace('backup-', 'backup_copy_' . pb_backupbuddy::random_string(5) . '-', $destination_file); } if (ftp_get($conn_id, $destination_file, $ftp_directory . $backup, FTP_BINARY)) { pb_backupbuddy::status('message', 'Successfully wrote remote file locally to `' . $destination_file . '`.'); } else { pb_backupbuddy::status('error', 'Error writing remote file locally to `' . $destination_file . '`.'); } // close this connection ftp_close($conn_id); }
$errorMsg = 'Error #894383: Unknown error starting restore. See advanced status log for details.'; } pb_backupbuddy::alert($errorMsg); return; } $restore->_state['defaultURL'] = $restore->getDefaultUrl(); $restore->_state['defaultDomain'] = $restore->getDefaultDomain(); if ('true' != pb_backupbuddy::_GET('deploy')) { // deployment mode pre-loads state data in a file instead of passing via post. $restore->_state = parse_options($restore->_state); } $restore->_state['skipUnzip'] = $skipUnzip; // Set up state variables. if ('db' == $restore->_state['dat']['backup_type'] || false == $restore->_state['restoreFiles']) { pb_backupbuddy::status('details', 'Database backup OR not restoring files.'); $restore->_state['tempPath'] = ABSPATH . 'importbuddy/temp_' . pb_backupbuddy::random_string(12) . '/'; $restore->_state['restoreFileRoot'] = $restore->_state['tempPath']; pb_backupbuddy::anti_directory_browsing($restore->_state['restoreFileRoot'], $die = false); } else { pb_backupbuddy::status('details', 'Restoring files.'); $restore->_state['restoreFileRoot'] = ABSPATH; // Restore files into current root. } // Parse submitted options for saving to state. function parse_options($restoreData) { if ('1' == pb_backupbuddy::_POST('restoreFiles')) { $restoreData['restoreFiles'] = true; } else { $restoreData['restoreFiles'] = false; }
<?php //pb_backupbuddy::$filesystem->recursive_copy( //pb_backupbuddy::load_script( 'admin.js' ); // Thickbox used for remote send button for user after backup. wp_enqueue_script('thickbox'); wp_print_scripts('thickbox'); wp_print_styles('thickbox'); require_once pb_backupbuddy::plugin_path() . '/classes/backup.php'; pb_backupbuddy::$classes['backup'] = new pb_backupbuddy_backup(); // Set serial ahead of time so can be used by AJAX before backup procedure actually begins. $serial_override = pb_backupbuddy::random_string(10); pb_backupbuddy::$ui->title('Create Backup'); if ('true' == pb_backupbuddy::_GET('quickstart_wizard')) { pb_backupbuddy::alert('Your Quick Setup Settings have been saved. Now performing your first backup...'); } ?> <script type="text/javascript"> var messages_output = ''; jQuery(document).ready(function() { // Wait 0 seconds before first poll. setTimeout( 'backupbuddy_poll()' , 0 ); // was: 1000 setInterval( 'blink_ledz()' , 400 ); jQuery( '.pb_backupbuddy_hoveraction_send' ).click( function(e) { tb_show( 'BackupBuddy', '<?php echo pb_backupbuddy::ajax_url('destination_picker');
public static function deploymentImportBuddy($password, $backupFile, $additionalStateInfo = '') { if (!file_exists($backupFile)) { $error = 'Error #43848378: Backup file `' . $backupFile . '` not found uploaded.'; pb_backupbuddy::status('error', $error); return array(false, $error); } $backupSerial = backupbuddy_core::get_serial_from_file($backupFile); $importFileSerial = pb_backupbuddy::random_string(15); $importFilename = 'importbuddy-' . $importFileSerial . '.php'; backupbuddy_core::importbuddy(ABSPATH . $importFilename, $password); // Render default config file overrides. Overrrides default restore.php state data. $state = array(); global $wpdb; $state['type'] = 'deploy'; $state['archive'] = $backupFile; $state['siteurl'] = preg_replace('|/*$|', '', site_url()); // Strip trailing slashes. $state['homeurl'] = preg_replace('|/*$|', '', home_url()); // Strip trailing slashes. $state['restoreFiles'] = false; $state['migrateHtaccess'] = false; $state['remote_api'] = pb_backupbuddy::$options['remote_api']; // For use by importbuddy api auth. Enables remote api in this importbuddy. $state['databaseSettings']['server'] = DB_HOST; $state['databaseSettings']['database'] = DB_NAME; $state['databaseSettings']['username'] = DB_USER; $state['databaseSettings']['password'] = DB_PASSWORD; $state['databaseSettings']['prefix'] = $wpdb->prefix; $state['databaseSettings']['renamePrefix'] = true; $state['cleanup']['deleteImportBuddy'] = true; $state['cleanup']['deleteImportLog'] = true; if (is_array($additionalStateInfo)) { $state = array_merge($state, $additionalStateInfo); } // Write default state overrides. $state_file = ABSPATH . 'importbuddy-' . $importFileSerial . '-state.php'; if (false === ($file_handle = @fopen($state_file, 'w'))) { $error = 'Error #8384784: Temp state file is not creatable/writable. Check your permissions. (' . $state_file . ')'; pb_backupbuddy::status('error', $error); return array(false, $error); } fwrite($file_handle, "<?php die('Access Denied.'); // <!-- ?>\n" . base64_encode(serialize($state))); fclose($file_handle); $undoFile = 'backupbuddy_deploy_undo-' . $backupSerial . '.php'; //$undoURL = rtrim( site_url(), '/\\' ) . '/' . $undoFile; if (false === copy(pb_backupbuddy::plugin_path() . '/classes/_rollback_undo.php', ABSPATH . $undoFile)) { $error = 'Error #3289447: Unable to write undo file `' . ABSPATH . $undoFile . '`. Check permissions on directory.'; pb_backupbuddy::status('error', $error); return array(false, $error); } return $importFileSerial; }
function remote_send_email($email, $file, $send_importbuddy = false) { if (defined('PB_DEMO_MODE')) { return; } if ($send_importbuddy === true) { pb_backupbuddy::status('details', 'Sending importbuddy to Email based on settings.'); $importbuddy_temp = pb_backupbuddy::$options['temp_directory'] . 'importbuddy_' . pb_backupbuddy::random_string(10) . '.php.tmp'; // Full path & filename to temporary importbuddy $this->importbuddy($importbuddy_temp); // Create temporary importbuddy. if (is_array($file)) { // array $file[] = $importbuddy_temp; } else { // string $file = array($file, $importbuddy_temp); } } pb_backupbuddy::status('details', 'Sending remote email.'); $headers = 'From: BackupBuddy <' . get_option('admin_email') . '>' . "\r\n\\"; wp_mail($email, 'BackupBuddy Backup', 'BackupBuddy backup for ' . site_url(), $headers, $file); pb_backupbuddy::status('details', 'Sent remote email.'); if ($send_importbuddy === true) { @unlink($importbuddy_temp); // Delete temporary importbuddy. } }
function process_ftp_copy($backup, $ftp_server, $ftp_username, $ftp_password, $ftp_directory, $port = '21', $ftps = '0') { pb_backupbuddy::set_greedy_script_limits(); if (!class_exists('backupbuddy_core')) { require_once pb_backupbuddy::plugin_path() . '/classes/core.php'; } // Connect to server. if ($ftps == '1') { // Connect with FTPs. if (function_exists('ftp_ssl_connect')) { $conn_id = ftp_ssl_connect($ftp_server, $port); if ($conn_id === false) { pb_backupbuddy::status('details', 'Unable to connect to FTPS (check address/FTPS support).', 'error'); return false; } else { pb_backupbuddy::status('details', 'Connected to FTPs.'); } } else { pb_backupbuddy::status('details', 'Your web server doesnt support FTPS in PHP.', 'error'); return false; } } else { // Connect with FTP (normal). if (function_exists('ftp_connect')) { $conn_id = ftp_connect($ftp_server, $port); if ($conn_id === false) { pb_backupbuddy::status('details', 'ERROR: Unable to connect to FTP (check address).', 'error'); return false; } else { pb_backupbuddy::status('details', 'Connected to FTP.'); } } else { pb_backupbuddy::status('details', 'Your web server doesnt support FTP in PHP.', 'error'); return false; } } // login with username and password $login_result = ftp_login($conn_id, $ftp_username, $ftp_password); // try to download $server_file and save to $local_file $destination_file = backupbuddy_core::getBackupDirectory() . $backup; if (file_exists($destination_file)) { $destination_file = str_replace('backup-', 'backup_copy_' . pb_backupbuddy::random_string(5) . '-', $destination_file); } if (ftp_get($conn_id, $destination_file, $ftp_directory . $backup, FTP_BINARY)) { pb_backupbuddy::status('message', 'Successfully wrote remote file locally to `' . $destination_file . '`.'); } else { pb_backupbuddy::status('error', 'Error writing remote file locally to `' . $destination_file . '`.'); } // close this connection ftp_close($conn_id); }
// db profile is always index 1. $profile = '1'; } elseif ('full' == $profile) { // full profile is always index 2. $profile = '2'; } if (is_numeric($profile)) { if (isset(pb_backupbuddy::$options['profiles'][$profile])) { $profileArray = pb_backupbuddy::$options['profiles'][$profile]; } else { return 'Error #2332904: Invalid profile ID `' . htmlentities($profile) . '`. Profile with this number was not found. Try deactivating then reactivating the plugin. If this fails please reset the plugin Settings back to Defaults from the Settings page.'; } } else { return 'Error #85489548955. Invalid profile ID not numeric: `' . htmlentities($profile) . '`.'; } } if ('' == $triggerTitle) { $triggerTitle = 'BB API'; } $profileArray['backup_mode'] = $backupMode; // Force modern mode when running under API. 1=classic (single page load), 2=modern (cron) if ('' == $backupSerial) { $backupSerial = pb_backupbuddy::random_string(10); } require_once pb_backupbuddy::plugin_path() . '/classes/backup.php'; pb_backupbuddy::$classes['backup'] = new pb_backupbuddy_backup(); // Run the backup! if (pb_backupbuddy::$classes['backup']->start_backup_process($profileArray, 'manual', array(), array(), $triggerTitle, $backupSerial, array()) !== true) { return 'Error #435832: Backup failed. See BackupBuddy log for details.'; } return true;
public static function test($settings) { $remote_path = self::get_remote_path($settings['directory']); // Has leading and trailng slashes. $manage_data = pb_backupbuddy_destination_stash::get_manage_data($settings); if (!is_array($manage_data['credentials'])) { // Credentials were somehow faulty. User changed password after prior page? Unlikely but you never know... $error_msg = 'Error #8484383c: Your authentication credentials for Stash failed. Verify your login and password to Stash. You may need to update the Stash destination settings. Perhaps you recently changed your password?'; pb_backupbuddy::status('error', $error_msg); return $error_msg; } // Try sending a file. $send_response = pb_backupbuddy_destinations::send($settings, dirname(dirname(__FILE__)) . '/remote-send-test.php', $send_id = 'TEST-' . pb_backupbuddy::random_string(12)); // 3rd param true forces clearing of any current uploads. if (false === $send_response) { $send_response = 'Error sending test file to Stash.'; } else { $send_response = 'Success.'; } // S3 object for managing files. $credentials = pb_backupbuddy_destination_stash::get_manage_data($settings); $s3_manage = new AmazonS3($manage_data['credentials']); if ($settings['ssl'] == 0) { @$s3_manage->disable_ssl(true); } // Delete sent file. $delete_response = 'Success.'; $delete_response = $s3_manage->delete_object($manage_data['bucket'], $manage_data['subkey'] . $remote_path . 'remote-send-test.php'); if (!$delete_response->isOK()) { $delete_response = 'Unable to delete test Stash file `remote-send-test.php`. Details: `' . print_r($response, true) . '`.'; pb_backupbuddy::status('details', $delete_response); } else { $delete_response = 'Success.'; } // Load destination fileoptions. pb_backupbuddy::status('details', 'About to load fileoptions data.'); require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php'; $fileoptions_obj = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $send_id . '.txt', $read_only = false, $ignore_lock = false, $create_file = false); if (true !== ($result = $fileoptions_obj->is_ok())) { pb_backupbuddy::status('error', __('Fatal Error #9034.84838. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result); return false; } pb_backupbuddy::status('details', 'Fileoptions data loaded.'); $fileoptions =& $fileoptions_obj->options; if ('Success.' != $send_response || 'Success.' != $delete_response) { $fileoptions['status'] = 'failure'; $fileoptions_obj->save(); unset($fileoptions_obj); return 'Send details: `' . $send_response . '`. Delete details: `' . $delete_response . '`.'; } else { $fileoptions['status'] = 'success'; $fileoptions['finish_time'] = time(); } $fileoptions_obj->save(); unset($fileoptions_obj); return true; }
public static function test($settings) { if (class_exists('CFRuntime')) { die('CFRuntime already defined. Another plugin may be incorrectly loading its copy of S3 libraries on BackupBuddy pages.'); } require_once dirname(dirname(__FILE__)) . '/_s3lib/aws-sdk/sdk.class.php'; $remote_path = self::get_remote_path($settings['directory']); // Has leading and trailng slashes. $settings['bucket'] = strtolower($settings['bucket']); // Buckets must be lowercase. /* if ( FALSE !== strpos( $settings['bucket'], ' ' ) ) { $message = 'Bucket names cannot have spaces in them.'; return $message; } */ // Try sending a file. $send_response = pb_backupbuddy_destinations::send($settings, dirname(dirname(__FILE__)) . '/remote-send-test.php', $send_id = 'TEST-' . pb_backupbuddy::random_string(12)); // 3rd param true forces clearing of any current uploads. if (false === $send_response) { $send_response = 'Error sending test file to S3.'; } else { $send_response = 'Success.'; } // S3 object for managing files. $credentials = pb_backupbuddy_destination_s3::get_credentials($settings); $s3_manage = new AmazonS3($credentials); if ($settings['ssl'] == 0) { @$s3_manage->disable_ssl(true); } // Verify bucket exists; create if not. Also set region to the region bucket exists in. if (false === self::_prepareBucketAndRegion($s3_manage, $settings)) { return false; } // Delete sent file. $delete_response = 'Success.'; $delete_response = $s3_manage->delete_object($credentials['bucket'], $remote_path . 'remote-send-test.php'); if (!$delete_response->isOK()) { $delete_response = 'Unable to delete test S3 file `remote-send-test.php`.'; pb_backupbuddy::status('details', $delete_response . ' Details: `' . print_r($delete_response, true) . '`.'); } else { $delete_response = 'Success.'; } // Load destination fileoptions. pb_backupbuddy::status('details', 'About to load fileoptions data.'); require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php'; pb_backupbuddy::status('details', 'Fileoptions instance #7.'); $fileoptions_obj = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $send_id . '.txt', $read_only = false, $ignore_lock = false, $create_file = false); if (true !== ($result = $fileoptions_obj->is_ok())) { pb_backupbuddy::status('error', __('Fatal Error #9034.84838. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result); return false; } pb_backupbuddy::status('details', 'Fileoptions data loaded.'); $fileoptions =& $fileoptions_obj->options; if ('Success.' != $send_response || 'Success.' != $delete_response) { $fileoptions['status'] = 'failure'; $fileoptions_obj->save(); unset($fileoptions_obj); return 'Send details: `' . $send_response . '`. Delete details: `' . $delete_response . '`.'; } else { $fileoptions['status'] = 'success'; $fileoptions['finish_time'] = time(); } $fileoptions_obj->save(); unset($fileoptions_obj); return true; }