本文整理汇总了PHP中backupbuddy_core::getLogDirectory方法的典型用法代码示例。如果您正苦于以下问题:PHP backupbuddy_core::getLogDirectory方法的具体用法?PHP backupbuddy_core::getLogDirectory怎么用?PHP backupbuddy_core::getLogDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类backupbuddy_core
的用法示例。
在下文中一共展示了backupbuddy_core::getLogDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate_queue
public function generate_queue($root = '', $generate_sha1 = true)
{
if ($root == '') {
$root = backupbuddy_core::getLogDirectory();
}
echo 'mem:' . memory_get_usage(true) . '<br>';
$files = (array) pb_backupbuddy::$filesystem->deepglob($root);
echo 'mem:' . memory_get_usage(true) . '<br>';
$root_len = strlen($root);
$new_files = array();
foreach ($files as $file_id => &$file) {
$stat = stat($file);
if (FALSE === $stat) {
pb_backupbuddy::status('error', 'Unable to read file `' . $file . '` stat.');
}
$new_file = substr($file, $root_len);
$sha1 = '';
if (true === $generate_sha1 && $stat['size'] < 1073741824) {
// < 100mb
$sha1 = sha1_file($file);
}
$new_files[$new_file] = array('scanned' => time(), 'size' => $stat['size'], 'modified' => $stat['mtime'], 'sha1' => $sha1);
unset($files[$file_id]);
// Better to free memory or leave out for performance?
}
unset($files);
echo 'mem:' . memory_get_usage(true) . '<br>';
function pb_queuearray_size_compare($a, $b)
{
return $a['size'] > $b['size'];
}
uasort($new_files, 'pb_queuearray_size_compare');
echo '<pre>';
print_r($new_files);
echo '</pre>';
// fileoptions file live_signatures.txt
//backupbuddy_core::st_stable_options( 'xxx', 'test', 5 );
// get file listing of site: glob and store in an array
// open previously generated master list (master file listing since last queue generation).
// loop through and compare file specs to specs in master list. ( anything changed AND not yet in queue AND not maxed out send attempts ) gets added into $queue_files[];
// add master file to end of list so it will be backed up as soon files are finished sending. to keep it up to date.
// sort list smallest to largest
// store in $queue_files[] in format:
/*
array(
'size' => 434344,
'attempts' => 0,
);
*/
// open current queue file (if exists)
// combine new files into queue
// serialize $queue_files
// base64 encode
// write to queue file
pb_backupbuddy::status('details', '12 new or modified files added into Stash queue.');
// Schedule process_queue() to run in 30 seconds from now _IF_ not already scheduled to run.
}
示例2: shutdown_function
function shutdown_function()
{
// Get error message.
// Error types: http://php.net/manual/en/errorfunc.constants.php
$e = error_get_last();
if ($e === NULL) {
// No error of any kind.
return;
} else {
// Some type of error.
if (!is_array($e) || $e['type'] != E_ERROR && $e['type'] != E_USER_ERROR) {
// Return if not a fatal error.
//echo '<!-- ' . print_r( $e, true ) . ' -->' . "\n";
return;
}
}
// Calculate log directory.
$log_directory = backupbuddy_core::getLogDirectory();
// Also handle when in importbuddy.
$main_file = $log_directory . 'log-' . pb_backupbuddy::$options['log_serial'] . '.txt';
// Determine if writing to a serial log.
if (pb_backupbuddy::$_status_serial != '') {
$serial = pb_backupbuddy::$_status_serial;
$serial_file = $log_directory . 'status-' . $serial . '_' . pb_backupbuddy::$options['log_serial'] . '.txt';
$write_serial = true;
} else {
$write_serial = false;
}
// Format error message.
$e_string = '----- FATAL ERROR ----- A fatal PHP error was encountered: ';
foreach ((array) $e as $e_line_title => $e_line) {
$e_string .= $e_line_title . ' => ' . $e_line . "; ";
}
$e_string = rtrim($e_string, '; ') . '.';
// Write to log.
@file_put_contents($main_file, $e_string, FILE_APPEND);
// IMPORTBUDDY
$status = pb_backupbuddy::$format->date(time()) . "\t" . sprintf("%01.2f", round(microtime(true) - pb_backupbuddy::$start_time, 2)) . "\t" . sprintf("%01.2f", round(memory_get_peak_usage() / 1048576, 2)) . "\t" . 'error' . "\t\t" . str_replace(chr(9), ' ', $e_string);
$status = str_replace('\\', '/', $status);
echo '<script type="text/javascript">pb_status_append("' . str_replace('"', '"', $status) . '");</script>';
}
示例3: destination_send
public function destination_send($destination_settings, $files, $send_id = '', $delete_after = false, $identifier = '', $isRetry = false)
{
pb_backupbuddy::status('details', 'Beginning cron destination_send. Unique ID: `' . $identifier . '`.');
if ('' != $identifier) {
$lockFile = backupbuddy_core::getLogDirectory() . 'cronSend-' . $identifier . '.lock';
pb_backupbuddy::anti_directory_browsing(backupbuddy_core::getTempDirectory(), $die = false);
if (@file_exists($lockFile)) {
// Lock exists already. Duplicate run?
$attempts = @file_get_contents($lockFile);
$attempts++;
pb_backupbuddy::status('warning', 'Lock file exists and now shows ' . $attempts . ' attempts.');
$attempts = @file_get_contents($lockFile, $attempts);
return;
} else {
// No lock yet.
if (false === @file_put_contents($lockFile, '1')) {
pb_backupbuddy::status('warning', 'Unable to create destination send lock file `' . $lockFile . '`.');
} else {
pb_backupbuddy::status('details', 'Create destination send lock file `' . $lockFile . '`.');
}
}
}
pb_backupbuddy::status('details', 'Launching destination send via cron.');
if (!class_exists('backupbuddy_core')) {
require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
}
if (true === backupbuddy_core::destination_send($destination_settings, $files, $send_id, $delete_after, $isRetry)) {
// completely finished, go ahead and clean up lock file.
/* DO not delete here as we need to keep this locked down a little longer...
if ( '' != $identifier ) {
if ( true === @unlink( $lockFile ) ) {
pb_backupbuddy::status( 'details', 'Removed destination lock file.' );
} else {
pb_backupbuddy::status( 'warning', 'Unable to remove destination lock file `' . $lockFile . '`.' );
}
}
*/
}
}
示例4: array
}
}
}
// end foreach.
// Mark any timed out remote sends as timed out.
$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_obj = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $send_id . '.txt', $read_only = false, $ignore_lock = false, $create_file = false);
if (true !== ($result = $fileoptions_obj->is_ok())) {
pb_backupbuddy::status('error', __('Fatal Error #9034.32393. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
return false;
}
// 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.
示例5: send
//.........这里部分代码省略.........
$dataRemains = false;
}
$isFileTest = false;
if (false !== stristr(basename($file), 'remote-send-test.php')) {
$isFileTest = true;
$settings['sendType'] = 'test';
}
if (true === $dataRemains) {
$isFileDone = false;
} else {
$isFileDone = true;
}
if (!isset($size)) {
$size = '';
}
pb_backupbuddy::status('details', 'Connecting to remote server to send data.');
$response = backupbuddy_remote_api::remoteCall($apiSettings, 'sendFile_' . $settings['sendType'], array(), $settings['max_time'], $file, $fileData, $prevPointer, $isFileTest, $isFileDone, $size, $filePath);
unset($fileData);
// Free up memory.
$settings['chunks_sent']++;
if (true === $dataRemains) {
// More chunks remain.
pb_backupbuddy::status('details', 'Connection finished sending part ' . $settings['chunks_sent'] . ' of ~' . $settings['chunks_total'] . '.');
} else {
// No more chunks remain.
pb_backupbuddy::status('details', 'Connection finished sending final part ' . $settings['chunks_sent'] . '.');
}
if (false === $response) {
echo implode(', ', backupbuddy_remote_api::getErrors()) . ' ';
pb_backupbuddy::status('error', 'Errors encountered details: ' . implode(', ', backupbuddy_remote_api::getErrors()));
global $pb_backupbuddy_destination_errors;
$pb_backupbuddy_destination_errors[] = backupbuddy_remote_api::getErrors();
return false;
//implode( ', ', backupbuddy_remote_api::getErrors() );
}
if (FALSE === ($prevPointer = ftell($fs))) {
pb_backupbuddy::status('error', 'Error #438347844: Unable to get ftell pointer of file handle for passing to prevPointer.');
@fclose($fs);
return false;
} else {
pb_backupbuddy::status('details', 'File pointer: `' . $prevPointer . '`.');
}
if (true === $dataRemains) {
// More data remains so see if we need to consider chunking to a new PHP process.
// If we are within X second of reaching maximum PHP runtime then stop here so that it can be picked up in another PHP process...
if (microtime(true) - self::$_timeStart + self::TIME_WIGGLE_ROOM >= $settings['max_time']) {
pb_backupbuddy::status('message', 'Approaching limit of available PHP chunking time of `' . $settings['max_time'] . '` sec. Ran for ' . round(microtime(true) - self::$_timeStart, 3) . ' sec. Proceeding to use chunking.');
@fclose($fs);
// Tells next chunk where to pick up.
$settings['resume_point'] = $prevPointer;
// Schedule cron.
$cronTime = time();
$cronArgs = array($settings, $files, $send_id, $delete_after);
$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 Site chunk step cron event scheduled.');
} else {
pb_backupbuddy::status('error', 'Next Site 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($prevPointer, 'Sent part ' . $settings['chunks_sent'] . ' of ~' . $settings['chunks_total'] . ' parts.');
// filepointer location, elapsed time during the import
} else {
// End if.
pb_backupbuddy::status('details', 'Not approaching time limit.');
}
} else {
pb_backupbuddy::status('details', 'No more data remains (eg for chunking) so finishing up.');
}
}
// end while data remains in file.
// Update fileoptions stats.
pb_backupbuddy::status('details', 'About to load fileoptions data.');
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
pb_backupbuddy::status('details', 'Fileoptions instance #20.');
$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 !== ($result = $fileoptions_obj->is_ok())) {
pb_backupbuddy::status('error', __('Fatal Error #9034.279327. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
return false;
}
pb_backupbuddy::status('details', 'Fileoptions data loaded.');
$fileoptions =& $fileoptions_obj->options;
$fileoptions['finish_time'] = microtime(true);
$fileoptions['status'] = 'success';
$fileoptions['_multipart_status'] = 'Sent all parts.';
if (isset($uploaded_speed)) {
$fileoptions['write_speed'] = $uploaded_speed;
}
$fileoptions_obj->save();
unset($fileoptions);
// Made it this far so completed!
pb_backupbuddy::status('message', 'Finished sending file. Took ' . round(microtime(true) - self::$_timeStart, 3) . ' seconds this round.');
pb_backupbuddy::status('deployFileSent', 'File sent.');
return true;
}
示例6: unset
pb_backupbuddy::status('details', 'Cleaned up stale local destination `' . $destination_id . '`.');
unset(pb_backupbuddy::$options['remote_destinations'][$destination_id]);
pb_backupbuddy::save();
}
}
}
// Cleanup excess remote sending stats.
pb_backupbuddy::status('details', 'Cleaning up remote send stats.');
backupbuddy_core::trim_remote_send_stats($backup_age_limit);
// Verify directory existance and anti-directory browsing is in place everywhere.
backupbuddy_core::verify_directories($skipTempGeneration = true);
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
// Mark any backups noted as in progress to timed out if taking too long. Send error email is scheduled and failed or timed out.
// Also, Purge fileoptions files without matching backup file in existance that are older than 30 days.
pb_backupbuddy::status('details', 'Cleaning up old backup fileoptions option files.');
$fileoptions_directory = backupbuddy_core::getLogDirectory() . 'fileoptions/';
$files = glob($fileoptions_directory . '*.txt');
if (!is_array($files)) {
$files = array();
}
foreach ($files as $file) {
pb_backupbuddy::status('details', 'Fileoptions instance #43.');
$backup_options = new pb_backupbuddy_fileoptions($file, $read_only = true);
if (true !== ($result = $backup_options->is_ok())) {
pb_backupbuddy::status('error', 'Error retrieving fileoptions file `' . $file . '`. Err 335353266.');
} else {
if (isset($backup_options->options['archive_file'])) {
//error_log( print_r( $backup_options->options, true ) );
if ($backup_options->options['finish_time'] >= $backup_options->options['start_time'] && 0 != $backup_options->options['start_time']) {
// Completed
} elseif ($backup_options->options['finish_time'] == -1) {
示例7: elseif
} elseif ($remote_send['status'] == 'timeout') {
$status = '<span class="pb_label pb_label-warning">In progress or timed out</span>';
// <a class="pb_backupbuddy_remotesend_abort" href="' . pb_backupbuddy::ajax_url( 'remotesend_abort' ) . '&send_id=' . $send_id . '">( Abort )</a>';
} elseif ($remote_send['status'] == 'aborted') {
$status = '<span class="pb_label pb_label-warning">Aborted by user</span>';
} elseif ($remote_send['status'] == 'multipart') {
$status = '<span class="pb_label pb_label-info">Multipart transfer</span>';
// <a class="pb_backupbuddy_remotesend_abort" href="' . pb_backupbuddy::ajax_url( 'remotesend_abort' ) . '&send_id=' . $send_id . '">( Abort )</a>';
} else {
$status = '<span class="pb_label pb_label-important">' . ucfirst($remote_send['status']) . '</span>';
}
if (isset($remote_send['_multipart_status'])) {
$status .= '<br>' . $remote_send['_multipart_status'];
}
// Display 'View Log' link if log available for this send.
$log_file = backupbuddy_core::getLogDirectory() . 'status-remote_send-' . $send_id . '_' . pb_backupbuddy::$options['log_serial'] . '.txt';
if (file_exists($log_file)) {
$status .= '<br><a title="' . __('Backup Process Technical Details', 'it-l10n-backupbuddy') . '" href="' . pb_backupbuddy::ajax_url('remotesend_details') . '&send_id=' . $send_id . '&TB_iframe=1&width=640&height=600" class="thickbox">View Log</a>';
}
// Determine destination.
if (isset(pb_backupbuddy::$options['remote_destinations'][$remote_send['destination']])) {
// Valid destination.
$destination = pb_backupbuddy::$options['remote_destinations'][$remote_send['destination']]['title'] . ' (' . pb_backupbuddy::$options['remote_destinations'][$remote_send['destination']]['type'] . ')';
} else {
// Invalid destination (been deleted since send?).
$destination = '<span class="description">Unknown</span>';
}
$write_speed = '';
if (isset($remote_send['write_speed']) && '' != $remote_send['write_speed']) {
$write_speed = 'Transfer Speed: ' . pb_backupbuddy::$format->file_size($remote_send['write_speed']) . '/sec<br>';
}
示例8: __
$parent_class_test['status'] = __('OK', 'it-l10n-backupbuddy');
array_push($tests, $parent_class_test);
/***** BEGIN AVERAGE WRITE SPEED *****/
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
$write_speed_samples = 0;
$write_speed_sum = 0;
$backups = glob(backupbuddy_core::getBackupDirectory() . '*.zip');
if (!is_array($backups)) {
$backups = array();
}
foreach ($backups as $backup) {
$serial = backupbuddy_core::get_serial_from_file($backup);
pb_backupbuddy::status('details', 'Fileoptions instance #22.');
$backup_options = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt', $read_only = true);
if (true !== ($result = $backup_options->is_ok())) {
pb_backupbuddy::status('warning', 'Unable to open fileoptions file `' . backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt' . '`. Details: `' . $result . '`.');
}
if (isset($backup_options->options['integrity']) && isset($backup_options->options['integrity']['size'])) {
$write_speed_samples++;
$size = $backup_options->options['integrity']['size'];
$time_taken = 0;
if (isset($backup_options->options['steps'])) {
foreach ($backup_options->options['steps'] as $step) {
if ($step['function'] == 'backup_zip_files') {
$time_taken = $step['finish_time'] - $step['start_time'];
break;
}
}
// End foreach.
}
// End if steps isset.
示例9: send
public static function send($settings = array(), $files = array(), $send_id = '', $delete_after = false)
{
if (!is_array($files)) {
$files = array($files);
}
pb_backupbuddy::status('details', 'Dropbox2 send function started. Remote send id: `' . $send_id . '`.');
// Normalize settings, apply defaults, etc.
$settings = self::_normalizeSettings($settings);
// Connect to Dropbox.
if (false === self::_connect($settings['access_token'])) {
// Try to connect. Return false if fail.
return false;
}
$max_chunk_size_bytes = $settings['max_chunk_size'] * 1024 * 1024;
/***** BEGIN MULTIPART CHUNKED CONTINUE *****/
// Continue Multipart Chunked Upload
if ($settings['_chunk_upload_id'] != '') {
$file = $settings['_chunk_file'];
pb_backupbuddy::status('details', 'Dropbox (PHP 5.3+) preparing to send chunked multipart upload part ' . ($settings['_chunk_sent_count'] + 1) . ' of ' . $settings['_chunk_total_count'] . ' with set chunk size of `' . $settings['max_chunk_size'] . '` MB. Dropbox Upload ID: `' . $settings['_chunk_upload_id'] . '`.');
pb_backupbuddy::status('details', 'Opening file `' . basename($file) . '` to send.');
$f = @fopen($file, 'rb');
if (false === $f) {
pb_backupbuddy::status('error', 'Error #87954435. Unable to open file `' . $file . '` to send to Dropbox.');
return false;
}
// Seek to next chunk location.
pb_backupbuddy::status('details', 'Seeking file to byte `' . $settings['_chunk_next_offset'] . '`.');
if (0 != fseek($f, $settings['_chunk_next_offset'])) {
// return of 0 is success.
pb_backupbuddy::status('error', 'Unable to seek file to proper location offset `' . $settings['_chunk_next_offset'] . '`.');
} else {
pb_backupbuddy::status('details', 'Seek success.');
}
// Read this file chunk into memory.
pb_backupbuddy::status('details', 'Reading chunk into memory.');
try {
$data = self::readFully($f, $settings['_chunk_maxsize']);
} catch (\Exception $e) {
pb_backupbuddy::status('error', 'Dropbox Error #484938376: ' . $e->getMessage());
return false;
}
pb_backupbuddy::status('details', 'About to put chunk to Dropbox for continuation.');
$send_time = -microtime(true);
try {
$result = self::$_dbxClient->chunkedUploadContinue($settings['_chunk_upload_id'], $settings['_chunk_next_offset'], $data);
} catch (\Exception $e) {
pb_backupbuddy::status('error', 'Dropbox Error #8754646: ' . $e->getMessage());
return false;
}
// Examine response from Dropbox.
if (true === $result) {
// Upload success.
pb_backupbuddy::status('details', 'Chunk upload continuation success with valid offset.');
} elseif (false === $result) {
// Failed.
pb_backupbuddy::status('error', 'Chunk upload continuation failed at offset `' . $settings['_chunk_next_offset'] . '`.');
return false;
} elseif (is_numeric($result)) {
// offset wrong. Update to use this.
pb_backupbuddy::status('details', 'Chunk upload continuation received an updated offset response of `' . $result . '` when we tried `' . $settings['_chunk_next_offset'] . '`.');
$settings['_chunk_next_offset'] = $result;
// Try resending with corrected offset.
try {
$result = self::$_dbxClient->chunkedUploadContinue($settings['_chunk_upload_id'], $settings['_chunk_next_offset'], $data);
} catch (\Exception $e) {
pb_backupbuddy::status('error', 'Dropbox Error #8263836: ' . $e->getMessage());
return false;
}
}
$send_time += microtime(true);
$data_length = strlen($data);
unset($data);
// Calculate some stats to log.
$chunk_transfer_speed = $data_length / $send_time;
pb_backupbuddy::status('details', 'Dropbox chunk transfer stats - Sent: `' . pb_backupbuddy::$format->file_size($data_length) . '`, Transfer duration: `' . $send_time . '`, Speed: `' . pb_backupbuddy::$format->file_size($chunk_transfer_speed) . '`.');
// Set options for subsequent step chunks.
$chunked_destination_settings = $settings;
$chunked_destination_settings['_chunk_offset'] = $data_length;
$chunked_destination_settings['_chunk_sent_count']++;
$chunked_destination_settings['_chunk_next_offset'] = $data_length * $chunked_destination_settings['_chunk_sent_count'];
// First chunk was sent initiationg multipart send.
$chunked_destination_settings['_chunk_transfer_speeds'][] = $chunk_transfer_speed;
// Load destination fileoptions.
pb_backupbuddy::status('details', 'About to load fileoptions data.');
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
pb_backupbuddy::status('details', 'Fileoptions instance #15.');
$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 !== ($result = $fileoptions_obj->is_ok())) {
pb_backupbuddy::status('error', __('Fatal Error #9034.84838. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
return false;
}
pb_backupbuddy::status('details', 'Fileoptions data loaded.');
$fileoptions =& $fileoptions_obj->options;
// Multipart send completed. Send finished signal to Dropbox to seal the deal.
if (true === feof($f)) {
pb_backupbuddy::status('details', 'At end of file. Finishing transfer and notifying Dropbox of file transfer completion.');
$chunked_destination_settings['_chunk_upload_id'] = '';
// Unset since chunking finished.
try {
$result = self::$_dbxClient->chunkedUploadFinish($settings['_chunk_upload_id'], $settings['directory'] . '/' . basename($file), dbx\WriteMode::add());
//.........这里部分代码省略.........
示例10: test
public static function test($settings)
{
$settings = self::_init($settings);
$sendOK = false;
$deleteOK = false;
$send_id = 'TEST-' . pb_backupbuddy::random_string(12);
// Try sending a file.
if ('1' == $settings['stash_mode']) {
// Stash mode.
$settings['type'] = 'stash2';
}
$send_response = pb_backupbuddy_destinations::send($settings, dirname(dirname(__FILE__)) . '/remote-send-test.php', $send_id);
// 3rd param true forces clearing of any current uploads.
if (true === $send_response) {
$send_response = __('Success.', 'it-l10n-backupbuddy');
$sendOK = true;
} else {
global $pb_backupbuddy_destination_errors;
$send_response = 'Error sending test file to S3 (v2). Details: `' . implode(', ', $pb_backupbuddy_destination_errors) . '`.';
}
pb_backupbuddy::add_status_serial('remote_send-' . $send_id);
// Delete sent file if it was sent.
$delete_response = 'n/a';
if (true === $sendOK) {
pb_backupbuddy::status('details', 'Preparing to delete sent test file.');
if ('1' == $settings['stash_mode']) {
// Stash mode.
if (true === ($delete_response = pb_backupbuddy_destination_stash2::deleteFile($settings, 'remote-send-test.php'))) {
// success
$delete_response = __('Success.', 'it-l10n-backupbuddy');
$deleteOK = true;
} else {
// error
$error = 'Unable to delete Stash test file `remote-send-test.php`. Details: `' . $delete_response . '`.';
$delete_response = $error;
$deleteOK = false;
}
} else {
// S3 mode.
if (true === ($delete_response = self::deleteFile($settings, 'remote-send-test.php'))) {
$delete_response = __('Success.', 'it-l10n-backupbuddy');
$deleteOK = true;
} else {
$error = 'Unable to delete test file `remote-send-test.php`. Details: `' . $delete_response . '`.';
pb_backupbuddy::status('details', $error);
$delete_response = $error;
$deleteOK = false;
}
}
} else {
// end if $sendOK.
pb_backupbuddy::status('details', 'Skipping test delete due to failed send.');
}
// Load destination fileoptions.
pb_backupbuddy::status('details', 'About to load fileoptions data.');
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
pb_backupbuddy::status('details', 'Fileoptions instance #7.');
$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 !== ($result = $fileoptions_obj->is_ok())) {
return self::_error(__('Fatal Error #9034.84838. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
}
pb_backupbuddy::status('details', 'Fileoptions data loaded.');
$fileoptions =& $fileoptions_obj->options;
if (true !== $sendOK || true !== $deleteOK) {
$fileoptions['status'] = 'failure';
$fileoptions_obj->save();
unset($fileoptions_obj);
return 'Send details: `' . $send_response . '`. Delete details: `' . $delete_response . '`.';
} else {
$fileoptions['status'] = 'success';
$fileoptions['finish_time'] = time();
}
$fileoptions_obj->save();
unset($fileoptions_obj);
pb_backupbuddy::status('details', 'Finished test function.');
return true;
}
示例11: process_backup
function process_backup($serial, $trigger = 'manual')
{
pb_backupbuddy::status('details', 'Running process_backup() for serial `' . $serial . '`.');
// Assign reference to backup data structure for this backup.
if (!isset($this->_backup_options)) {
pb_backupbuddy::status('details', 'About to load fileoptions data.');
$attempt_transient_prefix = 'pb_backupbuddy_lock_attempts-';
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
$this->_backup_options = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/' . $serial . '.txt');
if (true !== ($result = $this->_backup_options->is_ok())) {
// Unable to access fileoptions.
$attempt_delay_base = 10;
// Base number of seconds to delay. Each subsequent attempt increases this delay by a multiple of the attempt number.
$max_attempts = 8;
// Max number of attempts to try to delay around a file lock. Delay increases each time.
$this->_backup['serial'] = $serial;
// Needs to be populated for use by cron schedule step.
pb_backupbuddy::status('warning', __('Warning #9034 B. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Warning: ' . $result, $serial);
// Track lock attempts in transient system. This is not vital & since locks may be having issues track this elsewhere.
$lock_attempts = get_transient($attempt_transient_prefix . $serial);
if (false === $lock_attempts) {
$lock_attempts = 0;
}
$lock_attempts++;
set_transient($attempt_transient_prefix . $serial, $lock_attempts, 60 * 60 * 24);
// Increment lock attempts. Hold attempt count for 24 hours to help make sure we don't lose attempt count if very low site activity, etc.
if ($lock_attempts > $max_attempts) {
pb_backupbuddy::status('error', 'Backup halted. Maximum number of attempts made attempting to access locked fileoptions file. This may be caused by something causing backup steps to run out of order or file permission issues on the temporary directory holding the file `' . $fileoptions_file . '`. Verify correct permissions.', $serial);
pb_backupbuddy::status('action', 'halt_script', $serial);
// Halt JS on page.
delete_transient($attempt_transient_prefix . $serial);
return false;
}
$wait_time = $attempt_delay_base * $lock_attempts;
pb_backupbuddy::status('message', 'A scheduled step attempted to run before the previous step completed. The previous step may have failed or two steps may be attempting to run simultaneously.', $serial);
pb_backupbuddy::status('message', 'Waiting `' . $wait_time . '` seconds before continuing. Attempt #' . $lock_attempts . ' of ' . $max_attempts . ' max allowed before giving up.', $serial);
$this->cron_next_step(false, $wait_time);
return false;
//pb_backupbuddy::status( 'action', 'halt_script' ); // Halt JS on page.
//return false;
} else {
// Accessed fileoptions. Clear/reset any attempt count.
delete_transient($attempt_transient_prefix . $serial);
}
pb_backupbuddy::status('details', 'Fileoptions data loaded.');
$this->_backup =& $this->_backup_options->options;
}
// Handle cancelled backups (stop button).
if (true == get_transient('pb_backupbuddy_stop_backup-' . $serial)) {
// Backup flagged for stoppage. Proceed directly to cleanup.
pb_backupbuddy::status('message', 'Backup STOPPED. Post backup cleanup step has been scheduled to clean up any temporary files.');
foreach ($this->_backup['steps'] as $step_id => $step) {
if ($step['function'] != 'post_backup') {
if ($step['start_time'] == 0) {
$this->_backup['steps'][$step_id]['start_time'] = -1;
// Flag for skipping.
}
} else {
// Post backup step.
$this->_backup['steps'][$step_id]['args'] = array(true, true);
// Run post_backup in fail mode & delete backup file.
}
}
//pb_backupbuddy::save();
$this->_backup_options->save();
pb_backupbuddy::status('action', 'halt_script');
// Halt JS on page.
}
$found_next_step = false;
foreach ((array) $this->_backup['steps'] as $step_index => $step) {
// Loop through steps finding first step that has not run.
//pb_backupbuddy::status( 'details', 'step: ' . $step['function'] . 'start: ' . $step['start_time'] );
if ($step['start_time'] != -1 && $step['start_time'] != 0 && $step['finish_time'] == 0) {
// A step is not marked for skippage, has begun but has not finished. This should not happen but the WP cron is funky. Wait a while before continuing.
$this->_backup['steps'][$step_index]['attempts']++;
// Increment this as an attempt.
$this->_backup_options->save();
if ($step['attempts'] < 6) {
$wait_time = 60 * $step['attempts'];
// Each attempt adds a minute of wait time.
pb_backupbuddy::status('message', 'A scheduled step attempted to run before the previous step completed. Waiting `' . $wait_time . '` seconds before continuing for it to catch up. Attempt number `' . $step['attempts'] . '`.');
$this->cron_next_step(false, $wait_time);
return false;
} else {
// Too many attempts to run this step.
pb_backupbuddy::status('error', 'A scheduled step attempted to run before the previous step completed. After several attempts (`' . $step['attempts'] . '`) of failure BackupBuddy has given up. Halting backup.');
return false;
}
break;
} elseif ($step['start_time'] == 0) {
// Step that is not marked for skippage and has not started yet.
$found_next_step = true;
$this->_backup['steps'][$step_index]['start_time'] = time();
// Set this step time to now.
$this->_backup['steps'][$step_index]['attempts']++;
// Increment this as an attempt.
$this->_backup_options->save();
pb_backupbuddy::status('details', 'Found next step to run: `' . $step['function'] . '`.');
break;
// Break out of foreach loop to continue.
//.........这里部分代码省略.........
示例12: trim
*/
$step = pb_backupbuddy::_POST('step');
$backup_file = pb_backupbuddy::_POST('backup_file');
$url = trim(pb_backupbuddy::_POST('url'));
switch ($step) {
case 'step1':
// Make sure backup file has been transferred properly.
// Find last migration.
$last_migration_key = get_transient('pb_backupbuddy_migrationkey');
if (false === $last_migration_key) {
die(json_encode(array('status_code' => 'failure', 'status_message' => 'Status: Error #54849545. Unable to determine which backup is migrating. Please try again.', 'next_step' => '0')));
}
pb_backupbuddy::status('details', 'About to load fileoptions data.');
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
pb_backupbuddy::status('details', 'Fileoptions instance #26.');
$fileoptions_obj = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $last_migration_key . '.txt', $read_only = true, $ignore_lock = true, $create_file = false);
if (true !== ($result = $fileoptions_obj->is_ok())) {
pb_backupbuddy::status('error', __('Fatal Error #9034.2342348. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
return false;
}
pb_backupbuddy::status('details', 'Fileoptions data loaded.');
$fileoptions =& $fileoptions_obj->options;
$migrate_send_status = $fileoptions['status'];
if ($migrate_send_status == 'timeout') {
$status_message = 'Status: Waiting for backup to finish uploading to server...';
$next_step = '1';
} elseif ($migrate_send_status == 'failure') {
$status_message = 'Status: Sending backup to server failed.';
$next_step = '0';
} elseif ($migrate_send_status == 'success') {
$status_message = 'Status: Success sending backup file.';
示例13: test
public static function test($settings)
{
if (class_exists('CFRuntime')) {
die('CFRuntime already defined. Another plugin may be incorrectly loading its copy of S3 libraries on BackupBuddy pages.');
}
require_once dirname(dirname(__FILE__)) . '/_s3lib/aws-sdk/sdk.class.php';
$remote_path = self::get_remote_path($settings['directory']);
// Has leading and trailng slashes.
$settings['bucket'] = strtolower($settings['bucket']);
// Buckets must be lowercase.
/*
if ( FALSE !== strpos( $settings['bucket'], ' ' ) ) {
$message = 'Bucket names cannot have spaces in them.';
return $message;
}
*/
// Try sending a file.
$send_response = pb_backupbuddy_destinations::send($settings, dirname(dirname(__FILE__)) . '/remote-send-test.php', $send_id = 'TEST-' . pb_backupbuddy::random_string(12));
// 3rd param true forces clearing of any current uploads.
if (false === $send_response) {
$send_response = 'Error sending test file to S3.';
} else {
$send_response = 'Success.';
}
// S3 object for managing files.
$credentials = pb_backupbuddy_destination_s3::get_credentials($settings);
$s3_manage = new AmazonS3($credentials);
if ($settings['ssl'] == 0) {
@$s3_manage->disable_ssl(true);
}
// Verify bucket exists; create if not. Also set region to the region bucket exists in.
if (false === self::_prepareBucketAndRegion($s3_manage, $settings)) {
return false;
}
// Delete sent file.
$delete_response = 'Success.';
$delete_response = $s3_manage->delete_object($credentials['bucket'], $remote_path . 'remote-send-test.php');
if (!$delete_response->isOK()) {
$delete_response = 'Unable to delete test S3 file `remote-send-test.php`.';
pb_backupbuddy::status('details', $delete_response . ' Details: `' . print_r($delete_response, true) . '`.');
} else {
$delete_response = 'Success.';
}
// Load destination fileoptions.
pb_backupbuddy::status('details', 'About to load fileoptions data.');
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
pb_backupbuddy::status('details', 'Fileoptions instance #7.');
$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 !== ($result = $fileoptions_obj->is_ok())) {
pb_backupbuddy::status('error', __('Fatal Error #9034.84838. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
return false;
}
pb_backupbuddy::status('details', 'Fileoptions data loaded.');
$fileoptions =& $fileoptions_obj->options;
if ('Success.' != $send_response || 'Success.' != $delete_response) {
$fileoptions['status'] = 'failure';
$fileoptions_obj->save();
unset($fileoptions_obj);
return 'Send details: `' . $send_response . '`. Delete details: `' . $delete_response . '`.';
} else {
$fileoptions['status'] = 'success';
$fileoptions['finish_time'] = time();
}
$fileoptions_obj->save();
unset($fileoptions_obj);
return true;
}
示例14: glob
// Move all files from old backup to new.
$old_backups_moved = 0;
$old_backups = glob($old_backup_dir . 'backup*.zip');
if (!is_array($old_backups) || empty($old_backups)) {
// On failure glob() returns false or an empty array depending on server settings so normalize here.
$old_backups = array();
}
foreach ($old_backups as $old_backup) {
if (false === rename($old_backup, $new_backup_dir . basename($old_backup))) {
pb_backupbuddy::alert('ERROR: Unable to move backup "' . basename($old_backup) . '" to new storage directory. Manually move it or delete it for security and to prevent it from being backed up within backups.');
} else {
// rename success.
$old_backups_moved++;
$serial = backupbuddy_core::get_serial_from_file(basename($old_backup));
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
$fileoptions_files = glob(backupbuddy_core::getLogDirectory() . 'fileoptions/*.txt');
if (!is_array($fileoptions_files)) {
$fileoptions_files = array();
}
foreach ($fileoptions_files as $fileoptions_file) {
pb_backupbuddy::status('details', 'Fileoptions instance #21.');
$backup_options = new pb_backupbuddy_fileoptions($fileoptions_file);
if (true !== ($result = $backup_options->is_ok())) {
pb_backupbuddy::status('error', __('Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
continue;
}
if (isset($backup_options->options[$serial])) {
if (isset($backup_options->options['archive_file'])) {
$backup_options->options['archive_file'] = str_replace($old_backup_dir, $new_backup_dir, $backup_options->options['archive_file']);
}
}
示例15: test
public static function test($settings)
{
if ($settings['address'] == '' || $settings['username'] == '' || $settings['password'] == '') {
return __('Missing required input.', 'it-l10n-backupbuddy');
}
// Try sending a file.
$send_response = pb_backupbuddy_destinations::send($settings, dirname(dirname(__FILE__)) . '/remote-send-test.php', $send_id = 'TEST-' . pb_backupbuddy::random_string(12));
// 3rd param true forces clearing of any current uploads.
if (false === $send_response) {
$send_response = 'Error sending test file to FTP.';
} else {
$send_response = 'Success.';
}
// Now we will need to go and cleanup this potentially uploaded file.
$delete_response = 'Error deleting test file from FTP.';
// Default.
// Settings.
$server = $settings['address'];
$username = $settings['username'];
$password = $settings['password'];
$path = $settings['path'];
$ftps = $settings['ftps'];
if ($settings['active_mode'] == '0') {
$active_mode = false;
} else {
$active_mode = true;
}
$url = $settings['url'];
// optional url for using with migration.
$port = '21';
if (strstr($server, ':')) {
$server_params = explode(':', $server);
$server = $server_params[0];
$port = $server_params[1];
}
// Connect.
if ($ftps == '0') {
$conn_id = @ftp_connect($server, $port, 10);
// timeout of 10 seconds.
if ($conn_id === false) {
$error = __('Unable to connect to FTP address `' . $server . '` on port `' . $port . '`.', 'it-l10n-backupbuddy');
$error .= "\n" . __('Verify the server address and port (default 21). Verify your host allows outgoing FTP connections.', 'it-l10n-backupbuddy');
return $send_response . ' ' . $error;
}
} else {
if (function_exists('ftp_ssl_connect')) {
$conn_id = @ftp_ssl_connect($server, $port);
if ($conn_id === false) {
return $send_response . ' ' . __('Destination server does not support FTPS?', 'it-l10n-backupbuddy');
}
} else {
return $send_response . ' ' . __('Your web server doesnt support FTPS.', 'it-l10n-backupbuddy');
}
}
$login_result = @ftp_login($conn_id, $username, $password);
if (!$conn_id || !$login_result) {
pb_backupbuddy::status('details', 'FTP test: Invalid user/pass.');
$response = __('Unable to login. Bad user/pass.', 'it-l10n-backupbuddy');
if ($ftps != '0') {
$response .= "\n\nNote: You have FTPs enabled. You may get this error if your host does not support encryption at this address/port.";
}
return $send_response . ' ' . $response;
}
pb_backupbuddy::status('details', 'FTP test: Success logging in.');
// Handle active/pasive mode.
if ($active_mode === true) {
// do nothing, active is default.
pb_backupbuddy::status('details', 'Active FTP mode based on settings.');
} elseif ($active_mode === false) {
// Turn passive mode on.
pb_backupbuddy::status('details', 'Passive FTP mode based on settings.');
ftp_pasv($conn_id, true);
} else {
pb_backupbuddy::status('error', 'Unknown FTP active/passive mode: `' . $active_mode . '`.');
}
// Delete test file.
pb_backupbuddy::status('details', 'FTP test: Deleting temp test file.');
if (true === ftp_delete($conn_id, $path . '/remote-send-test.php')) {
$delete_response = 'Success.';
}
// Close FTP connection.
pb_backupbuddy::status('details', 'FTP test: Closing FTP connection.');
@ftp_close($conn_id);
// Load destination fileoptions.
pb_backupbuddy::status('details', 'About to load fileoptions data.');
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
pb_backupbuddy::status('details', 'Fileoptions instance #12.');
$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 !== ($result = $fileoptions_obj->is_ok())) {
pb_backupbuddy::status('error', __('Fatal Error #9034.72373. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
return false;
}
pb_backupbuddy::status('details', 'Fileoptions data loaded.');
$fileoptions =& $fileoptions_obj->options;
if ('Success.' != $send_response || 'Success.' != $delete_response) {
$fileoptions['status'] = 'failure';
$fileoptions_obj->save();
unset($fileoptions_obj);
return 'Send details: `' . $send_response . '`. Delete details: `' . $delete_response . '`.';
} else {
//.........这里部分代码省略.........