function backup_migrate_destination_nodesquirrel::save_file

cis7 destinations.nodesquirrel.inc backup_migrate_destination_nodesquirrel::save_file($file, $settings)
cle7 destinations.nodesquirrel.inc backup_migrate_destination_nodesquirrel::save_file($file, $settings)
elmsmedia7 destinations.nodesquirrel.inc backup_migrate_destination_nodesquirrel::save_file($file, $settings)
icor7 destinations.nodesquirrel.inc backup_migrate_destination_nodesquirrel::save_file($file, $settings)
meedjum_blog7 destinations.nodesquirrel.inc backup_migrate_destination_nodesquirrel::save_file($file, $settings)
mooc7 destinations.nodesquirrel.inc backup_migrate_destination_nodesquirrel::save_file($file, $settings)

Save to the NodeSquirrel destination.

Overrides backup_migrate_destination::save_file

File

sites/all/modules/ulmus/backup_migrate/includes/destinations.nodesquirrel.inc, line 184
Functions to handle the NodeSquirrel backup destination.

Class

backup_migrate_destination_nodesquirrel
A destination for sending database backups to the NodeSquirel backup service.

Code

function save_file($file, $settings) {
  if ($destination = $this->_get_destination()) {
    srand((double) microtime() * 1000000);

    $filename = $file->filename();
    $filesize = filesize($file->filepath());
    $ticket = $this->_xmlrpc('backups.getUploadTicket', array($destination, $filename, $filesize, $file->file_info));

    if ($ticket) {

      $url = $ticket['url'];

      // If the ticket requires authentication add our username/password to the url.
      if (!empty($ticket['auth']) && $ticket['auth'] = 'basic') {
        $parts = parse_url($ticket['url']);
        list($parts['user'], $parts['pass']) = $this->get_user_pass();
        $url = $this->glue_url($parts, FALSE);
      }

      $out = $this->_post_file($url, 'POST', $ticket['params'], $file);

      if ($out->code == 200) {
        // Confirm the upload.
        $confirm = $this->_xmlrpc('backups.confirmUpload', array($destination, $filename, $filesize));

        if ($confirm['success']) {
          // Set a message with a link to the manage console.
          $url = variable_get('nodesquirrel_manage_url', 'http://manage.nodesquirrel.com') . '/backups/' . $this->_get_destination();
          _backup_migrate_message('Your backup has been saved to your NodeSquirrel account. View it at !account', array('!account' => l($url, $url)));

          return $file;
        }
        else {
          _backup_migrate_message('The backup file never made it to the NodeSquirrel backup server. There may have been a network problem. Please try again later');
        }
      }
      else {
        $error = !empty($out->headers['x-bams-error']) ? $out->headers['x-bams-error'] : $out->error;
        _backup_migrate_message('The NodeSquirrel server returned the following error: %err', array('%err' => $error), 'error');
      }
    }
    else if ($err = xmlrpc_error()) {
      // XMLRPC errors are already handled by the server function below.
    }
    else {
      _backup_migrate_message('The NodeSquirrel server refused the backup but did not specify why. Maybe the server is down.');
    }
  }
  return NULL;
}