public function remote_send($destination_id, $backup_file, $trigger, $send_importbuddy = false) { pb_backupbuddy::set_greedy_script_limits(); pb_backupbuddy::status('message', 'Sending `' . $backup_file . '` to remote destination `' . $destination_id . '`. Importbuddy?: `' . $send_importbuddy . '`.'); if (!isset(pb_backupbuddy::$options)) { pb_backupbuddy::load(); } pb_backupbuddy::status('details', 'Launching remote send via cron.'); if (!isset(pb_backupbuddy::$classes['core'])) { require_once pb_backupbuddy::plugin_path() . '/classes/core.php'; pb_backupbuddy::$classes['core'] = new pb_backupbuddy_core(); } pb_backupbuddy::$classes['core']->send_remote_destination($destination_id, $backup_file, $trigger, $send_importbuddy); }
public function remote_send($destination_id, $backup_file, $trigger, $send_importbuddy = false, $delete_after = false) { pb_backupbuddy::set_greedy_script_limits(); if ('' == $backup_file && $send_importbuddy) { pb_backupbuddy::status('message', 'Only sending ImportBuddy to remote destination `' . $destination_id . '`.'); } else { pb_backupbuddy::status('message', 'Sending `' . $backup_file . '` to remote destination `' . $destination_id . '`. Importbuddy?: `' . $send_importbuddy . '`. Delete after?: `' . $delete_after . '`.'); } if (!isset(pb_backupbuddy::$options)) { pb_backupbuddy::load(); } if (!class_exists('backupbuddy_core')) { require_once pb_backupbuddy::plugin_path() . '/classes/core.php'; } backupbuddy_core::send_remote_destination($destination_id, $backup_file, $trigger, $send_importbuddy, $delete_after); }
public static function run_periodic($backup_age_limit = 172800, $die_on_fail = true) { if (is_multisite()) { // For Multisite only run on main Network site. if (!is_main_site()) { return; } } pb_backupbuddy::status('message', 'Starting periodic housekeeeping procedure for BackupBuddy v' . pb_backupbuddy::settings('version') . '.'); require_once pb_backupbuddy::plugin_path() . '/classes/core.php'; require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php'; if (!isset(pb_backupbuddy::$options)) { pb_backupbuddy::load(); } // Top priority. Security related or otherwise crucial to run first. self::no_recent_backup_reminder(); backupbuddy_core::verify_directories($skipTempGeneration = true); // Verify directory existance and anti-directory browsing is in place everywhere. self::check_high_security_mode($die_on_fail); self::remove_importbuddy_file(); self::remove_importbuddy_dir(); self::remove_rollback_files(); // Potential large file/dir cleanup. May bog down site. self::cleanup_temp_dir($backup_age_limit); self::remove_temp_zip_dirs($backup_age_limit); // Robustness -- handle re-processing timeouts, verifying schedules, etc. self::process_timed_out_backups(); self::process_timed_out_sends(); self::validate_bb_schedules_in_wp(); // More minor cleanup. self::remove_temp_tables(); self::remove_wp_schedules_with_no_bb_schedule(); self::trim_old_notifications(); self::trim_remote_send_stats(); self::s3_cancel_multipart_pieces(); self::s32_cancel_multipart_pieces(); self::cleanup_local_destination_temp(); self::purge_logs(); self::purge_large_logs(); self::clear_cron_send(); // PHP tests. self::schedule_php_runtime_tests(); self::schedule_php_memory_tests(); @clearstatcache(); // Clears file info stat cache. pb_backupbuddy::status('message', 'Finished periodic housekeeping cleanup procedure.'); }
public function backupbuddy() { $function = str_replace(array('/', '\\'), '', pb_backupbuddy::_GET('function')); if ('' == $function) { $function = str_replace(array('/', '\\'), '', pb_backupbuddy::_POST('function')); } $file = pb_backupbuddy::plugin_path() . '/controllers/ajax/' . $function . '.php'; if (!file_exists($file)) { die('0'); } pb_backupbuddy::load(); //pb_backupbuddy::$ui->ajax_header(); require_once 'ajax/' . $function . '.php'; //pb_backupbuddy::$ui->ajax_footer(); //die(); die; }
public function run($arguments) { $arguments = Ithemes_Sync_Functions::merge_defaults($arguments, $this->default_arguments); if ('' == $arguments['password']) { // no password send in arguments. if (!isset(pb_backupbuddy::$options)) { pb_backupbuddy::load(); } if ('' == pb_backupbuddy::$options['importbuddy_pass_hash']) { // no default password is set on Settings page. return array('api' => '0', 'status' => 'error', 'message' => 'No ImportBuddy password was entered and no default has been set on the Settings page.'); } else { // Use default. $importbuddy_pass_hash = pb_backupbuddy::$options['importbuddy_pass_hash']; } } else { // Password passed in arguments. $importbuddy_pass_hash = md5($arguments['password']); } require_once pb_backupbuddy::plugin_path() . '/classes/core.php'; return array('api' => '4', 'status' => 'ok', 'message' => 'ImportBuddy retrieved.', 'importbuddy' => base64_encode(backupbuddy_core::importbuddy('', $importbuddy_pass_hash, $returnNotEcho = true))); }
<?php // This code runs whenever in the wp-admin. /********** MISC **********/ pb_backupbuddy::load(); // Load backupbuddy class with helper functions. if ( !isset( pb_backupbuddy::$classes['core'] ) ) { require_once( pb_backupbuddy::plugin_path() . '/classes/core.php' ); pb_backupbuddy::$classes['core'] = new pb_backupbuddy_core(); } /********** Begin directory checking. **********/ // Keep backup directory up to date. if ( pb_backupbuddy::$options['backup_directory'] != ( ABSPATH . 'wp-content/uploads/backupbuddy_backups/' ) ) { pb_backupbuddy::status( 'details', 'Backup directory has changed. Updating from `' . pb_backupbuddy::$options['backup_directory'] . '` to `' . ABSPATH . 'wp-content/uploads/backupbuddy_backups/' . '`.' ); pb_backupbuddy::$options['backup_directory'] = ABSPATH . 'wp-content/uploads/backupbuddy_backups/'; pb_backupbuddy::save(); } // Make backup directory if it does not exist yet. //pb_backupbuddy::status( 'details', 'Verifying backup directory `' . pb_backupbuddy::$options['backup_directory'] . '` exists.' ); if ( !file_exists( pb_backupbuddy::$options['backup_directory'] ) ) { pb_backupbuddy::status( 'details', 'Backup directory does not exist. Attempting to create.' ); if ( pb_backupbuddy::$filesystem->mkdir( pb_backupbuddy::$options['backup_directory'] ) === false ) { pb_backupbuddy::status( 'error', sprintf( __('Unable to create backup storage directory (%s)', 'it-l10n-backupbuddy' ) , pb_backupbuddy::$options['backup_directory'] ) ); pb_backupbuddy::alert( sprintf( __('Unable to create backup storage directory (%s)', 'it-l10n-backupbuddy' ) , pb_backupbuddy::$options['backup_directory'] ), true, '9002' ); }
public function final_cleanup($serial) { if (!isset(pb_backupbuddy::$options)) { pb_backupbuddy::load(); } pb_backupbuddy::status('details', 'cron_final_cleanup started'); // Delete temporary data directory. if (isset(pb_backupbuddy::$options['backups'][$serial]['temp_directory']) && file_exists(pb_backupbuddy::$options['backups'][$serial]['temp_directory'])) { pb_backupbuddy::$filesystem->unlink_recursive(pb_backupbuddy::$options['backups'][$serial]['temp_directory']); } // Delete temporary zip directory. if (isset(pb_backupbuddy::$options['backups'][$serial]['temporary_zip_directory']) && file_exists(pb_backupbuddy::$options['backups'][$serial]['temporary_zip_directory'])) { pb_backupbuddy::$filesystem->unlink_recursive(pb_backupbuddy::$options['backups'][$serial]['temporary_zip_directory']); } // Delete status log text file. if (file_exists(pb_backupbuddy::$options['backup_directory'] . 'temp_status_' . $serial . '.txt')) { unlink(pb_backupbuddy::$options['backup_directory'] . 'temp_status_' . $serial . '.txt'); } }
public function importexport_settings() { pb_backupbuddy::load(); pb_backupbuddy::$ui->ajax_header(); if (pb_backupbuddy::_POST('import_settings') != '') { $import = trim(stripslashes(pb_backupbuddy::_POST('import_data'))); $import = base64_decode($import); if ($import === false) { // decode failed. pb_backupbuddy::alert('Unable to decode settings data. Import aborted. Insure that you fully copied the settings and did not change any of the text.'); } else { // decode success. if (($import = maybe_unserialize($import)) === false) { // unserialize fail. pb_backupbuddy::alert('Unable to unserialize settings data. Import aborted. Insure that you fully copied the settings and did not change any of the text.'); } else { // unserialize success. if (!isset($import['data_version'])) { // missing expected content. pb_backupbuddy::alert('Unserialized settings data but it did not contain expected data. Import aborted. Insure that you fully copied the settings and did not change any of the text.'); } else { // contains expected content. pb_backupbuddy::$options = $import; require_once pb_backupbuddy::plugin_path() . '/controllers/activation.php'; // Run data migration to upgrade if needed. pb_backupbuddy::save(); pb_backupbuddy::alert('Provided settings successfully imported. Prior settings overwritten.'); } } } } echo '<h2>Export BackupBuddy Settings</h2>'; echo 'Copy the encoded plugin settings below and paste it into the destination BackupBuddy Settings Import page.<br><br>'; echo '<textarea style="width: 100%; height: 100px;" wrap="on">'; echo base64_encode(serialize(pb_backupbuddy::$options)); echo '</textarea>'; echo '<br><br><br>'; echo '<h2>Import BackupBuddy Settings</h2>'; echo 'Paste encoded plugin settings below to import & replace current settings. If importing settings from an older version and errors are encountered please deactivate and reactivate the plugin.<br><br>'; echo '<form method="post" action="' . pb_backupbuddy::ajax_url('importexport_settings') . '">'; echo '<textarea style="width: 100%; height: 100px;" wrap="on" name="import_data"></textarea>'; echo '<br><br><input type="submit" name="import_settings" value="Import Settings" class="button button-primary">'; echo '</form>'; pb_backupbuddy::$ui->ajax_footer(); die; }
public static function final_cleanup($serial) { if (!isset(pb_backupbuddy::$options)) { pb_backupbuddy::load(); } pb_backupbuddy::status('details', 'cron_final_cleanup started'); require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php'; pb_backupbuddy::status('details', 'Fileoptions instance #31.'); $backup_options = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt', $read_only = true); if (true !== ($result = $backup_options->is_ok())) { pb_backupbuddy::status('error', 'Unable to open fileoptions file.'); } // Delete temporary data directory. if (isset($backup_options->options['temp_directory']) && file_exists($backup_options->options['temp_directory'])) { pb_backupbuddy::$filesystem->unlink_recursive($backup_options->options['temp_directory']); } // Delete temporary zip directory. if (isset($backup_options->options['temporary_zip_directory']) && file_exists($backup_options->options['temporary_zip_directory'])) { pb_backupbuddy::$filesystem->unlink_recursive($backup_options->options['temporary_zip_directory']); } // Delete status log text file. if (file_exists(backupbuddy_core::getBackupDirectory() . 'temp_status_' . $serial . '.txt')) { unlink(backupbuddy_core::getBackupDirectory() . 'temp_status_' . $serial . '.txt'); } }
public function migration_picker() { pb_backupbuddy::load(); pb_backupbuddy::$ui->ajax_header(); require_once 'ajax/_migration_picker.php'; pb_backupbuddy::$ui->ajax_footer(); die; }
public static function importbuddy($output_file = '', $importbuddy_pass_hash = '', $return_not_echo = false) { pb_backupbuddy::set_greedy_script_limits(); // Some people run out of PHP memory. if ($importbuddy_pass_hash == '') { if (!isset(pb_backupbuddy::$options)) { pb_backupbuddy::load(); } $importbuddy_pass_hash = pb_backupbuddy::$options['importbuddy_pass_hash']; } if ($importbuddy_pass_hash == '') { $message = 'Warning #9032 - You have not set an ImportBuddy password on the BackupBuddy Settings page. Once this password is set a copy of the importbuddy.php file needed to restore your backup will be included in Full backup zip files for convenience. It may manually be downloaded from the Restore / Migrate page.'; pb_backupbuddy::status('warning', $message); return false; } pb_backupbuddy::status('details', 'Loading importbuddy core file into memory.'); $output = file_get_contents(pb_backupbuddy::plugin_path() . '/_importbuddy/_importbuddy.php'); if ($importbuddy_pass_hash != '') { $output = preg_replace('/#PASSWORD#/', $importbuddy_pass_hash, $output, 1); // Only replaces first instance. } $version_string = pb_backupbuddy::settings('version') . ' (downloaded ' . date(DATE_W3C) . ')'; // If on DEV system (.git dir exists) then append some details on current. if (defined('BACKUPBUDDY_DEV') && true === BACKUPBUDDY_DEV) { if (@file_exists(pb_backupbuddy::plugin_path() . '/.git/logs/HEAD')) { $commit_log = escapeshellarg(pb_backupbuddy::plugin_path() . '/.git/logs/HEAD'); $commit_line = str_replace('\'', '`', exec("tail -n 1 {$commit_log}")); $version_string .= ' <span style="font-size: 8px;">[DEV: ' . $commit_line . ']</span>'; } } $output = preg_replace('/#VERSION#/', $version_string, $output, 1); // Only replaces first instance. // PACK IMPORTBUDDY $_packdata = array('_importbuddy/importbuddy' => 'importbuddy', 'classes/_migrate_database.php' => 'importbuddy/classes/_migrate_database.php', 'classes/core.php' => 'importbuddy/classes/core.php', 'classes/import.php' => 'importbuddy/classes/import.php', 'classes/restore.php' => 'importbuddy/classes/restore.php', 'classes/_restoreFiles.php' => 'importbuddy/classes/_restoreFiles.php', 'classes/remote_api.php' => 'importbuddy/classes/remote_api.php', 'js/jquery.leanModal.min.js' => 'importbuddy/js/jquery.leanModal.min.js', 'js/jquery.joyride-2.0.3.js' => 'importbuddy/js/jquery.joyride-2.0.3.js', 'js/modernizr.mq.js' => 'importbuddy/js/modernizr.mq.js', 'css/joyride.css' => 'importbuddy/css/joyride.css', 'images/working.gif' => 'importbuddy/images/working.gif', 'images/bullet_go.png' => 'importbuddy/images/bullet_go.png', 'images/favicon.png' => 'importbuddy/images/favicon.png', 'images/sort_down.png' => 'importbuddy/images/sort_down.png', 'images/icon_menu_32x32.png' => 'importbuddy/images/icon_menu_32x32.png', 'lib/dbreplace' => 'importbuddy/lib/dbreplace', 'lib/dbimport' => 'importbuddy/lib/dbimport', 'lib/commandbuddy' => 'importbuddy/lib/commandbuddy', 'lib/zipbuddy' => 'importbuddy/lib/zipbuddy', 'lib/mysqlbuddy' => 'importbuddy/lib/mysqlbuddy', 'lib/textreplacebuddy' => 'importbuddy/lib/textreplacebuddy', 'lib/cpanel' => 'importbuddy/lib/cpanel', 'pluginbuddy' => 'importbuddy/pluginbuddy', 'controllers/pages/server_info' => 'importbuddy/controllers/pages/server_info', 'controllers/pages/server_tools.php' => 'importbuddy/controllers/pages/server_tools.php', 'destinations/stash/lib/class.itx_helper.php' => 'importbuddy/classes/class.itx_helper.php', 'destinations/_s3lib/aws-sdk/lib/requestcore' => 'importbuddy/lib/requestcore'); pb_backupbuddy::status('details', 'Loading each file into memory for writing master importbuddy file.'); $output .= "\n<?php /*\n###PACKDATA,BEGIN\n"; foreach ($_packdata as $pack_source => $pack_destination) { $pack_source = '/' . $pack_source; if (is_dir(pb_backupbuddy::plugin_path() . $pack_source)) { $files = pb_backupbuddy::$filesystem->deepglob(pb_backupbuddy::plugin_path() . $pack_source); } else { $files = array(pb_backupbuddy::plugin_path() . $pack_source); } foreach ($files as $file) { if (is_file($file)) { $source = str_replace(pb_backupbuddy::plugin_path(), '', $file); $destination = $pack_destination . substr($source, strlen($pack_source)); $output .= "###PACKDATA,FILE_START,{$source},{$destination}\n"; $output .= base64_encode(file_get_contents($file)); $output .= "\n"; $output .= "###PACKDATA,FILE_END,{$source},{$destination}\n"; } } } $output .= "###PACKDATA,END\n*/"; $output .= "\n\n\n\n\n\n\n\n\n\n"; if (true === $return_not_echo) { return $output; } if ($output_file == '') { // No file so output to browser. header('Content-Description: File Transfer'); header('Content-Type: text/plain; name=importbuddy.php'); header('Content-Disposition: attachment; filename=importbuddy.php'); header('Expires: 0'); header('Content-Length: ' . strlen($output)); pb_backupbuddy::flush(); echo $output; pb_backupbuddy::flush(); // BE SURE TO die() AFTER THIS AND NOT OUTPUT TO BROWSER! } else { // Write to file. pb_backupbuddy::status('details', 'Writing importbuddy master file to disk.'); if (false === file_put_contents($output_file, $output)) { pb_backupbuddy::status('error', 'Error #483894: Unable to write to file `' . $output_file . '`.'); return false; } else { return true; } } }