示例#1
0
 public static function _step_run_remote_snapshot()
 {
     if (false === self::_load_state()) {
         return false;
     }
     // If not all files have uploaded, skip snapshot for now.
     if (self::$_state['stats']['files_pending_send'] > 0 || self::$_state['stats']['tables_pending_send'] > 0) {
         pb_backupbuddy::status('details', '`' . self::$_state['stats']['files_pending_send'] . '` files and `' . self::$_state['stats']['tables_pending_send'] . '` database tables are still pending transfer. Waiting for transfers to finish before creating Snapshot.');
         self::$_state['stats']['wait_on_transfers_start'] = microtime(true);
         backupbuddy_live::queue_step($step = 'wait_on_transfers', $args = array(), $skip_run_now = true);
         return true;
     }
     if (0 == self::$_state['stats']['files_total_count'] || 0 == self::$_state['stats']['tables_total_count']) {
         $error = 'Error #3489349834: Made it to the snapshot stage but there are zero files and/or tables. Halting to protect backup integrity. Files: `' . self::$_state['stats']['files_total_count'] . '`. Tables: `' . self::$_state['stats']['tables_total_count'] . '`.';
         backupbuddy_core::addNotification('live_error', 'BackupBuddy Stash Live Error', $error);
         return $error;
     }
     if (false !== self::$_state['stats']['manual_snapshot']) {
         pb_backupbuddy::status('details', 'Manual snapshot requested at `' . pb_backupbuddy::$format->date(pb_backupbuddy::$format->localize_time(self::$_state['stats']['manual_snapshot'])) . '` (' . pb_backupbuddy::$format->time_ago(self::$_state['stats']['manual_snapshot']) . ' ago). Triggering remote snapshot now.');
         $trigger = 'manual';
     } else {
         $trigger = 'automatic';
         $destination_settings = self::get_destination_settings();
         $schedule_times = wp_get_schedules();
         if (!isset($schedule_times[$destination_settings['remote_snapshot_period']])) {
             pb_backupbuddy::status('error', 'Error #383927494: Invalid schedule interval/period `' . $destination_settings['remote_snapshot_period'] . '`. Not found in wp_get_schedules().');
             return false;
         }
         $delay_between_runs = $schedule_times[$destination_settings['remote_snapshot_period']]['interval'];
         $adjusted_delay_between_runs = $delay_between_runs - self::REMOTE_SNAPSHOT_PERIOD_WIGGLE_ROOM;
         $time_since_last_run = microtime(true) - self::$_state['stats']['last_remote_snapshot'];
         pb_backupbuddy::status('details', 'Period between remote snapshots: `' . $destination_settings['remote_snapshot_period'] . '` (`' . $delay_between_runs . '` seconds). Time since last run: `' . $time_since_last_run . '`. Allowed to run `' . self::REMOTE_SNAPSHOT_PERIOD_WIGGLE_ROOM . '` secs early. Adjusted min delay between runs: `' . $adjusted_delay_between_runs . '`.');
         if ($time_since_last_run < $adjusted_delay_between_runs) {
             pb_backupbuddy::status('details', 'Not enough time has passed since last remote snapshot. Skipping this pass.');
             return true;
         }
         // Made it here so trigger remote snapshot.
         pb_backupbuddy::status('details', 'Enough time has passed since last remote snapshot. Triggering remote snapshot now.');
     }
     $response = backupbuddy_live_periodic::_run_remote_snapshot($trigger);
     if (!is_array($response)) {
         $error = 'Error #2397734: Unable to initiate Live snapshot. See log above for details or here: `' . $response . '`.';
         pb_backupbuddy::status('error', $error);
         backupbuddy_core::addNotification('live_error', 'BackupBuddy Stash Live Error', $error);
         return false;
     } else {
         // Either triggered snapshot or one already running.
         if (true === $response['success']) {
             // Triggered new snapshot.
             $snapshot_id = $response['snapshot'];
             backupbuddy_live_periodic::update_last_remote_snapshot_time($snapshot_id);
             pb_backupbuddy::status('details', 'Triggered new remote snapshot with ID `' . $snapshot_id . '`.');
             // TODO: Keeping in place until new tmtrim-settings and passing tmtrim data with snapshot trigger is verified. Deprecating as of 7.0.5.5.
             // Schedule to run trim cleanup.
             $cronArgs = array();
             $schedule_result = backupbuddy_core::schedule_single_event(time() + 60 * 60, 'live_after_snapshot', $cronArgs);
             // 1hr
             if (true === $schedule_result) {
                 pb_backupbuddy::status('details', 'Next Live trim cron event scheduled.');
             } else {
                 pb_backupbuddy::status('error', 'Next Live trim cron event FAILED to be scheduled.');
             }
             if ('1' != pb_backupbuddy::$options['skip_spawn_cron_call']) {
                 pb_backupbuddy::status('details', 'Spawning cron now.');
                 update_option('_transient_doing_cron', 0);
                 // Prevent cron-blocking for next item.
                 spawn_cron(time() + 150);
                 // Adds > 60 seconds to get around once per minute cron running limit.
             }
             return true;
         } elseif (false === $response['success']) {
             // Failed to trigger new snapshot. Most likely one is already in progress.
             if (isset($response['snapshot'])) {
                 pb_backupbuddy::status('details', 'Did NOT trigger a new snapshot. One is already in progress with ID `' . $response['snapshot'] . '`.');
                 return true;
             } else {
                 pb_backupbuddy::status('error', 'Error #2898923: Something went wrong triggering snapshot. Details: `' . print_r($response) . '`.');
                 return false;
             }
         } else {
             pb_backupbuddy::status('error', 'Error #3832792397: Something went wrong triggering snapshot. Details: `' . print_r($response) . '`.');
             return false;
         }
     }
     pb_backupbuddy::status('error', 'Error #8028434. This should never happen. This code should not be reached.');
     return false;
 }