Exemplo n.º 1
0
/**
 * Receive the heartbeat and return backup status
 */
function heartbeat_received($response, $data)
{
    $response['heartbeat_interval'] = 'fast';
    if (!empty($data['hmbkp_schedule_id'])) {
        $schedule = new Scheduled_Backup(sanitize_text_field(urldecode($data['hmbkp_schedule_id'])));
        $status = new Backup_Status($schedule->get_id());
        if (!empty($data['hmbkp_is_in_progress'])) {
            if (!$status->get_status()) {
                $response['hmbkp_schedule_status'] = 0;
                // Slow the heartbeat back down
                $response['heartbeat_interval'] = 'slow';
            } else {
                $response['hmbkp_schedule_status'] = schedule_status($schedule, false);
            }
        }
        if (!empty($data['hmbkp_client_request'])) {
            $site_size = new Site_Size($schedule->get_type(), $schedule->get_excludes());
            // Pass the site size to be displayed when it's ready.
            if ($site_size->is_site_size_cached()) {
                $response['hmbkp_site_size'] = $site_size->get_formatted_site_size();
                ob_start();
                require HMBKP_PLUGIN_PATH . 'admin/schedule-form-excludes.php';
                $response['hmbkp_dir_sizes'] = ob_get_clean();
                // Slow the heartbeat back down
                $response['heartbeat_interval'] = 'slow';
            }
        }
    }
    return $response;
}
Exemplo n.º 2
0
				<td>

					<input type="number" id="hmbkp_schedule_max_backups" name="hmbkp_schedule_max_backups" min="1" step="1" value="<?php 
echo esc_attr($schedule->get_max_backups());
?>
" />

					<p class="description">

						<?php 
printf(__('Past this limit older backups will be deleted automatically.', 'backupwordpress'));
?>

						<?php 
$site_size = new Site_Size($schedule->get_type(), $schedule->get_excludes());
if ($site_size->is_site_size_cached()) {
    printf(__('This schedule will store a maximum of %s of backups.', 'backupwordpress'), '<code>' . esc_html(size_format($site_size->get_site_size() * $schedule->get_max_backups())) . '</code>');
}
?>

					</p>

				</td>

			</tr>

			<?php 
foreach (Services::get_services($schedule) as $service) {
    $service->field();
}
?>
/**
 * Returns a formatted string containing the calculated total site size or a message
 * to indicate it is being calculated.
 *
 * @param HM\BackUpWordPress\Scheduled_Backup $schedule
 *
 * @return string
 */
function get_site_size_text(Scheduled_Backup $schedule)
{
    if (isset($_GET['hmbkp_add_schedule'])) {
        return '';
    }
    $site_size = new Site_Size($schedule->get_type(), $schedule->get_excludes());
    if ('database' === $schedule->get_type() || $site_size->is_site_size_cached()) {
        return sprintf('(<code title="' . __('Backups will be compressed and should be smaller than this.', 'backupwordpress') . '">%s</code>)', esc_html($site_size->get_formatted_site_size()));
    }
    return '';
}
Exemplo n.º 4
0
 /**
  * @return array
  */
 public static function test()
 {
     $backup_sizes = array();
     $schedules = Schedules::get_instance();
     foreach ($schedules->get_schedules() as $schedule) {
         $site_size = new Site_Size($schedule->get_type(), $schedule->get_excludes());
         if ($site_size->is_site_size_cached()) {
             $backup_sizes[$schedule->get_type()] = $site_size->get_formatted_site_size();
         }
     }
     return $backup_sizes;
 }
Exemplo n.º 5
0
				<td>

					<input type="number" id="hmbkp_schedule_max_backups" name="hmbkp_schedule_max_backups" min="1" step="1" value="<?php 
echo esc_attr($schedule->get_max_backups());
?>
" />

					<p class="description">

						<?php 
printf(__('Past this limit older backups will be deleted automatically.', 'backupwordpress'));
?>

						<?php 
$site_size = new Site_Size();
if (Site_Size::is_site_size_cached()) {
    printf(__('This schedule will store a maximum of %s of backups.', 'backupwordpress'), '<code>' . esc_html(size_format($site_size->get_site_size($schedule->get_type(), $schedule->get_excludes()) * $schedule->get_max_backups())) . '</code>');
}
?>

					</p>

				</td>

			</tr>

			<?php 
foreach (Services::get_services($schedule) as $service) {
    $service->field();
}
?>
/**
 * Returns a formatted string containing the calculated total site size or a message
 * to indicate it is being calculated.
 *
 * @param HM\BackUpWordPress\Scheduled_Backup $schedule
 *
 * @return string
 */
function get_site_size_text(Scheduled_Backup $schedule)
{
    if (isset($_GET['hmbkp_add_schedule'])) {
        return '';
    }
    $site_size = new Site_Size($schedule->get_type(), $schedule->get_excludes());
    if ('database' === $schedule->get_type() || $site_size->is_site_size_cached()) {
        return sprintf('(<code title="' . __('Backups will be compressed and should be smaller than this.', 'backupwordpress') . '">%s</code>)', esc_attr($site_size->get_formatted_site_size()));
    } else {
        return sprintf('(<code class="calculating" title="' . __('this shouldn\'t take long&hellip;', 'backupwordpress') . '">' . __('calculating the size of your site&hellip;', 'backupwordpress') . '</code>)');
    }
}
Exemplo n.º 7
0
/**
 * Check whether the server is low on disk space.
 *
 * @return bool Whether there's less disk space less than 2 * the entire size of the site.
 */
function disk_space_low($backup_size = false)
{
    $disk_space = @disk_free_space(Path::get_path());
    if (!$disk_space) {
        return false;
    }
    if (!$backup_size) {
        $site_size = new Site_Size('complete', new Excludes());
        if (!$site_size->is_site_size_cached()) {
            return false;
        }
        $backup_size = $site_size->get_site_size() * 2;
    }
    return $backup_size >= $disk_space;
}