本文整理汇总了PHP中backupbuddy_core::mail_error方法的典型用法代码示例。如果您正苦于以下问题:PHP backupbuddy_core::mail_error方法的具体用法?PHP backupbuddy_core::mail_error怎么用?PHP backupbuddy_core::mail_error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类backupbuddy_core
的用法示例。
在下文中一共展示了backupbuddy_core::mail_error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send_remote_destination
function send_remote_destination($destination_id, $delete_after = false)
{
pb_backupbuddy::status('details', 'Sending file to remote destination ID: `' . $destination_id . '`. Delete after: `' . $delete_after . '`.');
$response = backupbuddy_core::send_remote_destination($destination_id, $this->_backup['archive_file'], '', false, $delete_after);
if (false === $response) {
// Send failure.
$error_message = 'BackupBuddy failed sending a backup to the remote destination "' . pb_backupbuddy::$options['remote_destinations'][$destination_id]['title'] . '" (id: ' . $destination_id . '). Please verify and test destination settings and permissions. Check the error log for further details.';
pb_backupbuddy::status('error', 'Failure sending to remote destination. Details: ' . $error_message);
backupbuddy_core::mail_error($error_message);
}
}
示例2: 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;
}
示例3: glob
$temp_directory = backupbuddy_core::getBackupDirectory() . 'temp_zip_*';
$files = glob($temp_directory . '*');
if (is_array($files) && !empty($files)) {
// For robustness. Without open_basedir the glob() function returns an empty array for no match. With open_basedir in effect the glob() function returns a boolean false for no match.
foreach ($files as $file) {
if (strpos($file, 'index.') !== false || strpos($file, '.htaccess') !== false) {
// Index file or htaccess dont get deleted so go to next file.
continue;
}
$file_stats = stat($file);
if (time() - $file_stats['mtime'] > $backup_age_limit) {
// If older than 12 hours, delete the log.
if (@pb_backupbuddy::$filesystem->unlink_recursive($file) === false) {
$message = 'BackupBuddy was unable to clean up (delete) temporary directory/file: `' . $file . '`. You should manually delete it and/or verify proper file permissions to allow BackupBuddy to clean up for you.';
pb_backupbuddy::status('error', $message);
backupbuddy_core::mail_error($message);
}
}
}
}
// Cleanup remote S3 multipart chunking.
foreach (pb_backupbuddy::$options['remote_destinations'] as $destination) {
if ($destination['type'] != 's3') {
continue;
}
if (isset($destination['max_chunk_size']) && $destination['max_chunk_size'] == '0') {
continue;
}
pb_backupbuddy::status('details', 'Found S3 Multipart Chunking Destinations to cleanup.');
require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php';
$cleanup_result = pb_backupbuddy_destinations::multipart_cleanup($destination);
示例4: remove_temp_zip_dirs
public static function remove_temp_zip_dirs($backup_age_limit = 172800)
{
// Remove any old temporary zip directories: wp-content/uploads/backupbuddy_backups/temp_zip_XXXX/. Logs any directories it cannot delete.
pb_backupbuddy::status('details', 'Cleaning up any old temporary zip directories in backup directory temp location `' . backupbuddy_core::getBackupDirectory() . 'temp_zip_XXXX/`.');
$temp_directory = backupbuddy_core::getBackupDirectory() . 'temp_zip_*';
$files = glob($temp_directory . '*');
if (is_array($files) && !empty($files)) {
// For robustness. Without open_basedir the glob() function returns an empty array for no match. With open_basedir in effect the glob() function returns a boolean false for no match.
foreach ($files as $file) {
if (strpos($file, 'index.') !== false || strpos($file, '.htaccess') !== false) {
// Index file or htaccess dont get deleted so go to next file.
continue;
}
$file_stats = stat($file);
if (time() - $file_stats['mtime'] > $backup_age_limit) {
// If older than 12 hours, delete the log.
if (@pb_backupbuddy::$filesystem->unlink_recursive($file) === false) {
$message = 'BackupBuddy was unable to clean up (delete) temporary directory/file: `' . $file . '`. You should manually delete it and/or verify proper file permissions to allow BackupBuddy to clean up for you.';
pb_backupbuddy::status('error', $message);
backupbuddy_core::mail_error($message);
}
}
}
}
}
示例5: email_error_test
function email_error_test()
{
$email = pb_backupbuddy::_POST('email');
if ($email == '') {
die('You must supply an Error email address to send test message to.');
}
backupbuddy_core::mail_error('THIS IS ONLY A TEST. This is a test of the Error Notification email.', $email);
die('1');
}
示例6: process_dropbox_copy
function process_dropbox_copy($destination_id, $file)
{
pb_backupbuddy::set_greedy_script_limits();
if (!class_exists('backupbuddy_core')) {
require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
}
require_once pb_backupbuddy::plugin_path() . '/destinations/dropbox/lib/dropbuddy/dropbuddy.php';
$dropbuddy = new pb_backupbuddy_dropbuddy(pb_backupbuddy::$options['remote_destinations'][$destination_id]['token']);
if ($dropbuddy->authenticate() !== true) {
if (!class_exists('backupbuddy_core')) {
require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
}
backupbuddy_core::mail_error('Dropbox authentication failed in cron_process_dropbox_copy.');
return false;
}
$destination_file = backupbuddy_core::getBackupDirectory() . basename($file);
if (file_exists($destination_file)) {
$destination_file = str_replace('backup-', 'backup_copy_' . pb_backupbuddy::random_string(5) . '-', $destination_file);
}
pb_backupbuddy::status('error', 'About to get file `' . $file . '` from Dropbox and save to `' . $destination_file . '`.');
file_put_contents($destination_file, $dropbuddy->get_file($file));
pb_backupbuddy::status('error', 'Got object from Dropbox cron.');
}
示例7: send
public static function send($settings = array(), $files = array(), $send_id = '')
{
$limit = $settings['archive_limit'];
$path = $settings['path'];
if (!file_exists($settings['path'])) {
pb_backupbuddy::$filesystem->mkdir($settings['path']);
}
$total_transfer_time = 0;
$total_transfer_size = 0;
foreach ($files as $file) {
pb_backupbuddy::status('details', 'Starting send to `' . $path . '`.');
$filesize = filesize($file);
$total_transfer_size += $filesize;
$send_time = -microtime(true);
if (true !== @copy($file, $path . '/' . basename($file))) {
pb_backupbuddy::status('error', 'Unable to copy file `' . $file . '` of size `' . pb_backupbuddy::$format->file_size($filesize) . '` to local path `' . $path . '`. Please verify the directory exists and permissions permit writing.');
backupbuddy_core::mail_error($error_message);
return false;
} else {
pb_backupbuddy::status('details', 'Send success.');
}
$send_time += microtime(true);
$total_transfer_time += $send_time;
// Start remote backup limit
if ($limit > 0) {
pb_backupbuddy::status('details', 'Archive limit of `' . $limit . '` in settings.');
pb_backupbuddy::status('details', 'path: ' . $path . '*.zip');
$remote_files = glob($path . '/*.zip');
if (!is_array($remote_files)) {
$remote_files = array();
}
usort($remote_files, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));
pb_backupbuddy::status('details', 'Found `' . count($remote_files) . '` backups.');
// Create array of backups and organize by date
$bkupprefix = backupbuddy_core::backup_prefix();
foreach ($remote_files as $file_key => $remote_file) {
if (false === stripos($remote_file, 'backup-' . $bkupprefix . '-')) {
pb_backupbuddy::status('details', 'backup-' . $bkupprefix . '-' . 'not in file: ' . $remote_file);
unset($backups[$file_key]);
}
}
arsort($remote_files);
pb_backupbuddy::status('details', 'Found `' . count($remote_files) . '` backups.');
if (count($remote_files) > $limit) {
pb_backupbuddy::status('details', 'More archives (' . count($remote_files) . ') than limit (' . $limit . ') allows. Trimming...');
$i = 0;
$delete_fail_count = 0;
foreach ($remote_files as $remote_file) {
$i++;
if ($i > $limit) {
pb_backupbuddy::status('details', 'Trimming excess file `' . $remote_file . '`...');
if (!unlink($remote_file)) {
pb_backupbuddy::status('details', 'Unable to delete excess local file `' . $remote_file . '`.');
$delete_fail_count++;
}
}
}
pb_backupbuddy::status('details', 'Finished trimming excess backups.');
if ($delete_fail_count !== 0) {
$error_message = 'Local remote limit could not delete ' . $delete_fail_count . ' backups.';
pb_backupbuddy::status('error', $error_message);
backupbuddy_core::mail_error($error_message);
}
}
} else {
pb_backupbuddy::status('details', 'No local destination file limit to enforce.');
}
// End remote backup limit
}
// end foreach.
// Load fileoptions to the send.
pb_backupbuddy::status('details', 'About to load fileoptions data.');
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
pb_backupbuddy::status('details', 'Fileoptions instance #11.');
$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.2344848. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
return false;
}
pb_backupbuddy::status('details', 'Fileoptions data loaded.');
$fileoptions =& $fileoptions_obj->options;
$fileoptions['write_speed'] = $total_transfer_time / $total_transfer_size;
return true;
}
示例8: send_remote_destination
function send_remote_destination($destination_id, $delete_after = false)
{
pb_backupbuddy::status('details', 'Sending file to remote destination ID: `' . $destination_id . '`. Delete after: `' . $delete_after . '`.');
pb_backupbuddy::status('details', 'IMPORTANT: If the transfer is set to be chunked then only the first chunk status will be displayed during this process. Subsequent chunks will happen after this has finished.');
$response = backupbuddy_core::send_remote_destination($destination_id, $this->_backup['archive_file'], '', false, $delete_after);
if (false === $response) {
// Send failure.
$error_message = 'BackupBuddy failed sending a backup to the remote destination "' . pb_backupbuddy::$options['remote_destinations'][$destination_id]['title'] . '" (id: ' . $destination_id . '). Please verify and test destination settings and permissions. Check the error log for further details.';
pb_backupbuddy::status('error', 'Failure sending to remote destination. Details: ' . $error_message);
backupbuddy_core::mail_error($error_message);
}
}
示例9: send
public static function send($destination_settings, $file, $send_id = '', $delete_after = false)
{
if (is_array($file)) {
// As of v6.1.0.1 no longer accepting multiple files to send.
$file = $file[0];
}
if ('' != $send_id) {
pb_backupbuddy::add_status_serial('remote_send-' . $send_id);
pb_backupbuddy::status('details', '----- Initiating master send function for BackupBuddy v' . pb_backupbuddy::settings('version') . '. Post-send deletion: ' . $delete_after);
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
$fileoptions_file = backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $send_id . '.txt';
if (!file_exists($fileoptions_file)) {
//pb_backupbuddy::status( 'details', 'Fileoptions file `' . $fileoptions_file . '` does not exist yet; creating.' );
//pb_backupbuddy::status( 'details', 'Fileoptions instance #19.' );
$fileoptions_obj = new pb_backupbuddy_fileoptions($fileoptions_file, $read_only = false, $ignore_lock = true, $create_file = true);
} else {
//pb_backupbuddy::status( 'details', 'Fileoptions file exists; loading.' );
//pb_backupbuddy::status( 'details', 'Fileoptions instance #18.' );
$fileoptions_obj = new pb_backupbuddy_fileoptions($fileoptions_file, $read_only = false, $ignore_lock = false, $create_file = false);
}
if (true !== ($result = $fileoptions_obj->is_ok())) {
pb_backupbuddy::status('error', __('Fatal Error #9034.2344848. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
return false;
}
//pb_backupbuddy::status( 'details', 'Fileoptions data loaded.' );
$fileoptions =& $fileoptions_obj->options;
if ('' == $fileoptions) {
// Set defaults.
$fileoptions = backupbuddy_core::get_remote_send_defaults();
$fileoptions['type'] = $destination_settings['type'];
$fileoptions['file'] = $file;
$fileoptions['retries'] = 0;
}
$fileoptions['sendID'] = $send_id;
$fileoptions['destinationSettings'] = $destination_settings;
// always store the LATEST settings for resume info and retry function.
$fileoptions['update_time'] = time();
$fileoptions['deleteAfter'] = $delete_after;
$fileoptions_obj->save();
if (isset($fileoptions['status']) && 'aborted' == $fileoptions['status']) {
pb_backupbuddy::status('warning', 'Destination send triggered on an ABORTED transfer. Ending send function.');
return false;
}
unset($fileoptions_obj);
}
if (false === ($destination = self::_init_destination($destination_settings))) {
echo '{Error #546893498a. Destination configuration file missing.}';
if ('' != $send_id) {
pb_backupbuddy::remove_status_serial('remote_send-' . $send_id);
}
return false;
}
$destination_settings = $destination['settings'];
// Settings with defaults applied, normalized, etc.
if (!file_exists($file)) {
pb_backupbuddy::status('error', 'Error #58459458743. The file that was attempted to be sent to a remote destination, `' . $file . '`, was not found. It either does not exist or permissions prevent accessing it. Check that local backup limits are not causing it to be deleted.');
if ('' != $send_id) {
pb_backupbuddy::remove_status_serial('remote_send-' . $send_id);
}
return false;
}
if (!method_exists($destination['class'], 'send')) {
pb_backupbuddy::status('error', 'Destination class `' . $destination['class'] . '` does not support send operation -- missing function.');
if ('' != $send_id) {
pb_backupbuddy::remove_status_serial('remote_send-' . $send_id);
}
return false;
}
global $pb_backupbuddy_destination_errors;
$pb_backupbuddy_destination_errors = array();
$result = call_user_func_array("{$destination['class']}::send", array($destination_settings, $file, $send_id, $delete_after));
/* $result values:
* false Transfer FAILED.
* true Non-chunked transfer succeeded.
* array() array(
* multipart_id, // Unique string ID for multipart send. Empty string if last chunk finished sending successfully.
* multipart_status_message
* )
*/
if ($result === false) {
$error_details = implode('; ', $pb_backupbuddy_destination_errors);
if ('' != $error_details) {
$error_details = ' Details: ' . $error_details;
}
$log_directory = backupbuddy_core::getLogDirectory();
$preError = 'There was an error sending to the remote destination titled `' . $destination_settings['title'] . '` of type `' . backupbuddy_core::pretty_destination_type($destination_settings['type']) . '`. One or more files may have not been fully transferred. Please see error details for additional information. If the error persists, enable full error logging and try again for full details and troubleshooting. Details: ' . "\n\n";
$logFile = $log_directory . 'status-remote_send-' . $send_id . '_' . pb_backupbuddy::$options['log_serial'] . '.txt';
pb_backupbuddy::status('details', 'Looking for remote send log file to send in error email: `' . $logFile . '`.');
if (!file_exists($logFile)) {
pb_backupbuddy::status('details', 'Remote send log file not found.');
backupbuddy_core::mail_error($preError . $error_details);
} else {
// Log exists. Attach.
pb_backupbuddy::status('details', 'Remote send log file found. Attaching to error email.');
backupbuddy_core::mail_error($preError . $error_details . "\n\nSee the attached log for details.", '', array($logFile));
}
// Save error details into fileoptions for this send.
//pb_backupbuddy::status( 'details', 'About to load fileoptions data.' );
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
pb_backupbuddy::status('details', 'Fileoptions instance #45.');
//.........这里部分代码省略.........
示例10: send
//.........这里部分代码省略.........
return self::_error('Error #2379327. Unable to open file `' . $file . '` to send. Did it get deleted?');
}
// Initiate SINGLE PART upload.
$startSend = time(true);
pb_backupbuddy::status('details', 'Initiating non-chunked transfer.');
try {
$response = self::$_client->upload($settings['bucket'], $settings['directory'] . basename($file), $f, 'private', array('StorageClass' => $settings['storage'], 'ServerSideEncryption' => 'AES256'));
} catch (Exception $e) {
return self::_error('Error #389383: Unable to initiate non-chunked upload. Details: `' . $e->getMessage() . '`.');
}
@fclose($f);
// Made it here so SUCCESS sending.
$uploaded_size = $file_size;
$uploaded_speed = $file_size / (time(true) - $startSend);
pb_backupbuddy::status('details', 'Success uploading file `' . basename($file) . '`. Upload details: `' . print_r($response, true) . '`. Uploaded size: ' . pb_backupbuddy::$format->file_size($uploaded_size) . ', Speed: ' . pb_backupbuddy::$format->file_size($uploaded_speed) . '/sec.');
// 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 #882.');
$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.23737. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
}
pb_backupbuddy::status('details', 'Fileoptions data loaded.');
$fileoptions =& $fileoptions_obj->options;
// Save stats.
if (isset($uploaded_speed)) {
$fileoptions['write_speed'] = $uploaded_speed;
$fileoptions_obj->save();
}
unset($fileoptions_obj);
}
// End non-chunked upload.
}
// end not multipart continuation.
// BEGIN FILE LIMIT PROCESSING. Enforce archive limits if applicable.
if ($backup_type == 'full') {
$limit = $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 = $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 = $db_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-' . backup_prefix()));
// List all users files in this directory that are a backup for this site (limited by prefix).
} catch (Exception $e) {
self::_error('Error #9338292: Unable to list files for archive limiting. Details: `' . $e->getMessage() . '`.');
}
// List backups associated with this site by date.
$backups = array();
foreach ($response_manage->Contents as $object) {
$file = str_replace($settings['directory'], '', $object['Key']);
$backups[$file] = strtotime($object['LastModified']);
}
arsort($backups);
pb_backupbuddy::status('details', 'Stash found `' . count($backups) . '` backups of this type when checking archive limits.');
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++;
}
}
}
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
if (isset($fileoptions_obj)) {
unset($fileoptions_obj);
}
// Success if we made it this far.
return true;
}
示例11: periodic_cleanup
public static function periodic_cleanup($backup_age_limit = 172800, $die_on_fail = true)
{
$max_importbuddy_age = 60 * 60 * 1;
// 1hr - Max age, in seconds, importbuddy files can be there before cleaning up (delay useful if just imported and testing out site).
$max_status_log_age = 48;
// Max age in hours.
$max_site_log_size = pb_backupbuddy::$options['max_site_log_size'] * 1024 * 1024;
// in bytes.
pb_backupbuddy::status('message', 'Starting cleanup procedure for BackupBuddy v' . pb_backupbuddy::settings('version') . '.');
if (!isset(pb_backupbuddy::$options)) {
self::load();
}
// Alert user if no new backups FINISHED within X number of days if enabled. Max 1 email notification per 24 hours period.
if (pb_backupbuddy::$options['no_new_backups_error_days'] > 0) {
if (pb_backupbuddy::$options['last_backup_finish'] > 0) {
$time_since_last = time() - pb_backupbuddy::$options['last_backup_finish'];
$days_since_last = $time_since_last / 60 / 60 / 24;
if ($days_since_last > pb_backupbuddy::$options['no_new_backups_error_days']) {
$last_sent = get_transient('pb_backupbuddy_no_new_backup_error');
if (false === $last_sent) {
$last_sent = time();
set_transient('pb_backupbuddy_no_new_backup_error', $last_sent, 60 * 60 * 24);
}
if (time() - $last_sent > 60 * 60 * 24) {
// 24hrs+ elapsed since last email sent.
$message = 'Alert! BackupBuddy is configured to notify you if no new backups have completed in `' . pb_backupbuddy::$options['no_new_backups_error_days'] . '` days. It has been `' . $days_since_last . '` days since your last completed backups.';
pb_backupbuddy::status('warning', $message);
backupbuddy_core::mail_error($message);
}
}
}
}
// TODO: Check for orphaned .gz files in root from PCLZip.
// Cleanup backup itegrity portion of array (status logging info inside function).
// DEPRECATED: self::trim_backups_integrity_stats();
/***** BEGIN CLEANUP LOGS *****/
// Purge old logs.
pb_backupbuddy::status('details', 'Cleaning up old logs.');
$log_directory = backupbuddy_core::getLogDirectory();
// Purge individual backup status logs unmodified in certain number of hours.
$files = glob($log_directory . 'status-*.txt');
if (is_array($files) && !empty($files)) {
// For robustness. Without open_basedir the glob() function returns an empty array for no match. With open_basedir in effect the glob() function returns a boolean false for no match.
foreach ($files as $file) {
$file_stats = stat($file);
if (time() - $file_stats['mtime'] > $max_status_log_age) {
@unlink($file);
}
}
}
// Purge site-wide log if over certain size.
$files = glob($log_directory . 'log-*.txt');
if (is_array($files) && !empty($files)) {
// For robustness. Without open_basedir the glob() function returns an empty array for no match. With open_basedir in effect the glob() function returns a boolean false for no match.
foreach ($files as $file) {
$file_stats = stat($file);
if ($file_stats['size'] > $max_site_log_size) {
self::mail_error('NOTICE ONLY (not an error): A BackupBuddy log file has exceeded the size threshold of ' . $max_site_log_size . ' KB and has been deleted to maintain performance. This is only a notice. Deleted log file: ' . $file . '.');
@unlink($file);
}
}
}
/***** END CLEANUP LOGS *****/
// Cleanup any temporary local destinations.
pb_backupbuddy::status('details', 'Cleaning up any temporary local destinations.');
foreach (pb_backupbuddy::$options['remote_destinations'] as $destination_id => $destination) {
if ($destination['type'] == 'local' && (isset($destination['temporary']) && $destination['temporary'] === true)) {
// If local and temporary.
if (time() - $destination['created'] > $backup_age_limit) {
// Older than 12 hours; clear out!
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.');
self::trim_remote_send_stats($backup_age_limit);
// Verify directory existance and anti-directory browsing is in place everywhere.
self::verify_directories();
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
// 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) {
$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'])) {
if (!file_exists($backup_options->options['archive_file'])) {
// No corresponding backup ZIP file.
$modified = filemtime($file);
if (time() - $modified > self::MAX_SECONDS_TO_KEEP_ORPHANED_FILEOPTIONS_FILES) {
// Too many days old so delete.
//.........这里部分代码省略.........
示例12: die
<?php
backupbuddy_core::verifyAjaxAccess();
/* email_error_test()
*
* Test sending emails on the Settings page. Tries sending email and dies with "1" on success, else error message string echo'd out and dies.
*
*/
$email = pb_backupbuddy::_POST('email');
if ($email == '') {
die('You must supply an Error email address to send test message to.');
}
backupbuddy_core::mail_error('THIS IS ONLY A TEST. This is a test of the Error Notification email.', $email);
die('1');
示例13: send
public static function send($settings = array(), $files = array(), $send_id = '')
{
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;
}
if (!is_array($files)) {
$files = array($files);
}
$rs_container = $settings['container'];
$limit = $settings['archive_limit'];
if (false === ($conn = self::connect($settings))) {
return false;
}
// Set container
@$conn->create_container($rs_container);
// Create container if it does not exist.
$container = $conn->get_container($rs_container);
// Get container.
foreach ($files as $rs_file) {
pb_backupbuddy::status('details', 'About to create object on Rackspace...');
// Put file to Rackspace.
$sendbackup = $container->create_object(basename($rs_file));
pb_backupbuddy::status('details', 'Object created. About to stream actual file `' . $rs_file . '`...');
if ($sendbackup->load_from_filename($rs_file)) {
pb_backupbuddy::status('details', 'Send succeeded.');
// Start remote backup limit
if ($limit > 0) {
pb_backupbuddy::status('details', 'Archive limit of `' . $limit . '` in settings.');
$bkupprefix = backupbuddy_core::backup_prefix();
$results = $container->get_objects(0, NULL, 'backup-' . $bkupprefix . '-');
// Create array of backups and organize by date
$backups = array();
foreach ($results as $backup) {
$backups[$backup->name] = $backup->last_modified;
}
arsort($backups);
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 . '`...');
if (!$container->delete_object($buname)) {
pb_backupbuddy::status('details', 'Unable to delete excess Rackspace file `' . $buname . '`');
$delete_fail_count++;
}
}
}
if ($delete_fail_count !== 0) {
$error_message = 'Rackspace remote limit could not delete `' . $delete_fail_count . '` backups.';
pb_backupbuddy::status('error', $error_message);
backupbuddy_core::mail_error($error_message);
}
}
} else {
pb_backupbuddy::status('details', 'No Rackspace file limit to enforce.');
}
// End remote backup limit
return true;
// Success.
} else {
// Failed.
$error_message = 'ERROR #9025: Connected to Rackspace but unable to put file. Verify Rackspace settings included Rackspace permissions.' . "\n\n" . 'http://ithemes.com/codex/page/BackupBuddy:_Error_Codes#9025';
pb_backupbuddy::status('details', $error_message, 'error');
backupbuddy_core::mail_error(__($error_message, 'it-l10n-backupbuddy'));
return false;
// Failed.
}
}
// end foreach.
}
示例14: send
//.........这里部分代码省略.........
// Schedule next chunk to send.
pb_backupbuddy::status('details', 'Dropbox (PHP 5.3+) scheduling send of next part(s).');
$cronTime = time();
$cronArgs = array($chunked_destination_settings, $files, $send_id, $delete_after);
$cronHashID = md5($cronTime . serialize($cronArgs));
$cronArgs[] = $cronHashID;
if (false === backupbuddy_core::schedule_single_event($cronTime, pb_backupbuddy::cron_tag('destination_send'), $cronArgs)) {
pb_backupbuddy::status('error', 'Error #948844: Unable to schedule next Dropbox2 cron chunk.');
return false;
} else {
pb_backupbuddy::status('details', 'Success scheduling next cron chunk.');
}
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', 'Dropbox (PHP 5.3+) scheduled send of next part(s). Done for this cycle.');
return array($chunked_destination_settings['_chunk_upload_id'], 'Sent 1 of ' . $chunked_destination_settings['_chunk_total_count'] . ' parts.');
} else {
// normal (non-chunked) send.
pb_backupbuddy::status('details', 'Dropbox send not set to be chunked.');
pb_backupbuddy::status('details', 'About to put file `' . basename($file) . '` (' . pb_backupbuddy::$format->file_size($file_size) . ') to Dropbox (PHP 5.3+).');
$send_time = -microtime(true);
try {
$result = self::$_dbxClient->uploadFile($settings['directory'] . '/' . basename($file), dbx\WriteMode::add(), $f);
} catch (\Exception $e) {
pb_backupbuddy::status('error', 'Dropbox Error: ' . $e->getMessage());
return false;
}
$send_time += microtime(true);
@fclose($f);
pb_backupbuddy::status('details', 'About to load fileoptions data.');
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
pb_backupbuddy::status('details', 'Fileoptions instance #14.');
$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.2344848. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
return false;
}
pb_backupbuddy::status('details', 'Fileoptions data loaded.');
$fileoptions =& $fileoptions_obj->options;
// Calculate some stats to log.
$data_length = $file_size;
$transfer_speed = $data_length / $send_time;
pb_backupbuddy::status('details', 'Dropbox (non-chunked) transfer stats - Sent: `' . pb_backupbuddy::$format->file_size($data_length) . '`, Transfer duration: `' . $send_time . '`, Speed: `' . pb_backupbuddy::$format->file_size($transfer_speed) . '/sec`.');
$fileoptions['write_speed'] = $transfer_speed;
$fileoptions_obj->save();
unset($fileoptions_obj);
}
// end normal (non-chunked) send.
pb_backupbuddy::status('message', 'Success sending `' . basename($file) . '` to Dropbox!');
// Start remote backup limit
if ($settings['archive_limit'] > 0) {
pb_backupbuddy::status('details', 'Dropbox file limit in place. Proceeding with enforcement.');
$meta_data = self::$_dbxClient->getMetadataWithChildren($settings['directory']);
// Create array of backups and organize by date
$bkupprefix = backupbuddy_core::backup_prefix();
$backups = array();
foreach ((array) $meta_data['contents'] as $looping_file) {
if ($looping_file['is_dir'] == '1') {
// JUST IN CASE. IGNORE anything that is a directory.
continue;
}
// check if file is backup
if (strpos($looping_file['path'], 'backup-' . $bkupprefix . '-') !== false) {
// Appears to be a backup file.
$backups[$looping_file['path']] = strtotime($looping_file['modified']);
}
}
arsort($backups);
if (count($backups) > $settings['archive_limit']) {
pb_backupbuddy::status('details', 'Dropbox backup file count of `' . count($backups) . '` exceeds limit of `' . $settings['archive_limit'] . '`.');
$i = 0;
$delete_fail_count = 0;
foreach ($backups as $buname => $butime) {
$i++;
if ($i > $settings['archive_limit']) {
if (!self::$_dbxClient->delete($buname)) {
// Try to delete backup on Dropbox. Increment failure count if unable to.
pb_backupbuddy::status('details', 'Unable to delete excess Dropbox file: `' . $buname . '`');
$delete_fail_count++;
} else {
pb_backupbuddy::status('details', 'Deleted excess Dropbox file: `' . $buname . '`');
}
}
}
if ($delete_fail_count !== 0) {
backupbuddy_core::mail_error(sprintf(__('Dropbox remote limit could not delete %s backups.', 'it-l10n-backupbuddy'), $delete_fail_count));
}
}
} else {
pb_backupbuddy::status('details', 'No Dropbox file limit to enforce.');
}
// End remote backup limit
}
// end foreach.
pb_backupbuddy::status('details', 'All files sent.');
return true;
// Success if made it this far.
}
示例15: send
public static function send($destination_settings, $files, $send_id = '', $delete_after = false)
{
if ('' != $send_id) {
pb_backupbuddy::add_status_serial('remote_send-' . $send_id);
pb_backupbuddy::status('details', '----- Initiating master send function. Post-send deletion: ' . $delete_after);
require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
$fileoptions_file = backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $send_id . '.txt';
if (!file_exists($fileoptions_file)) {
//pb_backupbuddy::status( 'details', 'Fileoptions file `' . $fileoptions_file . '` does not exist yet; creating.' );
//pb_backupbuddy::status( 'details', 'Fileoptions instance #19.' );
$fileoptions_obj = new pb_backupbuddy_fileoptions($fileoptions_file, $read_only = false, $ignore_lock = true, $create_file = true);
} else {
//pb_backupbuddy::status( 'details', 'Fileoptions file exists; loading.' );
//pb_backupbuddy::status( 'details', 'Fileoptions instance #18.' );
$fileoptions_obj = new pb_backupbuddy_fileoptions($fileoptions_file, $read_only = false, $ignore_lock = false, $create_file = false);
}
if (true !== ($result = $fileoptions_obj->is_ok())) {
pb_backupbuddy::status('error', __('Fatal Error #9034.2344848. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
return false;
}
//pb_backupbuddy::status( 'details', 'Fileoptions data loaded.' );
$fileoptions =& $fileoptions_obj->options;
if ('' == $fileoptions) {
$fileoptions = backupbuddy_core::get_remote_send_defaults();
$fileoptions['type'] = $destination_settings['type'];
if (!is_array($files)) {
$fileoptions['file'] = $files;
} else {
$fileoptions['file'] = $files[0];
}
$fileoptions_obj->save();
}
if (isset($fileoptions['status']) && 'aborted' == $fileoptions['status']) {
pb_backupbuddy::status('warning', 'Destination send triggered on an ABORTED transfer. Ending send function.');
return false;
}
unset($fileoptions_obj);
}
if (false === ($destination = self::_init_destination($destination_settings))) {
echo '{Error #546893498a. Destination configuration file missing.}';
if ('' != $send_id) {
pb_backupbuddy::remove_status_serial('remote_send-' . $send_id);
}
return false;
}
$destination_settings = $destination['settings'];
// Settings with defaults applied, normalized, etc.
//$destination_info = $destination['info'];
if (!is_array($files)) {
$files = array($files);
}
$originalFiles = $files;
$files_with_sizes = '';
foreach ($files as $index => $file) {
if ('' == $file) {
unset($files[$index]);
continue;
// Not actually a file to send.
}
if (!file_exists($file)) {
pb_backupbuddy::status('error', 'Error #58459458743. The file that was attempted to be sent to a remote destination, `' . $file . '`, was not found. It either does not exist or permissions prevent accessing it.');
if ('' != $send_id) {
pb_backupbuddy::remove_status_serial('remote_send-' . $send_id);
}
return false;
}
$files_with_sizes .= $file . ' (' . pb_backupbuddy::$format->file_size(filesize($file)) . '); ';
}
//pb_backupbuddy::status( 'details', 'Sending files `' . $files_with_sizes . '` to destination type `' . $destination_settings['type'] . '` titled `' . $destination_settings['title'] . '`.' );
unset($files_with_sizes);
if (!method_exists($destination['class'], 'send')) {
pb_backupbuddy::status('error', 'Destination class `' . $destination['class'] . '` does not support send operation -- missing function.');
if ('' != $send_id) {
pb_backupbuddy::remove_status_serial('remote_send-' . $send_id);
}
return false;
}
//pb_backupbuddy::status( 'details', 'Calling send function.' );
//$result = $destination_class::send( $destination_settings, $files );
global $pb_backupbuddy_destination_errors;
$pb_backupbuddy_destination_errors = array();
$result = call_user_func_array("{$destination['class']}::send", array($destination_settings, $files, $send_id, $delete_after));
if ($result === false) {
$error_details = implode('; ', $pb_backupbuddy_destination_errors);
if ('' != $error_details) {
$error_details = ' Details: ' . $error_details;
}
$log_directory = backupbuddy_core::getLogDirectory();
$preError = 'There was an error sending to the remote destination. One or more files may have not been fully transferred. Please see error details for additional information. If the error persists, enable full error logging and try again for full details and troubleshooting. Details: ' . "\n\n";
$logFile = $log_directory . 'status-remote_send-' . $send_id . '_' . backupbuddy_core::get_serial_from_file($file) . '.txt';
pb_backupbuddy::status('details', 'Looking for remote send log file `' . $logFile . '`.');
if (!file_exists($logFile)) {
pb_backupbuddy::status('details', 'Remote send log file not found.');
backupbuddy_core::mail_error($preError . $error_details);
} else {
// Log exists. Attach.
pb_backupbuddy::status('details', 'Remote send log file found. Attaching to error email.');
backupbuddy_core::mail_error($preError . $error_details . "\n\nSee the attached log for details.", '', array($logFile));
}
// Save error details into fileoptions for this send.
//.........这里部分代码省略.........