public function run($arguments)
 {
     $arguments = Ithemes_Sync_Functions::merge_defaults($arguments, $this->default_arguments);
     $results = backupbuddy_api::runBackup($arguments['profile'], 'iThemes Sync', $backupMode = '2');
     if (true !== $results) {
         return array('api' => '0', 'status' => 'error', 'message' => 'Error running backup. Details: ' . $results);
     } else {
         return array('api' => '0', 'status' => 'ok', 'message' => 'Backup initiated successfully.', 'serial' => $serial);
     }
 }
Example #2
0
 /**
  * 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
  *
  * ## USAGE
  *
  *    wp backupbuddy backup <profile> [--quiet]
  *
  * @synopsis <profile> [--quiet]
  */
 public function backup($args, $assoc_args)
 {
     if (!isset($assoc_args['quiet'])) {
         define('BACKUPBUDDY_WP_CLI', true);
     }
     $profile = $args[0];
     $results = backupbuddy_api::runBackup($profile, $friendlyTrigger = 'wp-cli', $backupMode = '1');
     if (true === $results) {
         // success
         WP_CLI::success('Backup completed successfully.');
         return;
     } else {
         // fail
         WP_CLI::error('Error initiating backup. Details: ' . $results);
     }
 }
 private static function _verb_runBackup()
 {
     $backupSerial = pb_backupbuddy::random_string(10);
     $profileArray = pb_backupbuddy::_POST('profile');
     if (false === ($profileArray = base64_decode($profileArray))) {
         $message = 'Error #8343728: Unable to base64 decode profile data.';
         pb_backupbuddy::status('error', $message, $backupSerial);
         die(json_encode(array('success' => false, 'error' => $message)));
     }
     if (NULL === ($profileArray = json_decode($profileArray, true))) {
         $message = 'Error #3272383: Unable to json decode profile data.';
         pb_backupbuddy::status('error', $message, $backupSerial);
         die(json_encode(array('success' => false, 'error' => $message)));
     }
     // Appends session tokens from the pulling site so they wont get logged out when this database is restored there.
     if (isset($profileArray['sessionTokens']) && is_array($profileArray['sessionTokens'])) {
         pb_backupbuddy::status('details', 'Remote session tokens need updated.', $backupSerial);
         //error_log( 'needtoken' );
         if (!is_numeric($profileArray['sessionID'])) {
             $message = 'Error #328989893. Invalid session ID. Must be numeric.';
             pb_backupbuddy::status('error', $message);
             die(json_encode(array('success' => false, 'error' => $message)));
         }
         // Get current session tokens.
         global $wpdb;
         $sql = "SELECT meta_value FROM `" . DB_NAME . "`.`" . $wpdb->prefix . "usermeta` WHERE `user_id` = '" . $profileArray['sessionID'] . "' AND `meta_key` = 'session_tokens';";
         $results = $wpdb->get_var($sql);
         $oldSessionTokens = @unserialize($results);
         // Add remote tokens.
         if (!is_array($oldSessionTokens)) {
             $oldSessionTokens = array();
         }
         $newSessionTokens = array_merge($oldSessionTokens, $profileArray['sessionTokens']);
         // Re-serialize.
         $newSessionTokens = serialize($newSessionTokens);
         // Save merged tokens here.
         $sql = "UPDATE `" . DB_NAME . "`.`" . $wpdb->prefix . "usermeta` SET meta_value= %s WHERE `user_id` = '" . $profileArray['sessionID'] . "' AND `meta_key` = 'session_tokens';";
         $stringedSessionTokens = serialize($profileArray['sessionTokens']);
         if (false === $wpdb->query($wpdb->prepare($sql, $stringedSessionTokens))) {
             $message = 'Error #43734784: Unable to update remote session token.';
             pb_backupbuddy::status('error', $message, $backupSerial);
             die(json_encode(array('success' => false, 'error' => $message)));
         }
         pb_backupbuddy::status('details', 'Updated remote session tokens.', $backupSerial);
     }
     if (true !== ($maybeMessage = backupbuddy_api::runBackup($profileArray, $triggerTitle = 'deployment_pulling', $backupMode = '', $backupSerial))) {
         $message = 'Error #48394873: Unable to launch backup at source. Details: `' . $maybeMessage . '`.';
         pb_backupbuddy::status('error', $message, $backupSerial);
         die(json_encode(array('success' => false, 'error' => $message)));
     } else {
         $archiveFilename = basename(backupbuddy_core::calculateArchiveFilename($backupSerial, $profileArray['type']));
         die(json_encode(array('success' => true, 'backupSerial' => $backupSerial, 'backupFile' => $archiveFilename)));
     }
 }
Example #4
0
 private static function _verb_runBackup()
 {
     $backupSerial = pb_backupbuddy::random_string(10);
     backupbuddy_api::runBackup($profileArray, $triggerTitle = 'deployment', $backupMode = '', $backupSerial);
 }
Example #5
0
<?php

print_r($_POST);
echo '<hr>';
defined('ABSPATH') or die('404 Not Found');
if (!isset(pb_backupbuddy::$options['remote_destinations'][pb_backupbuddy::_POST('destination')])) {
    die('Error #8457474: Invalid destination ID `' . htmlentities(pb_backupbuddy::_POST('destination')) . '`.');
}
$deployment =& pb_backupbuddy::$options['deployments'][pb_backupbuddy::_GET('deployment')];
$profileID = pb_backupbuddy::_POST('backup_profile');
$backupSerial = pb_backupbuddy::random_string(10);
// Manually define serial so we can track this specific backup.
$backup_result = backupbuddy_api::runBackup($profileID, $triggerTitle = 'Deployment', $backupMode = '', $backupSerial);
if (true !== $backup_result) {
    die('Error #85487755: Unable to start backup. Details: `' . $backup_result . '`.');
}
print_r(backupbuddy_api::getLatestBackupStats());
?>

<script>
	function checkDeployStatus( step ) {
		jQuery('#pb_backupbuddy_loading').show();
		if ( '' == step ) {
			step = '0';
		}
		stepCounter = 0; // How many status checks of this step have been done.
		
		jQuery.ajax({
			
			url:	'<?php 
echo pb_backupbuddy::ajax_url('deploy_status');