本文整理汇总了PHP中backupbuddy_core::getBackupTypeFromFile方法的典型用法代码示例。如果您正苦于以下问题:PHP backupbuddy_core::getBackupTypeFromFile方法的具体用法?PHP backupbuddy_core::getBackupTypeFromFile怎么用?PHP backupbuddy_core::getBackupTypeFromFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类backupbuddy_core
的用法示例。
在下文中一共展示了backupbuddy_core::getBackupTypeFromFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
public static function send($settings = array(), $file, $send_id = '', $delete_after = false, $clear_uploads = false)
{
$settings = self::_init($settings);
if ('1' == $settings['disabled']) {
self::_error(__('Error #48933: This destination is currently disabled. Enable it under this destination\'s Advanced Settings.', 'it-l10n-backupbuddy'));
return false;
}
if (is_array($file)) {
$file = $files[0];
}
if ('' == $settings['_multipart_id']) {
// New transfer. Populate initial Stash settings.
$file_size = filesize($file);
$remote_path = self::get_remote_path();
// Has leading and trailng slashes.
$backup_type = backupbuddy_core::getBackupTypeFromFile($file);
if ('' == $backup_type) {
// unknown backup type
$backup_type_path = '';
} else {
// known backup type. store in subdir.
$backup_type_path = $backup_type . '/';
}
$additionalParams = array('filename' => $remote_path . $backup_type_path . basename($file), 'size' => $file_size, 'timezone' => get_option('timezone_string'));
$response = self::stashAPI($settings, 'upload', $additionalParams);
if (!is_array($response)) {
$error = 'Error #832973: Unable to initiate Stash (v2) upload. Details: `' . $response . '`.';
self::_error($error);
return false;
}
$backup_type = backupbuddy_core::getBackupTypeFromFile($file);
if (pb_backupbuddy::$options['log_level'] == '3') {
// Full logging enabled.
pb_backupbuddy::status('details', 'Stash API upload action response due to logging level: `' . print_r($response, true) . '`. Call params: `' . print_r($additionalParams, true) . ' `.');
}
$settings['stash_mode'] = '1';
// Stash is calling the s32 destination.
$settings['bucket'] = $response['bucket'];
$settings['credentials'] = $response['credentials'];
$settings['_stash_object'] = $response['object'];
$settings['_stash_upload_id'] = $response['upload_id'];
/*
$settings['_multipart_id'] = $response['upload_id'];
$settings['_multipart_partnumber'] = 0;
$settings['_multipart_file'] = $file;
$settings['_multipart_remotefile'] = $response['object']; //$remote_path . basename( $file );
$settings['_multipart_counts'] = pb_backupbuddy_destination_s32::_get_multipart_counts( $file_size, $settings['max_burst'] * 1024 * 1024 ); // Size of chunks expected to be in bytes.
$settings['_multipart_backup_type'] = $backup_type;
$settings['_multipart_backup_size'] = $file_size;
*/
}
//error_log( print_r( $settings, true ) );
// Send file.
$result = pb_backupbuddy_destination_s32::send($settings, $file, $send_id, $delete_after, $clear_uploads);
if (false === $result) {
// Notify Stash if failure.
self::_uploadFailed($settings);
}
return $result;
}
示例2: strtotime
// Do NOT display any files within a deeper subdirectory.
continue;
}
if (!preg_match(pb_backupbuddy_destination_s3::BACKUP_FILENAME_PATTERN, $file) && 'importbuddy.php' !== $file) {
// Do not display any files that do not appear to be a BackupBuddy backup file (except importbuddy.php).
continue;
}
/*
Unsure whether to include this here or not?
if ( FALSE === ( strpos( $file, 'backup-' . $prefix . '-' ) ) ) { // Not a backup for THIS site. Skip.
continue;
}
*/
$last_modified = strtotime($object->LastModified);
$size = (double) $object->Size;
$backup_type = backupbuddy_core::getBackupTypeFromFile($file);
// Generate array of table rows.
while (isset($backup_list_temp[$last_modified])) {
// Avoid collisions.
$last_modified += 0.1;
}
$backup_list_temp[$last_modified] = array($file, pb_backupbuddy::$format->date(pb_backupbuddy::$format->localize_time($last_modified)) . '<br /><span class="description">(' . pb_backupbuddy::$format->time_ago($last_modified) . ' ago)</span>', pb_backupbuddy::$format->file_size($size), backupbuddy_core::pretty_backup_type($backup_type));
}
krsort($backup_list_temp);
$backup_list = array();
foreach ($backup_list_temp as $backup_item) {
$backup_list[$backup_item[0]] = $backup_item;
}
unset($backup_list_temp);
$urlPrefix = pb_backupbuddy::ajax_url('remoteClient') . '&destination_id=' . htmlentities(pb_backupbuddy::_GET('destination_id'));
// Render table listing files.
示例3: archiveLimit
public static function archiveLimit($settings, $backup_type)
{
if ($backup_type == 'full') {
$limit = $settings['full_archive_limit'];
pb_backupbuddy::status('details', 'Full backup archive limit of `' . $limit . '` of type `full` based on destination settings.');
} elseif ($backup_type == 'db') {
$limit = $settings['db_archive_limit'];
pb_backupbuddy::status('details', 'Database backup archive limit of `' . $limit . '` of type `db` based on destination settings.');
} elseif ($backup_type == 'files') {
$limit = $settings['files_archive_limit'];
pb_backupbuddy::status('details', 'Database backup archive limit of `' . $limit . '` of type `files` based on destination settings.');
} else {
$limit = 0;
pb_backupbuddy::status('warning', 'Warning #237332. Unable to determine backup type (reported: `' . $backup_type . '`) so archive limits NOT enforced for this backup.');
}
if ($limit > 0) {
pb_backupbuddy::status('details', 'Archive limit enforcement beginning.');
// Get file listing.
try {
$response_manage = self::$_client->listObjects(array('Bucket' => $settings['bucket'], 'Prefix' => $settings['directory'] . 'backup-' . backupbuddy_core::backup_prefix()));
// List all users files in this directory that are a backup for this site (limited by prefix).
} catch (Exception $e) {
return self::_error('Error #9338292: Unable to list files for archive limiting. Details: `' . $e->getMessage() . '`.');
}
if (!is_array($response_manage['Contents'])) {
$response_manage['Contents'] = array();
}
// List backups associated with this site by date.
$backups = array();
foreach ($response_manage['Contents'] as $object) {
$file = str_replace($settings['directory'], '', $object['Key']);
if ($backup_type != backupbuddy_core::getBackupTypeFromFile($file, $quiet = true)) {
continue;
// Not of the same backup type.
}
$backups[$file] = strtotime($object['LastModified']);
}
arsort($backups);
pb_backupbuddy::status('details', 'Found `' . count($backups) . '` backups of this type when checking archive limits out of `' . count($response_manage['Contents']) . '` total files in this location.');
if (count($backups) > $limit) {
pb_backupbuddy::status('details', 'More archives (' . count($backups) . ') than limit (' . $limit . ') allows. Trimming...');
$i = 0;
$delete_fail_count = 0;
foreach ($backups as $buname => $butime) {
$i++;
if ($i > $limit) {
pb_backupbuddy::status('details', 'Trimming excess file `' . $buname . '`...');
try {
$response = self::$_client->deleteObject(array('Bucket' => $settings['bucket'], 'Key' => $settings['directory'] . $buname));
} catch (Exception $e) {
self::_error('Unable to delete excess Stash file `' . $buname . '`. Details: `' . $e->getMessage() . '`.');
$delete_fail_count++;
}
}
}
// end foreach.
pb_backupbuddy::status('details', 'Finished trimming excess backups.');
if ($delete_fail_count !== 0) {
$error_message = 'Stash remote limit could not delete ' . $delete_fail_count . ' backups.';
pb_backupbuddy::status('error', $error_message);
backupbuddy_core::mail_error($error_message);
}
}
pb_backupbuddy::status('details', 'Stash completed archive limiting.');
} else {
pb_backupbuddy::status('details', 'No Stash archive file limit to enforce.');
}
// End remote backup limit
return true;
}
示例4: print_r
/*
echo '<br><pre>';
print_r( $file );
echo '</pre>';
*/
if (!preg_match(pb_backupbuddy_destination_s32::BACKUP_FILENAME_PATTERN, $file['basename']) && 'importbuddy.php' !== $file) {
// Do not display any files that do not appear to be a BackupBuddy backup file (except importbuddy.php).
continue;
}
if ('' != $remotePath && !backupbuddy_core::startsWith(basename($file['filename']), $remotePath)) {
// Only show backups for this site unless set to show all.
continue;
}
$last_modified = $file['uploaded_timestamp'];
$size = (double) $file['size'];
$backup_type = backupbuddy_core::getBackupTypeFromFile($file['filename']);
// Generate array of table rows.
while (isset($backup_list_temp[$last_modified])) {
// Avoid collisions.
$last_modified += 0.1;
}
$backup_list_temp[$last_modified] = array(array(base64_encode($file['url']), $file['filename']), pb_backupbuddy::$format->date(pb_backupbuddy::$format->localize_time($last_modified)) . '<br /><span class="description">(' . pb_backupbuddy::$format->time_ago($last_modified) . ' ago)</span>', pb_backupbuddy::$format->file_size($size), backupbuddy_core::pretty_backup_type($backup_type));
}
krsort($backup_list_temp);
$backup_list = array();
foreach ($backup_list_temp as $backup_item) {
$backup_list[$backup_item[0][0]] = $backup_item;
}
unset($backup_list_temp);
$urlPrefix = pb_backupbuddy::ajax_url('remoteClient') . '&destination_id=' . htmlentities(pb_backupbuddy::_GET('destination_id'));
$quota = pb_backupbuddy_destination_stash2::get_quota($settings);
示例5: send
public static function send($settings = array(), $file, $send_id = '', $delete_after = false)
{
global $pb_backupbuddy_destination_errors;
if ('1' == $settings['disabled']) {
$pb_backupbuddy_destination_errors[] = __('Error #48933: This destination is currently disabled. Enable it under this destination\'s Advanced Settings.', 'it-l10n-backupbuddy');
return false;
}
$settings = self::_init($settings);
// Handles formatting & sanitizing settings.
$chunkSizeBytes = $settings['max_burst'] * 1024 * 1024;
// Send X mb at a time to limit memory usage.
self::$_timeStart = microtime(true);
// Initiate multipart upload.
if ('' == $settings['_multipart_id']) {
// New transfer. Note: All transfers are handled as presumed multiparts for ease.
// Handle chunking of file into a multipart upload (if applicable).
$file_size = filesize($file);
pb_backupbuddy::status('details', 'File size of `' . pb_backupbuddy::$format->file_size($file_size) . '`.');
// About to chunk so cleanup any previous hanging multipart transfers.
self::multipart_cleanup($settings);
// Initiate multipart upload with S3.
pb_backupbuddy::status('details', 'Initiating multipart transfer.');
try {
$response = self::$_client->createMultipartUpload(array('Bucket' => $settings['bucket'], 'Key' => $settings['directory'] . basename($file), 'StorageClass' => $settings['storage'], 'ServerSideEncryption' => 'AES256'));
} catch (Exception $e) {
return self::_error('Error #389383: Unable to initiate multipart upload. Details: `' . $e->getMessage() . '`.');
}
// Made it here so SUCCESS initiating multipart!
$upload_id = (string) $response['UploadId'];
pb_backupbuddy::status('details', 'Initiated multipart upload with ID `' . $upload_id . '`.');
$backup_type = backupbuddy_core::getBackupTypeFromFile($file);
// Calculate multipart settings.
$multipart_destination_settings = $settings;
$multipart_destination_settings['_multipart_id'] = $upload_id;
$multipart_destination_settings['_multipart_partnumber'] = 0;
$multipart_destination_settings['_multipart_file'] = $file;
$multipart_destination_settings['_multipart_remotefile'] = $settings['directory'] . basename($file);
$multipart_destination_settings['_multipart_counts'] = self::_get_multipart_counts($file_size, $settings['max_burst'] * 1024 * 1024);
// Size of chunks expected to be in bytes.
$multipart_destination_settings['_multipart_backup_type'] = $backup_type;
$multipart_destination_settings['_multipart_backup_size'] = $file_size;
$multipart_destination_settings['_multipart_etag_parts'] = array();
//pb_backupbuddy::status( 'details', 'Multipart settings to pass:' . print_r( $multipart_destination_settings, true ) );
//$multipart_destination_settings['_multipart_status'] = 'Starting send of ' . count( $multipart_destination_settings['_multipart_counts'] ) . ' parts.';
pb_backupbuddy::status('details', 'Multipart initiated; passing over to send first chunk this run.');
$settings = $multipart_destination_settings;
// Copy over settings.
unset($multipart_destination_settings);
}
// end initiating multipart.
// Send parts.
$backup_type = str_replace('/', '', $settings['_multipart_backup_type']);
// For use later by file limiting.
$backup_size = $settings['_multipart_backup_size'];
$maxTime = $settings['max_time'];
if ('' == $maxTime || !is_numeric($maxTime)) {
pb_backupbuddy::status('details', 'Max time not set in settings so detecting server max PHP runtime.');
$maxTime = backupbuddy_core::detectMaxExecutionTime();
}
pb_backupbuddy::status('details', 'Using max runtime: `' . $maxTime . '`.');
// Open file for streaming.
$f = @fopen($settings['_multipart_file'], 'r');
if (false === $f) {
return self::_error('Error #437734. Unable to open file `' . $settings['_multipart_file'] . '` to send. Did it get deleted?');
}
$fileDone = false;
while (!$fileDone && !feof($f)) {
$sendStart = microtime(true);
// Made it here so success sending part. Increment for next part to send.
$settings['_multipart_partnumber']++;
if (!isset($settings['_multipart_counts'][$settings['_multipart_partnumber'] - 1]['seekTo'])) {
pb_backupbuddy::status('error', 'Error #8239933: Missing multipart partnumber to seek to. Settings array: `' . print_r($settings, true) . '`.');
}
if (-1 == fseek($f, (int) $settings['_multipart_counts'][$settings['_multipart_partnumber'] - 1]['seekTo'])) {
return self::_error('Error #833838: Unable to fseek file.');
}
pb_backupbuddy::status('details', 'Beginning upload of part `' . $settings['_multipart_partnumber'] . '` of `' . count($settings['_multipart_counts']) . '` parts of file `' . $settings['_multipart_file'] . '` to remote location `' . $settings['_multipart_remotefile'] . '` with multipart ID `' . $settings['_multipart_id'] . '`.');
$contentLength = (int) $settings['_multipart_counts'][$settings['_multipart_partnumber'] - 1]['length'];
try {
$uploadArr = array('Bucket' => $settings['bucket'], 'Key' => $settings['_multipart_remotefile'], 'UploadId' => $settings['_multipart_id'], 'PartNumber' => $settings['_multipart_partnumber'], 'ContentLength' => $contentLength, 'Body' => fread($f, $contentLength));
//pb_backupbuddy::status( 'details', 'Send array: `' . print_r( $uploadArr, true ) . '`.' );
$response = self::$_client->uploadPart($uploadArr);
} catch (Exception $e) {
@fclose($f);
return self::_error('Unable to upload file part for multipart upload of ID `' . $settings['_multipart_id'] . '`. Details: `' . $e->getMessage() . '`.');
}
self::$_chunksSentThisRound++;
$settings['_multipart_etag_parts'][] = array('PartNumber' => $settings['_multipart_partnumber'], 'ETag' => $response['ETag']);
if (pb_backupbuddy::$options['log_level'] == '3') {
// Full logging enabled.
pb_backupbuddy::status('details', 'Success sending chunk. Upload details due to log level: `' . print_r($response, true) . '`.');
} else {
pb_backupbuddy::status('details', 'Success sending chunk. Enable full logging for upload result details.');
}
$uploaded_size = $contentLength;
$elapseTime = microtime(true) - $sendStart;
if (0 == $elapseTime) {
$elapseTime = 1;
}
$uploaded_speed = $uploaded_size / $elapseTime;
//.........这里部分代码省略.........
示例6: send
//.........这里部分代码省略.........
$cronHashID = md5($cronTime . serialize($cronArgs));
$cronArgs[] = $cronHashID;
$schedule_result = backupbuddy_core::schedule_single_event($cronTime, pb_backupbuddy::cron_tag('destination_send'), $cronArgs);
if (true === $schedule_result) {
pb_backupbuddy::status('details', 'Next S3 chunk step cron event scheduled.');
} else {
pb_backupbuddy::status('error', 'Next S3 chunk step cron even FAILED to be scheduled.');
}
spawn_cron(time() + 150);
// Adds > 60 seconds to get around once per minute cron running limit.
update_option('_transient_doing_cron', 0);
// Prevent cron-blocking for next item.
return array($settings['_multipart_id'], 'Sent part ' . $this_part_number . ' of ' . count($settings['_multipart_counts']) . ' parts.');
}
} else {
// not multipart continuation
// Handle chunking of file into a multipart upload (if applicable).
$file_size = filesize($file);
if ($settings['max_chunk_size'] >= self::MINIMUM_CHUNK_SIZE && $file_size / 1024 / 1024 > $settings['max_chunk_size']) {
// minimum chunk size is 5mb. Anything under 5mb we will not chunk.
pb_backupbuddy::status('details', 'File size of ' . pb_backupbuddy::$format->file_size($file_size) . ' exceeds max chunk size of ' . $settings['max_chunk_size'] . 'MB set in settings for sending file as multipart upload.');
// About to chunk so cleanup any previous hanging multipart transfers.
self::multipart_cleanup($settings, $lessLogs = false);
// Initiate multipart upload with S3.
pb_backupbuddy::status('details', 'Initiating multipart transfer.');
try {
$response = self::$_client->createMultipartUpload(array('Bucket' => $settings['bucket'], 'Key' => $settings['directory'] . basename($file), 'StorageClass' => $settings['storage'], 'ServerSideEncryption' => 'AES256'));
} catch (Exception $e) {
return self::_error('Error #389383: Unable to initiate multipart upload. Details: `' . $e->getMessage() . '`.');
}
// Made it here so SUCCESS initiating multipart!
$upload_id = (string) $response['UploadId'];
pb_backupbuddy::status('details', 'Initiated multipart upload with ID `' . $upload_id . '`.');
$backup_type = backupbuddy_core::getBackupTypeFromFile($file);
// Calculate multipart settings.
$multipart_destination_settings = $settings;
$multipart_destination_settings['_multipart_id'] = $upload_id;
$multipart_destination_settings['_multipart_partnumber'] = 0;
$multipart_destination_settings['_multipart_file'] = $file;
$multipart_destination_settings['_multipart_remotefile'] = $settings['directory'] . basename($file);
$multipart_destination_settings['_multipart_counts'] = self::_get_multipart_counts($file_size, $settings['max_chunk_size'] * 1024 * 1024);
// Size of chunks expected to be in bytes.
$multipart_destination_settings['_multipart_backup_type'] = $backup_type;
$multipart_destination_settings['_multipart_backup_size'] = $file_size;
pb_backupbuddy::status('details', 'Multipart settings to pass:' . print_r($multipart_destination_settings, true));
// Schedule to process the parts.
pb_backupbuddy::status('details', 'Scheduling send of next part.');
$cronTime = time();
$cronArgs = array($multipart_destination_settings, $file, $send_id, $delete_after);
$cronHashID = md5($cronTime . serialize($cronArgs));
$cronArgs[] = $cronHashID;
backupbuddy_core::schedule_single_event($cronTime, pb_backupbuddy::cron_tag('destination_send'), $cronArgs);
spawn_cron(time() + 150);
// Adds > 60 seconds to get around once per minute cron running limit.
update_option('_transient_doing_cron', 0);
// Prevent cron-blocking for next item.
pb_backupbuddy::status('details', 'Scheduled send of next part(s). Done for this cycle.');
return array($upload_id, 'Starting send of ' . count($multipart_destination_settings['_multipart_counts']) . ' parts.');
} else {
// did not meet chunking criteria.
if ($settings['max_chunk_size'] != '0') {
if ($file_size / 1024 / 1024 > self::MINIMUM_CHUNK_SIZE) {
pb_backupbuddy::status('details', 'File size of ' . pb_backupbuddy::$format->file_size($file_size) . ' is less than the max chunk size of ' . $settings['max_chunk_size'] . 'MB; not chunking into multipart upload.');
} else {
pb_backupbuddy::status('details', 'File size of ' . pb_backupbuddy::$format->file_size($file_size) . ' is less than the minimum allowed chunk size of ' . self::MINIMUM_CHUNK_SIZE . 'MB; not chunking into multipart upload.');
}
示例7: print_r
echo '<br><pre>';
print_r( $file );
echo '</pre>';
*/
/*
if ( ( ! preg_match( pb_backupbuddy_destination_s32::BACKUP_FILENAME_PATTERN, $file['basename'] ) ) && ( 'importbuddy.php' !== $file ) ) { // Do not display any files that do not appear to be a BackupBuddy backup file (except importbuddy.php).
continue;
}
*/
if ('' != $remotePath && !backupbuddy_core::startsWith(basename($file['filename']), $remotePath)) {
// Only show backups for this site unless set to show all.
continue;
}
$last_modified = $file['uploaded_timestamp'];
$size = (double) $file['size'];
$backup_type = backupbuddy_core::getBackupTypeFromFile($file['filename'], $quiet = false, $skip_fileoptions = true);
// Generate array of table rows.
while (isset($backup_list_temp[$last_modified])) {
// Avoid collisions.
$last_modified += 0.1;
}
if ('live' == $destination['type']) {
$backup_list_temp[$last_modified] = array(array(base64_encode($file['url']), '<span class="backupbuddy-stash-file-list-title">' . pb_backupbuddy::$format->date(pb_backupbuddy::$format->localize_time($last_modified)) . ' <span class="description">(' . pb_backupbuddy::$format->time_ago($last_modified) . ' ago)</span></span><br><span title="' . $file['filename'] . '">' . basename($file['filename']) . '</span>'), pb_backupbuddy::$format->date(pb_backupbuddy::$format->localize_time($last_modified)) . '<br /><span class="description">(' . pb_backupbuddy::$format->time_ago($last_modified) . ' ago)</span>', pb_backupbuddy::$format->file_size($size), backupbuddy_core::pretty_backup_type($backup_type));
} else {
$backup_list_temp[$last_modified] = array(array(base64_encode($file['url']), '<span title="' . $file['filename'] . '">' . basename($file['filename']) . '</span>'), pb_backupbuddy::$format->date(pb_backupbuddy::$format->localize_time($last_modified)) . '<br /><span class="description">(' . pb_backupbuddy::$format->time_ago($last_modified) . ' ago)</span>', pb_backupbuddy::$format->file_size($size), backupbuddy_core::pretty_backup_type($backup_type));
}
}
krsort($backup_list_temp);
$backup_list = array();
foreach ($backup_list_temp as $backup_item) {
$backup_list[$backup_item[0][0]] = $backup_item;