Exemplo n.º 1
0
 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 . '` with ID `' . $identifier . '` 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' => 'running', 'write_speed' => 0));
     pb_backupbuddy::save();
     // 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 );
             }
         }
     }
     // end if stash.
     /*
     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';
     pb_backupbuddy::status('details', 'Calling destination send() function.');
     $send_result = pb_backupbuddy_destinations::send($destination_settings, $file, $identifier, $delete_after);
     pb_backupbuddy::status('details', 'Finished destination send() function.');
     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 for ID `' . $identifier . '`.');
     $fileoptions =& $fileoptions_obj->options;
     // Set reference.
     // Update stats.
     $fileoptions[$identifier]['finish_time'] = microtime(true);
     if ($send_result === true) {
         // succeeded.
         $fileoptions['status'] = 'success';
         $fileoptions['finish_time'] = microtime(true);
         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;
 }