Esempio n. 1
0
function bb_build_remote_destinations($destinations_list)
{
    $remote_destinations = explode('|', $destinations_list);
    $remote_destinations_html = '';
    foreach ($remote_destinations as $destination) {
        if (isset($destination) && $destination != '') {
            $remote_destinations_html .= '<li id="pb_remotedestination_' . $destination . '">';
            if (!isset(pb_backupbuddy::$options['remote_destinations'][$destination])) {
                $remote_destinations_html .= '{destination no longer exists}';
            } else {
                $remote_destinations_html .= pb_backupbuddy::$options['remote_destinations'][$destination]['title'];
                $remote_destinations_html .= ' (' . backupbuddy_core::pretty_destination_type(pb_backupbuddy::$options['remote_destinations'][$destination]['type']) . ') ';
            }
            $remote_destinations_html .= '<img class="pb_remotedestionation_delete" src="' . pb_backupbuddy::plugin_url() . '/images/redminus.png" style="vertical-align: -3px; cursor: pointer;" title="' . __('Remove remote destination from this schedule.', 'it-l10n-backupbuddy') . '" />';
            $remote_destinations_html .= '</li>';
        }
    }
    $remote_destinations = '<ul id="pb_backupbuddy_remotedestinations_list">' . $remote_destinations_html . '</ul>';
    return $remote_destinations;
}
    $secondsAgo = time() - $fileoptions_obj->options['update_time'];
    if ($secondsAgo > backupbuddy_constants::TIME_BEFORE_CONSIDERED_TIMEOUT) {
        // If 24hrs passed since last update to backup then mark this timeout as failed.
        $isResending = backupbuddy_core::remoteSendRetry($fileoptions_obj, $send_id, pb_backupbuddy::$options['remote_send_timeout_retries']);
        if (true === $isResending) {
            // If resending then skip sending any error email just yet...
            continue;
        }
        if ('timeout' != $fileoptions_obj->options['status']) {
            // Do not send email if status is 'timeout' since either already sent or old-style status marking (pre-v6.0).
            // Calculate destination title and type for error email.
            $destination_title = '';
            $destination_type = '';
            if (isset(pb_backupbuddy::$options['remote_destinations'][$fileoptions_obj->options['destination']])) {
                $destination_title = pb_backupbuddy::$options['remote_destinations'][$fileoptions_obj->options['destination']]['title'];
                $destination_type = backupbuddy_core::pretty_destination_type(pb_backupbuddy::$options['remote_destinations'][$fileoptions_obj->options['destination']]['type']);
            }
            $error_message = 'A remote destination send of file `' . basename($fileoptions_obj->options['file']) . '` started `' . pb_backupbuddy::$format->time_ago($fileoptions_obj->options['start_time']) . '` ago sending to the destination titled `' . $destination_title . '` of type `' . $destination_type . '` likely timed out. BackupBuddy will attempt to retry this failed transfer ONCE. If the second atempt succeeds the failed attempt will be replaced in the recent sends list. Check the error log for further details and/or manually send a backup to test for problems.';
            pb_backupbuddy::status('error', $error_message);
            if ($secondsAgo < backupbuddy_constants::CLEANUP_MAX_AGE_TO_NOTIFY_TIMEOUT) {
                // Prevents very old timed out backups from triggering email send.
                backupbuddy_core::mail_error($error_message);
            }
        }
        $fileoptions_obj->options['status'] = 'timeout';
        $fileoptions_obj->options['finish_time'] = -1;
        $fileoptions_obj->save();
    }
    unset($fileoptions_obj);
}
// Handle high security mode archives directory .htaccess system. If high security backup directory mode: Make sure backup archives are NOT downloadable by default publicly. This is only lifted for ~8 seconds during a backup download for security. Overwrites any existing .htaccess in this location.
Esempio n. 3
0
     $type = 'Database only';
 } else {
     $type = 'Unknown (' . $schedule['type'] . ')';
 }
 $type = $profile['title'] . ' (' . $type . ')';
 $interval = $schedule['interval'];
 if (isset($schedule['on_off']) && $schedule['on_off'] == '0') {
     $on_off = '<font color=red>Disabled</font>';
 } else {
     $on_off = 'Enabled';
 }
 $destinations = explode('|', $schedule['remote_destinations']);
 $destination_array = array();
 foreach ($destinations as &$destination) {
     if (isset($destination) && $destination != '') {
         $destination_array[] = pb_backupbuddy::$options['remote_destinations'][$destination]['title'] . ' (' . backupbuddy_core::pretty_destination_type(pb_backupbuddy::$options['remote_destinations'][$destination]['type']) . ')';
     }
 }
 $destinations = implode(', ', $destination_array);
 if (count($destination_array) > 0) {
     if ($schedule['delete_after'] == '1') {
         $destinations .= '<br>' . '<span class="description">Delete local backup file after send</span>';
     } else {
         $destinations .= '<br>' . '<span class="description">Do not delete local backup file after send</span>';
     }
 } else {
     $destinations = '<span class="description">None</span>';
 }
 // Determine first run.
 $first_run = pb_backupbuddy::$format->date(pb_backupbuddy::$format->localize_time($schedule['first_run']));
 // Determine last run.
Esempio n. 4
0
$finish_time = 'Unknown';
if (isset($send_options->options['start_time'])) {
    $start_time = pb_backupbuddy::$format->date(pb_backupbuddy::$format->localize_time($send_options->options['start_time'])) . ' <span class="description">(' . pb_backupbuddy::$format->time_ago($send_options->options['start_time']) . ' ago)</span>';
    if ($send_options->options['finish_time'] > 0) {
        $finish_time = pb_backupbuddy::$format->date(pb_backupbuddy::$format->localize_time($send_options->options['finish_time'])) . ' <span class="description">(' . pb_backupbuddy::$format->time_ago($send_options->options['finish_time']) . ' ago)</span>';
    } else {
        // unfinished.
        $finish_time = '<i>Unfinished</i>';
    }
}
$steps = array();
$steps[] = array('Start Time', $start_time);
$steps[] = array('File', '<span title="' . $send_options->options['file'] . '">' . basename($send_options->options['file']) . '</span>');
$destination = '<i>Unknown</i>';
if (isset(pb_backupbuddy::$options['remote_destinations'][$send_options->options['destination']])) {
    $destination = htmlentities(pb_backupbuddy::$options['remote_destinations'][$send_options->options['destination']]['title']) . ' [' . backupbuddy_core::pretty_destination_type(pb_backupbuddy::$options['remote_destinations'][$send_options->options['destination']]['type']) . ']';
}
$steps[] = array('Destination', $destination);
// Total overall time from initiation to end.
if (isset($send_options->options['finish_time']) && isset($send_options->options['start_time']) && $send_options->options['finish_time'] != 0 && $send_options->options['start_time'] != 0) {
    $seconds = $send_options->options['finish_time'] - $send_options->options['start_time'];
    if ($seconds < 1) {
        $total_time = '< 1 second';
    } else {
        $total_time = $seconds . ' seconds';
    }
} else {
    $total_time = '<i>Unknown</i>';
}
$steps[] = array('Last Updated Time', $send_options->options['update_time']);
$steps[] = array('Finish Time', $finish_time);
Esempio n. 5
0
 public static function send($destination_settings, $file, $send_id = '', $delete_after = false)
 {
     if (is_array($file)) {
         // As of v6.1.0.1 no longer accepting multiple files to send.
         $file = $file[0];
     }
     if ('' != $send_id) {
         pb_backupbuddy::add_status_serial('remote_send-' . $send_id);
         pb_backupbuddy::status('details', '----- Initiating master send function for BackupBuddy v' . pb_backupbuddy::settings('version') . '. Post-send deletion: ' . $delete_after);
         require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
         $fileoptions_file = backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $send_id . '.txt';
         if (!file_exists($fileoptions_file)) {
             //pb_backupbuddy::status( 'details', 'Fileoptions file `' . $fileoptions_file . '` does not exist yet; creating.' );
             //pb_backupbuddy::status( 'details', 'Fileoptions instance #19.' );
             $fileoptions_obj = new pb_backupbuddy_fileoptions($fileoptions_file, $read_only = false, $ignore_lock = true, $create_file = true);
         } else {
             //pb_backupbuddy::status( 'details', 'Fileoptions file exists; loading.' );
             //pb_backupbuddy::status( 'details', 'Fileoptions instance #18.' );
             $fileoptions_obj = new pb_backupbuddy_fileoptions($fileoptions_file, $read_only = false, $ignore_lock = false, $create_file = false);
         }
         if (true !== ($result = $fileoptions_obj->is_ok())) {
             pb_backupbuddy::status('error', __('Fatal Error #9034.2344848. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
             return false;
         }
         //pb_backupbuddy::status( 'details', 'Fileoptions data loaded.' );
         $fileoptions =& $fileoptions_obj->options;
         if ('' == $fileoptions) {
             // Set defaults.
             $fileoptions = backupbuddy_core::get_remote_send_defaults();
             $fileoptions['type'] = $destination_settings['type'];
             $fileoptions['file'] = $file;
             $fileoptions['retries'] = 0;
         }
         $fileoptions['sendID'] = $send_id;
         $fileoptions['destinationSettings'] = $destination_settings;
         // always store the LATEST settings for resume info and retry function.
         $fileoptions['update_time'] = time();
         $fileoptions['deleteAfter'] = $delete_after;
         $fileoptions_obj->save();
         if (isset($fileoptions['status']) && 'aborted' == $fileoptions['status']) {
             pb_backupbuddy::status('warning', 'Destination send triggered on an ABORTED transfer. Ending send function.');
             return false;
         }
         unset($fileoptions_obj);
     }
     if (false === ($destination = self::_init_destination($destination_settings))) {
         echo '{Error #546893498a. Destination configuration file missing.}';
         if ('' != $send_id) {
             pb_backupbuddy::remove_status_serial('remote_send-' . $send_id);
         }
         return false;
     }
     $destination_settings = $destination['settings'];
     // Settings with defaults applied, normalized, etc.
     if (!file_exists($file)) {
         pb_backupbuddy::status('error', 'Error #58459458743. The file that was attempted to be sent to a remote destination, `' . $file . '`, was not found. It either does not exist or permissions prevent accessing it. Check that local backup limits are not causing it to be deleted.');
         if ('' != $send_id) {
             pb_backupbuddy::remove_status_serial('remote_send-' . $send_id);
         }
         return false;
     }
     if (!method_exists($destination['class'], 'send')) {
         pb_backupbuddy::status('error', 'Destination class `' . $destination['class'] . '` does not support send operation -- missing function.');
         if ('' != $send_id) {
             pb_backupbuddy::remove_status_serial('remote_send-' . $send_id);
         }
         return false;
     }
     global $pb_backupbuddy_destination_errors;
     $pb_backupbuddy_destination_errors = array();
     $result = call_user_func_array("{$destination['class']}::send", array($destination_settings, $file, $send_id, $delete_after));
     /* $result values:
      *		false		Transfer FAILED.
      *		true		Non-chunked transfer succeeded.
      *		array()		array(
      *						multipart_id,				// Unique string ID for multipart send. Empty string if last chunk finished sending successfully.
      *						multipart_status_message
      *					)
      */
     if ($result === false) {
         $error_details = implode('; ', $pb_backupbuddy_destination_errors);
         if ('' != $error_details) {
             $error_details = ' Details: ' . $error_details;
         }
         $log_directory = backupbuddy_core::getLogDirectory();
         $preError = 'There was an error sending to the remote destination titled `' . $destination_settings['title'] . '` of type `' . backupbuddy_core::pretty_destination_type($destination_settings['type']) . '`. One or more files may have not been fully transferred. Please see error details for additional information. If the error persists, enable full error logging and try again for full details and troubleshooting. Details: ' . "\n\n";
         $logFile = $log_directory . 'status-remote_send-' . $send_id . '_' . pb_backupbuddy::$options['log_serial'] . '.txt';
         pb_backupbuddy::status('details', 'Looking for remote send log file to send in error email: `' . $logFile . '`.');
         if (!file_exists($logFile)) {
             pb_backupbuddy::status('details', 'Remote send log file not found.');
             backupbuddy_core::mail_error($preError . $error_details);
         } else {
             // Log exists. Attach.
             pb_backupbuddy::status('details', 'Remote send log file found. Attaching to error email.');
             backupbuddy_core::mail_error($preError . $error_details . "\n\nSee the attached log for details.", '', array($logFile));
         }
         // Save error details into fileoptions for this send.
         //pb_backupbuddy::status( 'details', 'About to load fileoptions data.' );
         require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
         pb_backupbuddy::status('details', 'Fileoptions instance #45.');
         $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 !== ($fileoptions_result = $fileoptions_obj->is_ok())) {
             pb_backupbuddy::status('error', __('Error #9034.32731. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $fileoptions_result);
         }
         //pb_backupbuddy::status( 'details', 'Fileoptions data loaded.' );
         $fileoptions =& $fileoptions_obj->options;
         $fileoptions['status'] = 'failed';
         $fileoptions['error'] = 'Error sending.' . $error_details;
         $fileoptions['updated_time'] = time();
         $fileoptions_obj->save();
         unset($fileoptions_obj);
     }
     if (is_array($result)) {
         // Send is multipart.
         pb_backupbuddy::status('details', 'Multipart chunk mode completed a pass of the send function. Resuming will be needed. Result: `' . print_r($result, true) . '`.');
         if ('' != $send_id) {
             //pb_backupbuddy::status( 'details', 'About to load fileoptions data.' );
             require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
             //pb_backupbuddy::status( 'details', 'Fileoptions instance #17.' );
             $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 !== ($fileoptions_result = $fileoptions_obj->is_ok())) {
                 pb_backupbuddy::status('error', __('Fatal Error #9034.387462. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $fileoptions_result);
                 return false;
             }
             //pb_backupbuddy::status( 'details', 'Fileoptions data loaded.' );
             $fileoptions =& $fileoptions_obj->options;
             $fileoptions['_multipart_status'] = $result[1];
             $fileoptions['updated_time'] = time();
             pb_backupbuddy::status('details', 'Destination debugging details: `' . print_r($fileoptions, true) . '`.');
             $fileoptions_obj->save();
             unset($fileoptions_obj);
             pb_backupbuddy::status('details', 'Next multipart chunk will be processed shortly. Now waiting on its cron...');
         }
     } else {
         // Single all-at-once send.
         if (false === $result) {
             pb_backupbuddy::status('details', 'Completed send function. Failure. Post-send deletion will be skipped if enabled.');
         } elseif (true === $result) {
             pb_backupbuddy::status('details', 'Completed send function. Success.');
         } else {
             pb_backupbuddy::status('warning', 'Completed send function. Unknown result: `' . $result . '`.');
         }
         pb_backupbuddy::status('details', 'About to load fileoptions data.');
         require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
         pb_backupbuddy::status('details', 'Fileoptions instance #16.');
         $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 !== ($fileoptions_result = $fileoptions_obj->is_ok())) {
             pb_backupbuddy::status('error', __('Error #9034.387462. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $fileoptions_result);
         }
         pb_backupbuddy::status('details', 'Fileoptions data loaded.');
         $fileoptions =& $fileoptions_obj->options;
         $fileoptions['updated_time'] = time();
         unset($fileoptions_obj);
     }
     // File transfer completely finished successfully.
     if (true === $result) {
         $fileSize = filesize($file);
         $serial = backupbuddy_core::get_serial_from_file($file);
         // Handle deletion of send file if enabled.
         if (true === $delete_after && false !== $result) {
             pb_backupbuddy::status('details', __('Post-send deletion enabled.', 'it-l10n-backupbuddy'));
             if (false === $result) {
                 pb_backupbuddy::status('details', 'Skipping post-send deletion since transfer failed.');
             } else {
                 pb_backupbuddy::status('details', 'Performing post-send deletion since transfer succeeded.');
                 pb_backupbuddy::status('details', 'Deleting local file `' . $file . '`.');
                 // Handle post-send deletion on success.
                 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'));
                     backupbuddy_core::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('archiveDeleted', '');
                 }
             }
         } else {
             pb_backupbuddy::status('details', 'Post-send deletion not enabled.');
         }
         // Send email notification if enabled.
         if ('' != pb_backupbuddy::$options['email_notify_send_finish']) {
             pb_backupbuddy::status('details', __('Sending finished destination send email notification.', 'it-l10n-backupbuddy'));
             $extraReplacements = array();
             $extraReplacements = array('{backup_file}' => $file, '{backup_size}' => $fileSize, '{backup_serial}' => $serial);
             backupbuddy_core::mail_notify_scheduled($serial, 'destinationComplete', __('Destination send complete to', 'it-l10n-backupbuddy') . ' ' . backupbuddy_core::pretty_destination_type($destination_settings['type']), $extraReplacements);
         } else {
             pb_backupbuddy::status('details', __('Finished sending email NOT enabled. Skipping.', 'it-l10n-backupbuddy'));
         }
         // Save notification of final results.
         $data = array();
         $data['serial'] = $serial;
         $data['file'] = $file;
         $data['size'] = $fileSize;
         $data['pretty_size'] = pb_backupbuddy::$format->file_size($fileSize);
         backupbuddy_core::addNotification('remote_send_success', 'Remote file transfer completed', 'A file has successfully completed sending to a remote location.', $data);
     }
     // NOTE: Call this before removing status serial so it shows in log.
     pb_backupbuddy::status('details', 'Ending send() function pass.');
     // Return logging to normal file.
     if ('' != $send_id) {
         pb_backupbuddy::remove_status_serial('remote_send-' . $send_id);
     }
     return $result;
 }
Esempio n. 6
0
 public static function process_timed_out_sends()
 {
     require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
     // Mark any timed out remote sends as timed out. Attempt resend once.
     $remote_sends = array();
     $send_fileoptions = pb_backupbuddy::$filesystem->glob_by_date(backupbuddy_core::getLogDirectory() . 'fileoptions/send-*.txt');
     if (!is_array($send_fileoptions)) {
         $send_fileoptions = array();
     }
     foreach ($send_fileoptions as $send_fileoption) {
         $send_id = str_replace('.txt', '', str_replace('send-', '', basename($send_fileoption)));
         pb_backupbuddy::status('details', 'About to load fileoptions data.');
         require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
         pb_backupbuddy::status('details', 'Fileoptions instance #23.');
         $fileoptions_file = backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $send_id . '.txt';
         $fileoptions_obj = new pb_backupbuddy_fileoptions($fileoptions_file, $read_only = false, $ignore_lock = false, $create_file = false);
         if (true !== ($result = $fileoptions_obj->is_ok())) {
             pb_backupbuddy::status('error', __('Fatal Error #9034.3224442393. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
             return false;
         }
         // Corrupt fileoptions file. Remove.
         if (!isset($fileoptions_obj->options['start_time'])) {
             unset($fileoptions_obj);
             @unlink($fileoptions_file);
             continue;
         }
         // Finish time not set. Shouldn't happen buuuuut.... skip.
         if (!isset($fileoptions_obj->options['finish_time'])) {
             continue;
         }
         // Don't do anything for success, failure, or already-marked as -1 finish time.
         if ('success' == $fileoptions_obj->options['status'] || 'failure' == $fileoptions_obj->options['status'] || -1 == $fileoptions_obj->options['finish_time']) {
             continue;
         }
         // Older format did not include updated_time.
         if (!isset($fileoptions_obj->options['update_time'])) {
             continue;
         }
         $secondsAgo = time() - $fileoptions_obj->options['update_time'];
         if ($secondsAgo > backupbuddy_constants::TIME_BEFORE_CONSIDERED_TIMEOUT) {
             // If 24hrs passed since last update to backup then mark this timeout as failed.
             // Potentially try to resend if not a live_periodic transfer.
             if ('live_periodic' != $fileoptions_obj->options['trigger']) {
                 $isResending = backupbuddy_core::remoteSendRetry($fileoptions_obj, $send_id, pb_backupbuddy::$options['remote_send_timeout_retries']);
                 if (true === $isResending) {
                     // If resending then skip sending any error email just yet...
                     continue;
                 }
                 if ('timeout' != $fileoptions_obj->options['status']) {
                     // Do not send email if status is 'timeout' since either already sent or old-style status marking (pre-v6.0).
                     // Calculate destination title and type for error email.
                     $destination_title = '';
                     $destination_type = '';
                     if (isset(pb_backupbuddy::$options['remote_destinations'][$fileoptions_obj->options['destination']])) {
                         $destination_title = pb_backupbuddy::$options['remote_destinations'][$fileoptions_obj->options['destination']]['title'];
                         $destination_type = backupbuddy_core::pretty_destination_type(pb_backupbuddy::$options['remote_destinations'][$fileoptions_obj->options['destination']]['type']);
                     }
                     $error_message = 'A remote destination send of file `' . basename($fileoptions_obj->options['file']) . '` started `' . pb_backupbuddy::$format->time_ago($fileoptions_obj->options['start_time']) . '` ago sending to the destination titled `' . $destination_title . '` of type `' . $destination_type . '` likely timed out. BackupBuddy will attempt to retry this failed transfer ONCE. If the second atempt succeeds the failed attempt will be replaced in the recent sends list. Check the error log for further details and/or manually send a backup to test for problems.';
                     pb_backupbuddy::status('error', $error_message);
                     if ($secondsAgo < backupbuddy_constants::CLEANUP_MAX_AGE_TO_NOTIFY_TIMEOUT) {
                         // Prevents very old timed out backups from triggering email send.
                         backupbuddy_core::mail_error($error_message);
                     }
                 }
             }
             // Save as timed out.
             $fileoptions_obj->options['status'] = 'timeout';
             $fileoptions_obj->options['finish_time'] = -1;
             $fileoptions_obj->save();
             // If live_periofic then just try to delete the file at this point.
             if ('live_periodic' == $fileoptions_obj->options['trigger']) {
                 unset($fileoptions_obj);
                 @unlink($fileoptions_file);
                 continue;
             }
         }
         unset($fileoptions_obj);
     }
 }