コード例 #1
0
ファイル: backup.php プロジェクト: Brandonsmith23/prodgyr
 function post_backup($fail_mode = false, $cancel_backup = false)
 {
     pb_backupbuddy::status('message', __('Cleaning up after backup.', 'it-l10n-backupbuddy'));
     // Delete temporary data directory.
     if (file_exists($this->_backup['temp_directory'])) {
         pb_backupbuddy::status('details', __('Removing temp data directory.', 'it-l10n-backupbuddy'));
         pb_backupbuddy::$filesystem->unlink_recursive($this->_backup['temp_directory']);
     }
     // Delete temporary ZIP directory.
     if (file_exists(backupbuddy_core::getBackupDirectory() . 'temp_zip_' . $this->_backup['serial'] . '/')) {
         pb_backupbuddy::status('details', __('Removing temp zip directory.', 'it-l10n-backupbuddy'));
         pb_backupbuddy::$filesystem->unlink_recursive(backupbuddy_core::getBackupDirectory() . 'temp_zip_' . $this->_backup['serial'] . '/');
     }
     if (true === $fail_mode) {
         pb_backupbuddy::status('warning', 'Backup archive limiting has been skipped since there was an error to avoid deleting potentially good backups to make room for a potentially bad backup.');
     } else {
         $this->trim_old_archives();
         // Clean up any old excess archives pushing us over defined limits in settings.
     }
     if (true === $cancel_backup) {
         pb_backupbuddy::status('details', 'Backup stopped so deleting backup ZIP file.');
         $unlink_result = @unlink($this->_backup['archive_file']);
         if (true === $unlink_result) {
             pb_backupbuddy::status('details', 'Deleted stopped backup file.');
         } else {
             pb_backupbuddy::status('error', 'Unable to delete stopped backup file. You should delete it manually as it may be damaged from stopping mid-backup. File to delete: `' . $this->_backup['archive_file'] . '`.');
         }
         $this->_backup['finish_time'] = -1;
         //pb_backupbuddy::save();
         $this->_backup_options->save();
     } else {
         // Not cancelled.
         $this->_backup['archive_size'] = @filesize($this->_backup['archive_file']);
         pb_backupbuddy::status('details', __('Final ZIP file size', 'it-l10n-backupbuddy') . ': ' . pb_backupbuddy::$format->file_size($this->_backup['archive_size']));
         pb_backupbuddy::status('archiveSize', pb_backupbuddy::$format->file_size($this->_backup['archive_size']));
         if ($fail_mode === false) {
             // Not cancelled and did not fail so mark finish time.
             //error_log( print_r( $this->_backup_options->options, true ) );
             $archiveFile = basename($this->_backup_options->options['archive_file']);
             // Calculate backup download URL, if any.
             //$downloadURL = pb_backupbuddy::ajax_url( 'download_archive' ) . '&backupbuddy_backup=' . $archiveFile;
             $downloadURL = '';
             $abspath = str_replace('\\', '/', ABSPATH);
             // Change slashes to handle Windows as we store backup_directory with Linux-style slashes even on Windows.
             $backup_dir = str_replace('\\', '/', backupbuddy_core::getBackupDirectory());
             if (FALSE !== stristr($backup_dir, $abspath)) {
                 // Make sure file to download is in a publicly accessible location (beneath WP web root technically).
                 //pb_backupbuddy::status( 'details', 'mydir: `' . $backup_dir . '`, abs: `' . $abspath . '`.');
                 $sitepath = str_replace($abspath, '', $backup_dir);
                 $downloadURL = rtrim(site_url(), '/\\') . '/' . trim($sitepath, '/\\') . '/' . $archiveFile;
             }
             $integrityIsOK = '-1';
             if (isset($this->_backup_options->options['integrity']['is_ok'])) {
                 $integrityIsOK = $this->_backup_options->options['integrity']['is_ok'];
             }
             $destinations = array();
             foreach ($this->_backup_options->options['steps'] as $step) {
                 if ('send_remote_destination' == $step['function']) {
                     $destinations[] = array('id' => $step['args'][0], 'title' => pb_backupbuddy::$options['remote_destinations'][$step['args'][0]]['title'], 'type' => pb_backupbuddy::$options['remote_destinations'][$step['args'][0]]['type']);
                 }
             }
             pb_backupbuddy::status('details', 'Updating statistics for last backup completed and number of edits since last backup.');
             $finishTime = microtime(true);
             pb_backupbuddy::$options['last_backup_finish'] = $finishTime;
             pb_backupbuddy::$options['last_backup_stats'] = array('archiveFile' => $archiveFile, 'archiveURL' => $downloadURL, 'archiveSize' => $this->_backup['archive_size'], 'start' => pb_backupbuddy::$options['last_backup_start'], 'finish' => $finishTime, 'type' => $this->_backup_options->options['profile']['type'], 'profileTitle' => htmlentities($this->_backup_options->options['profile']['title']), 'scheduleTitle' => $this->_backup_options->options['schedule_title'], 'integrityStatus' => $integrityIsOK, 'destinations' => $destinations);
             //error_log( print_r( pb_backupbuddy::$options['last_backup_stats'], true ) );
             pb_backupbuddy::$options['edits_since_last'] = 0;
             // Reset edit stats for notifying user of how many posts/pages edited since last backup happened.
             pb_backupbuddy::save();
         }
     }
     require_once pb_backupbuddy::plugin_path() . '/classes/housekeeping.php';
     backupbuddy_housekeeping::cleanup_temp_dir();
     if ($this->_backup['trigger'] == 'manual') {
         // Do nothing. No notifications as of pre-3.0 2012.
     } elseif ($this->_backup['trigger'] == 'deployment') {
         // Do nothing. No notifications.
     } elseif ($this->_backup['trigger'] == 'deployment_pulling') {
         // Do nothing.
     } elseif ($this->_backup['trigger'] == 'scheduled') {
         if (false === $fail_mode && false === $cancel_backup) {
             pb_backupbuddy::status('details', __('Sending scheduled backup complete email notification.', 'it-l10n-backupbuddy'));
             $message = 'completed successfully in ' . pb_backupbuddy::$format->time_duration(time() - $this->_backup['start_time']) . ".\n";
             backupbuddy_core::mail_notify_scheduled($this->_backup['serial'], 'complete', __('Scheduled backup', 'it-l10n-backupbuddy') . ' "' . $this->_backup['schedule_title'] . '" ' . $message);
         }
     } else {
         pb_backupbuddy::status('error', 'Error #4343434. Unknown backup trigger `' . $this->_backup['trigger'] . '`.');
     }
     pb_backupbuddy::status('message', __('Finished cleaning up.', 'it-l10n-backupbuddy'));
     if (true === $cancel_backup) {
         pb_backupbuddy::status('details', 'Backup cancellation complete.');
         return false;
     } else {
         if (true === $fail_mode) {
             pb_backupbuddy::status('details', __('As this backup did not pass the integrity check you should verify it manually or re-scan. Integrity checks can fail on good backups due to permissions, large file size exceeding memory limits, etc. You may manually disable integrity check on the Settings page but you will no longer be notified of potentially bad backups.', 'it-l10n-backupbuddy'));
         } else {
             if ($this->_backup['trigger'] != 'deployment' && $this->_backup['trigger'] != 'deployment_pulling') {
                 //$stats = stat( $this->_backup['archive_file'] );
                 //$sizeFormatted = pb_backupbuddy::$format->file_size( $stats['size'] );
                 pb_backupbuddy::status('archiveInfo', json_encode(array('file' => basename($this->_backup['archive_file']), 'url' => pb_backupbuddy::ajax_url('download_archive') . '&backupbuddy_backup=' . basename($this->_backup['archive_file']))));
             }
         }
     }
     return true;
 }