本文整理汇总了PHP中backupbuddy_core::getBackupDirectory方法的典型用法代码示例。如果您正苦于以下问题:PHP backupbuddy_core::getBackupDirectory方法的具体用法?PHP backupbuddy_core::getBackupDirectory怎么用?PHP backupbuddy_core::getBackupDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类backupbuddy_core
的用法示例。
在下文中一共展示了backupbuddy_core::getBackupDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: stats
function stats()
{
echo '<style type="text/css">';
echo ' .pb_fancy {';
echo ' font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif;';
echo ' font-size: 18px;';
echo ' color: #21759B;';
echo ' }';
echo '</style>';
echo '<div>';
$backup_url = 'admin.php?page=pb_backupbuddy_backup';
$files = glob(backupbuddy_core::getBackupDirectory() . 'backup*.zip');
if (!is_array($files) || empty($files)) {
$files = array();
}
echo sprintf(__('You currently have %s stored backups.', 'it-l10n-backupbuddy'), '<span class="pb_fancy"><a href="' . $backup_url . '">' . count($files) . '</a></span>');
if (pb_backupbuddy::$options['last_backup_finish'] == 0) {
echo ' ', __('You have not successfully created any backups.', 'it-l10n-backupbuddy');
} else {
echo ' ', sprintf(__(' Your most recent successful backup was %s ago.', 'it-l10n-backupbuddy'), '<span class="pb_fancy"><a href="' . $backup_url . '">' . pb_backupbuddy::$format->time_ago(pb_backupbuddy::$options['last_backup_finish']) . '</a></span>');
}
echo ' ', sprintf(__('There have been %s post/page modifications since your last backup.', 'it-l10n-backupbuddy'), '<span class="pb_fancy"><a href="' . $backup_url . '">' . pb_backupbuddy::$options['edits_since_last'] . '</a></span>');
echo ' <span class="pb_fancy"><a href="' . $backup_url . '">', __('Go create a backup!', 'it-l10n-backupbuddy'), '</a></span>';
echo '</div>';
}
示例2: calculateArchiveFilename
public static function calculateArchiveFilename($serial, $type)
{
// Prepare some values for setting up the backup data.
$siteurl_stripped = backupbuddy_core::backup_prefix();
// Calculate customizable section of archive filename (date vs date+time).
if (pb_backupbuddy::$options['archive_name_format'] == 'datetime') {
// "datetime" = Date + time.
$backupfile_datetime = date(backupbuddy_constants::ARCHIVE_NAME_FORMAT_DATETIME, pb_backupbuddy::$format->localize_time(time()));
} else {
// "date" = date only (the default).
$backupfile_datetime = date(backupbuddy_constants::ARCHIVE_NAME_FORMAT_DATE, pb_backupbuddy::$format->localize_time(time()));
}
$archiveFile = backupbuddy_core::getBackupDirectory() . 'backup-' . $siteurl_stripped . '-' . $backupfile_datetime . '-' . $type . '-' . $serial . '.zip';
pb_backupbuddy::status('details', 'Calculated archive file: `' . $archiveFile . '`.');
return $archiveFile;
}
示例3: array
<?php
// Incoming variables: $backups generated via core.php backups_list() function.
// $listing_mode should be either: default, migrate
$hover_actions = array();
// If download URL is within site root then allow downloading via web.
$backup_directory = backupbuddy_core::getBackupDirectory();
// Normalize for Windows paths.
$backup_directory = str_replace('\\', '/', $backup_directory);
$backup_directory = rtrim($backup_directory, '/\\') . '/';
// Enforce single trailing slash.
if ($listing_mode != 'restore_files' && FALSE !== stristr($backup_directory, ABSPATH)) {
$hover_actions[pb_backupbuddy::ajax_url('download_archive') . '&backupbuddy_backup='] = __('Download', 'it-l10n-backupbuddy');
}
if ($listing_mode == 'restore_files') {
$hover_actions[pb_backupbuddy::ajax_url('download_archive') . '&zip_viewer='] = __('Browse & Restore Files', 'it-l10n-backupbuddy');
$hover_actions['note'] = __('Note', 'it-l10n-backupbuddy');
$bulk_actions = array();
}
if ($listing_mode == 'default') {
$hover_actions['send'] = __('Send', 'it-l10n-backupbuddy');
$hover_actions['zip_viewer'] = __('Browse & Restore Files', 'it-l10n-backupbuddy');
$hover_actions['note'] = __('Note', 'it-l10n-backupbuddy');
$hover_actions['hash'] = __('Checksum', 'it-l10n-backupbuddy');
$bulk_actions = array('delete_backup' => __('Delete', 'it-l10n-backupbuddy'));
}
if ($listing_mode == 'migrate') {
$hover_actions['migrate'] = __('Migrate', 'it-l10n-backupbuddy');
$hover_actions[pb_backupbuddy::ajax_url('download_archive') . '&backupbuddy_backup='] = __('Download', 'it-l10n-backupbuddy');
$hover_actions['note'] = __('Note', 'it-l10n-backupbuddy');
$bulk_actions = array();
示例4: str_replace
// If temp directory is within webroot then lock it down.
$temp_dir = str_replace('\\', '/', $temp_dir);
// Normalize for Windows.
$temp_dir = rtrim($temp_dir, '/\\') . '/';
// Enforce single trailing slash.
if (FALSE !== stristr($temp_dir, ABSPATH)) {
// Temp dir is within webroot.
pb_backupbuddy::anti_directory_browsing($destination);
}
unset($temp_dir);
$message = 'Extracting "' . $file . '" from archive "' . $archive_file . '" into temporary file "' . $destination . '". ';
echo '<!-- ';
pb_backupbuddy::status('details', $message);
echo $message;
$extractions = array($file => $temp_file);
$extract_result = $zipbuddy->extract(backupbuddy_core::getBackupDirectory() . $archive_file, $destination, $extractions);
if (false === $extract_result) {
// failed.
echo ' -->';
$error = 'Error #584984458. Unable to extract.';
pb_backupbuddy::status('error', $error);
die($error);
} else {
// success.
_e('Success.', 'it-l10n-backupbuddy');
echo ' -->';
?>
<textarea readonly="readonly" wrap="off" style="width: 100%; min-height: 175px; height: 100%; margin: 0;"><?php
echo file_get_contents($destination . '/' . $temp_file);
?>
</textarea>
示例5: restore
public static function restore($archive_file, $files, $finalPath, &$zipbuddy = null)
{
if (!current_user_can(pb_backupbuddy::$options['role_access'])) {
die('Error #473623. Access Denied.');
}
$serial = backupbuddy_core::get_serial_from_file($archive_file);
// serial of archive.
$success = false;
foreach ($files as $file) {
$file = str_replace('*', '', $file);
// Remove any wildcard.
if (file_exists($finalPath . $file) && is_dir($finalPath . $file)) {
if (($file_count = @scandir($finalPath . $file)) && count($file_count) > 2) {
pb_backupbuddy::status('error', __('Error #9036. The destination directory being restored already exists and is NOT empty. The directory will not be restored to prevent inadvertently losing files within the existing directory. Delete existing directory first if you wish to proceed or restore individual files.', 'it-l10n-backupbuddy') . ' Existing directory: `' . $finalPath . $file . '`.');
return false;
}
}
}
if (null === $zipbuddy) {
require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
$zipbuddy = new pluginbuddy_zipbuddy(backupbuddy_core::getBackupDirectory());
}
// Calculate temp directory & lock it down.
$temp_dir = get_temp_dir();
$destination = $temp_dir . 'backupbuddy-' . $serial;
if (!file_exists($destination) && false === mkdir($destination, 0777, true)) {
$error = 'Error #458485945: Unable to create temporary location.';
pb_backupbuddy::status('error', $error);
return false;
}
// If temp directory is within webroot then lock it down.
$temp_dir = str_replace('\\', '/', $temp_dir);
// Normalize for Windows.
$temp_dir = rtrim($temp_dir, '/\\') . '/';
// Enforce single trailing slash.
if (FALSE !== stristr($temp_dir, ABSPATH)) {
// Temp dir is within webroot.
pb_backupbuddy::anti_directory_browsing($destination);
}
unset($temp_dir);
pb_backupbuddy::status('details', 'Extracting into temporary directory "' . $destination . '".');
$prettyFilesList = array();
foreach ($files as $fileSource => $fileDestination) {
$prettyFilesList[] = $fileSource . ' => ' . $fileDestination;
}
pb_backupbuddy::status('details', 'Files to extract: `' . htmlentities(implode(', ', $prettyFilesList)) . '`.');
unset($prettyFilesList);
pb_backupbuddy::flush();
// Do the actual extraction.
$extract_success = true;
if (false === $zipbuddy->extract($archive_file, $destination, $files)) {
pb_backupbuddy::status('error', 'Error #584984458b. Unable to extract.');
$extract_success = false;
}
if (true === $extract_success) {
// Verify all files/directories to be extracted exist in temp destination directory. If any missing then delete everything and bail out.
foreach ($files as &$file) {
$file = str_replace('*', '', $file);
// Remove any wildcard.
if (!file_exists($destination . '/' . $file)) {
// Cleanup.
foreach ($files as $file) {
@trigger_error('');
// Clear out last error.
@unlink($destination . '/' . $file);
$last_error = error_get_last();
if (is_array($last_error)) {
pb_backupbuddy::status('error', $last_error['message'] . ' File: `' . $last_error['file'] . '`. Line: `' . $last_error['line'] . '`.');
}
}
pb_backupbuddy::status('error', 'Error #854783474. One or more expected files / directories missing.');
$extract_success = false;
break;
}
}
unset($file);
// Made it this far so files all exist. Move them all.
foreach ($files as $file) {
@trigger_error('');
// Clear out last error.
if (false === @rename($destination . '/' . $file, $finalPath . $file)) {
$last_error = error_get_last();
if (is_array($last_error)) {
//print_r( $last_error );
pb_backupbuddy::status('error', $last_error['message'] . ' File: `' . $last_error['file'] . '`. Line: `' . $last_error['line'] . '`.');
}
$error = 'Error #9035. Unable to move restored file `' . $destination . '/' . $file . '` to `' . $finalPath . $file . '`. Verify permissions on destination location & that the destination directory/file does not already exist.';
pb_backupbuddy::status('error', $error);
} else {
$details = 'Moved `' . $destination . '/' . $file . '` to `' . $finalPath . $file . '`.<br>';
pb_backupbuddy::status('details', $details);
$success = true;
}
}
}
// end extract success.
// Try to cleanup.
if (file_exists($destination)) {
if (false === pb_backupbuddy::$filesystem->unlink_recursive($destination)) {
pb_backupbuddy::status('details', 'Unable to delete temporary holding directory `' . $destination . '`.');
//.........这里部分代码省略.........
示例6: process_ftp_copy
function process_ftp_copy($backup, $ftp_server, $ftp_username, $ftp_password, $ftp_directory, $port = '21', $ftps = '0')
{
pb_backupbuddy::set_greedy_script_limits();
if (!class_exists('backupbuddy_core')) {
require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
}
// Connect to server.
if ($ftps == '1') {
// Connect with FTPs.
if (function_exists('ftp_ssl_connect')) {
$conn_id = ftp_ssl_connect($ftp_server, $port);
if ($conn_id === false) {
pb_backupbuddy::status('details', 'Unable to connect to FTPS (check address/FTPS support).', 'error');
return false;
} else {
pb_backupbuddy::status('details', 'Connected to FTPs.');
}
} else {
pb_backupbuddy::status('details', 'Your web server doesnt support FTPS in PHP.', 'error');
return false;
}
} else {
// Connect with FTP (normal).
if (function_exists('ftp_connect')) {
$conn_id = ftp_connect($ftp_server, $port);
if ($conn_id === false) {
pb_backupbuddy::status('details', 'ERROR: Unable to connect to FTP (check address).', 'error');
return false;
} else {
pb_backupbuddy::status('details', 'Connected to FTP.');
}
} else {
pb_backupbuddy::status('details', 'Your web server doesnt support FTP in PHP.', 'error');
return false;
}
}
// login with username and password
$login_result = ftp_login($conn_id, $ftp_username, $ftp_password);
// try to download $server_file and save to $local_file
$destination_file = backupbuddy_core::getBackupDirectory() . $backup;
if (file_exists($destination_file)) {
$destination_file = str_replace('backup-', 'backup_copy_' . pb_backupbuddy::random_string(5) . '-', $destination_file);
}
if (ftp_get($conn_id, $destination_file, $ftp_directory . $backup, FTP_BINARY)) {
pb_backupbuddy::status('message', 'Successfully wrote remote file locally to `' . $destination_file . '`.');
} else {
pb_backupbuddy::status('error', 'Error writing remote file locally to `' . $destination_file . '`.');
}
// close this connection
ftp_close($conn_id);
}
示例7: _verb_renderImportBuddy
private static function _verb_renderImportBuddy()
{
$backupFile = pb_backupbuddy::_POST('backupFile');
$password = md5(md5(pb_backupbuddy::_POST('backupbuddy_api_key')));
// Store this serial in settings to cleanup any temp db tables in the future with this serial with periodic cleanup.
$backupSerial = backupbuddy_core::get_serial_from_file($backupFile);
pb_backupbuddy::$options['rollback_cleanups'][$backupSerial] = time();
pb_backupbuddy::save();
$importFileSerial = backupbuddy_core::deploymentImportBuddy($password, backupbuddy_core::getBackupDirectory() . $backupFile);
if (is_array($importFileSerial)) {
die(json_encode(array('success' => false, 'error' => $importFileSerial[1])));
} else {
die(json_encode(array('success' => true, 'importFileSerial' => $importFileSerial)));
}
}
示例8: restore_file_restore
public function restore_file_restore()
{
$files = pb_backupbuddy::_GET('files');
// file to extract.
$files_array = explode(',', $files);
$files = array();
foreach ($files_array as $file) {
if (substr($file, -1) == '/') {
// If directory then add wildcard.
$file = $file . '*';
}
$files[$file] = $file;
}
unset($files_array);
pb_backupbuddy::$ui->ajax_header(true, false);
// js, no padding
?>
<script type="text/javascript">
function pb_status_append( status_string ) {
target_id = 'pb_backupbuddy_status'; // importbuddy_status or pb_backupbuddy_status
if( jQuery( '#' + target_id ).length == 0 ) { // No status box yet so suppress.
return;
}
jQuery( '#' + target_id ).append( "\n" + status_string );
textareaelem = document.getElementById( target_id );
textareaelem.scrollTop = textareaelem.scrollHeight;
}
</script>
<?php
$success = false;
global $pb_backupbuddy_js_status;
$pb_backupbuddy_js_status = true;
echo pb_backupbuddy::status_box('Restoring . . .');
echo '<div id="pb_backupbuddy_working" style="width: 100px;"><br><center><img src="' . pb_backupbuddy::plugin_url() . '/images/working.gif" title="Working... Please wait as this may take a moment..."></center></div>';
pb_backupbuddy::set_status_serial('restore');
global $wp_version;
pb_backupbuddy::status('details', 'BackupBuddy v' . pb_backupbuddy::settings('version') . ' using WordPress v' . $wp_version . ' on ' . PHP_OS . '.');
$archive_file = pb_backupbuddy::_GET('archive');
// archive to extract from.
require pb_backupbuddy::plugin_path() . '/classes/_restoreFiles.php';
$result = backupbuddy_restore_files::restore(backupbuddy_core::getBackupDirectory() . $archive_file, $files, $finalPath = ABSPATH);
echo '<script type="text/javascript">jQuery("#pb_backupbuddy_working").hide();</script>';
pb_backupbuddy::flush();
if (false === $result) {
} else {
}
pb_backupbuddy::$ui->ajax_footer();
pb_backupbuddy::$ui->ajax_footer();
die;
}
示例9: complete
pb_backupbuddy::status('warning', 'The function `' . $step['function'] . '` is taking an abnormally long time to complete (' . $thisRunTime . ' seconds). The backup may have failed. If it does not increase in the next few minutes it most likely timed out. See the Status Log for details.', $serial);
}
} elseif ($step['start_time'] == 0) {
// Step that has not started yet.
// Do nothing.
} elseif ($step['start_time'] == -1) {
// Step marked for skipping (backup stop button hit).
// Do nothing.
} else {
// Last case: Finished. Skip.
// Do nothing.
}
}
//***** End outputting status of the current step.
//***** Begin output of temp zip file size.
$temporary_zip_directory = backupbuddy_core::getBackupDirectory() . 'temp_zip_' . $serial . '/';
if (file_exists($temporary_zip_directory)) {
// Temp zip file.
$directory = opendir($temporary_zip_directory);
while ($file = readdir($directory)) {
if ($file != '.' && $file != '..' && $file != 'exclusions.txt' && !preg_match('/.*\\.txt/', $file) && !preg_match('/pclzip.*\\.gz/', $file)) {
$stats = stat($temporary_zip_directory . $file);
$writeSpeedText = '';
if ($zipRunTime > 0) {
$writeSpeed = $stats['size'] / $zipRunTime;
$writeSpeedText = '. ' . __('Approximate creation speed', 'it-l10n-backupbuddy') . ': ' . pb_backupbuddy::$format->file_size($writeSpeed) . '/sec';
}
pb_backupbuddy::status('details', __('Temporary ZIP file size', 'it-l10n-backupbuddy') . ': ' . pb_backupbuddy::$format->file_size($stats['size']) . $writeSpeedText, $serial);
pb_backupbuddy::status('archiveSize', pb_backupbuddy::$format->file_size($stats['size']), $serial);
}
}
示例10: post_backup
function post_backup($fail_mode = false, $cancel_backup = false)
{
pb_backupbuddy::status('message', __('Cleaning up after backup.', 'it-l10n-backupbuddy'));
// Delete temporary data directory.
if (file_exists($this->_backup['temp_directory'])) {
pb_backupbuddy::status('details', __('Removing temp data directory.', 'it-l10n-backupbuddy'));
pb_backupbuddy::$filesystem->unlink_recursive($this->_backup['temp_directory']);
}
// Delete temporary ZIP directory.
if (file_exists(backupbuddy_core::getBackupDirectory() . 'temp_zip_' . $this->_backup['serial'] . '/')) {
pb_backupbuddy::status('details', __('Removing temp zip directory.', 'it-l10n-backupbuddy'));
pb_backupbuddy::$filesystem->unlink_recursive(backupbuddy_core::getBackupDirectory() . 'temp_zip_' . $this->_backup['serial'] . '/');
}
if (true === $fail_mode) {
pb_backupbuddy::status('warning', 'Backup archive limiting has been skipped since there was an error to avoid deleting potentially good backups to make room for a potentially bad backup.');
} else {
$this->trim_old_archives();
// Clean up any old excess archives pushing us over defined limits in settings.
}
if (true === $cancel_backup) {
pb_backupbuddy::status('details', 'Backup stopped so deleting backup ZIP file.');
$unlink_result = @unlink($this->_backup['archive_file']);
if (true === $unlink_result) {
pb_backupbuddy::status('details', 'Deleted stopped backup file.');
} else {
pb_backupbuddy::status('error', 'Unable to delete stopped backup file. You should delete it manually as it may be damaged from stopping mid-backup. File to delete: `' . $this->_backup['archive_file'] . '`.');
}
$this->_backup['finish_time'] = -1;
//pb_backupbuddy::save();
$this->_backup_options->save();
} else {
// Not cancelled.
$this->_backup['archive_size'] = filesize($this->_backup['archive_file']);
pb_backupbuddy::status('details', __('Final ZIP file size', 'it-l10n-backupbuddy') . ': ' . pb_backupbuddy::$format->file_size($this->_backup['archive_size']));
pb_backupbuddy::status('action', 'archive_size^' . pb_backupbuddy::$format->file_size($this->_backup['archive_size']));
if ($fail_mode === false) {
// Not cancelled and did not fail so mark finish time.
//error_log( print_r( $this->_backup_options->options, true ) );
$archiveFile = basename($this->_backup_options->options['archive_file']);
// Calculate backup download URL, if any.
//$downloadURL = pb_backupbuddy::ajax_url( 'download_archive' ) . '&backupbuddy_backup=' . $archiveFile;
$downloadURL = '';
$abspath = str_replace('\\', '/', ABSPATH);
// Change slashes to handle Windows as we store backup_directory with Linux-style slashes even on Windows.
$backup_dir = str_replace('\\', '/', backupbuddy_core::getBackupDirectory());
if (FALSE !== stristr($backup_dir, $abspath)) {
// Make sure file to download is in a publicly accessible location (beneath WP web root technically).
//pb_backupbuddy::status( 'details', 'mydir: `' . $backup_dir . '`, abs: `' . $abspath . '`.');
$sitepath = str_replace($abspath, '', $backup_dir);
$downloadURL = rtrim(site_url(), '/\\') . '/' . trim($sitepath, '/\\') . '/' . $archiveFile;
}
$integrityIsOK = '-1';
if (isset($this->_backup_options->options['integrity']['is_ok'])) {
$integrityIsOK = $this->_backup_options->options['integrity']['is_ok'];
}
$destinations = array();
foreach ($this->_backup_options->options['steps'] as $step) {
if ('send_remote_destination' == $step['function']) {
$destinations[] = array('id' => $step['args'][0], 'title' => pb_backupbuddy::$options['remote_destinations'][$step['args'][0]]['title'], 'type' => pb_backupbuddy::$options['remote_destinations'][$step['args'][0]]['type']);
}
}
$finishTime = time();
pb_backupbuddy::$options['last_backup_finish'] = $finishTime;
pb_backupbuddy::$options['last_backup_stats'] = array('archiveFile' => $archiveFile, 'archiveURL' => $downloadURL, 'archiveSize' => $this->_backup['archive_size'], 'start' => pb_backupbuddy::$options['last_backup_start'], 'finish' => $finishTime, 'type' => $this->_backup_options->options['profile']['type'], 'profileTitle' => htmlentities($this->_backup_options->options['profile']['title']), 'scheduleTitle' => $this->_backup_options->options['schedule_title'], 'integrityStatus' => $integrityIsOK, 'destinations' => $destinations);
//error_log( print_r( pb_backupbuddy::$options['last_backup_stats'], true ) );
pb_backupbuddy::save();
}
}
if ($this->_backup['trigger'] == 'manual') {
// No more manual notifications. Removed Feb 2012 before 3.0.
} elseif ($this->_backup['trigger'] == 'scheduled') {
if (false === $fail_mode && false === $cancel_backup) {
pb_backupbuddy::status('details', __('Sending scheduled backup complete email notification.', 'it-l10n-backupbuddy'));
$message = 'completed successfully in ' . pb_backupbuddy::$format->time_duration(time() - $this->_backup['start_time']) . ".\n";
backupbuddy_core::mail_notify_scheduled($this->_backup['serial'], 'complete', __('Scheduled backup', 'it-l10n-backupbuddy') . ' "' . $this->_backup['schedule_title'] . '" ' . $message);
}
} else {
pb_backupbuddy::status('error', 'Error #4343434. Unknown backup trigger.');
}
pb_backupbuddy::status('message', __('Finished cleaning up.', 'it-l10n-backupbuddy'));
if (true === $cancel_backup) {
pb_backupbuddy::status('details', 'Backup cancellation complete.');
return false;
} else {
if (true === $fail_mode) {
pb_backupbuddy::status('details', __('As this backup did not pass the integrity check you should verify it manually or re-scan. Integrity checks can fail on good backups due to permissions, large file size exceeding memory limits, etc. You may manually disable integrity check on the Settings page but you will no longer be notified of potentially bad backups.', 'it-l10n-backupbuddy'));
} else {
pb_backupbuddy::status('action', 'archive_url^' . basename($this->_backup['archive_file']));
}
}
return true;
}
示例11: str_replace
$backup_directory = backupbuddy_core::_getBackupDirectoryDefault();
}
$backup_directory = str_replace('\\', '/', $backup_directory);
$backup_directory = rtrim($backup_directory, '/\\') . '/';
// Enforce single trailing slash.
if (!is_dir($backup_directory)) {
if (false === @mkdir($backup_directory, 0755)) {
pb_backupbuddy::alert('Error #4838594589: Selected backup directory does not exist and it could not be created. Verify the path is correct or manually create the directory and set proper permissions. Reset to default path.');
$_POST['pb_backupbuddy_backup_directory'] = backupbuddy_core::getBackupDirectory();
// Set back to previous value (aka unchanged).
}
}
if (backupbuddy_core::getBackupDirectory() != $backup_directory) {
// Directory differs. Needs updated in post var. Give messages here as this value is going to end up being saved.
pb_backupbuddy::anti_directory_browsing($backup_directory);
$old_backup_dir = backupbuddy_core::getBackupDirectory();
$new_backup_dir = $backup_directory;
// 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));
示例12: restore_file_restore
public function restore_file_restore()
{
$success = false;
pb_backupbuddy::$ui->ajax_header(true, false);
// js, no padding
?>
<script type="text/javascript">
function pb_status_append( status_string ) {
target_id = 'pb_backupbuddy_status'; // importbuddy_status or pb_backupbuddy_status
if( jQuery( '#' + target_id ).length == 0 ) { // No status box yet so suppress.
return;
}
jQuery( '#' + target_id ).append( "\n" + status_string );
textareaelem = document.getElementById( target_id );
textareaelem.scrollTop = textareaelem.scrollHeight;
}
</script>
<?php
global $pb_backupbuddy_js_status;
$pb_backupbuddy_js_status = true;
echo pb_backupbuddy::status_box('Restoring . . .');
echo '<div id="pb_backupbuddy_working" style="width: 100px;"><br><center><img src="' . pb_backupbuddy::plugin_url() . '/images/working.gif" title="Working... Please wait as this may take a moment..."></center></div>';
pb_backupbuddy::set_status_serial('restore');
global $wp_version;
pb_backupbuddy::status('details', 'BackupBuddy v' . pb_backupbuddy::settings('version') . ' using WordPress v' . $wp_version . ' on ' . PHP_OS . '.');
$archive_file = pb_backupbuddy::_GET('archive');
// archive to extract from.
$files = pb_backupbuddy::_GET('files');
// file to extract.
$files_array = explode(',', $files);
$files = array();
foreach ($files_array as $file) {
if (substr($file, -1) == '/') {
// If directory then add wildcard.
$file = $file . '*';
}
$files[$file] = $file;
}
unset($files_array);
$serial = backupbuddy_core::get_serial_from_file($archive_file);
// serial of archive.
foreach ($files as $file) {
$file = str_replace('*', '', $file);
// Remove any wildcard.
if (file_exists(ABSPATH . $file) && is_dir(ABSPATH . $file)) {
if (($file_count = @scandir(ABSPATH . $file)) && count($file_count) > 2) {
pb_backupbuddy::status('error', __('Error #9036. The destination directory being restored already exists and is NOT empty. The directory will not be restored to prevent inadvertently losing files within the existing directory. Delete existing directory first if you wish to proceed or restore individual files.', 'it-l10n-backupbuddy') . ' Existing directory: `' . ABSPATH . $file . '`.');
echo '<script type="text/javascript">jQuery("#pb_backupbuddy_working").hide();</script>';
pb_backupbuddy::flush();
pb_backupbuddy::$ui->ajax_footer();
die;
}
}
}
require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
$zipbuddy = new pluginbuddy_zipbuddy(backupbuddy_core::getBackupDirectory());
// Calculate temp directory & lock it down.
$temp_dir = get_temp_dir();
$destination = $temp_dir . 'backupbuddy-' . $serial;
if (!file_exists($destination) && false === mkdir($destination, 0777, true)) {
$error = 'Error #458485945: Unable to create temporary location.';
pb_backupbuddy::status('error', $error);
echo '<script type="text/javascript">jQuery("#pb_backupbuddy_working").hide();</script>';
pb_backupbuddy::flush();
pb_backupbuddy::$ui->ajax_footer();
die;
}
// If temp directory is within webroot then lock it down.
$temp_dir = str_replace('\\', '/', $temp_dir);
// Normalize for Windows.
$temp_dir = rtrim($temp_dir, '/\\') . '/';
// Enforce single trailing slash.
if (FALSE !== stristr($temp_dir, ABSPATH)) {
// Temp dir is within webroot.
pb_backupbuddy::anti_directory_browsing($destination);
}
unset($temp_dir);
pb_backupbuddy::status('details', 'Extracting into temporary directory "' . $destination . '".');
pb_backupbuddy::status('details', 'Files to extract: `' . htmlentities(pb_backupbuddy::_GET('files')) . '`.');
// Make sure temp subdirectories exist.
/*
foreach( $files as $file => $null ) {
mkdir( $destination . '/' . basename( $file ), 0777, true );
}
*/
pb_backupbuddy::flush();
$extract_success = true;
$extract_result = $zipbuddy->extract(backupbuddy_core::getBackupDirectory() . $archive_file, $destination, $files);
if (false === $extract_result) {
// failed.
pb_backupbuddy::status('error', 'Error #584984458b. Unable to extract.');
$extract_success = false;
} else {
// success.
// Verify all files/directories to be extracted exist in temp destination directory. If any missing then delete everything and bail out.
foreach ($files as &$file) {
$file = str_replace('*', '', $file);
// Remove any wildcard.
if (!file_exists($destination . '/' . $file)) {
// Cleanup.
//.........这里部分代码省略.........
示例13: die
<?php
// Incoming vars: $backupFile, $step
if (!current_user_can(pb_backupbuddy::$options['role_access'])) {
die('Error #473623. Access Denied.');
}
require_once pb_backupbuddy::plugin_path() . '/classes/restore.php';
$rollback = new backupbuddy_restore('rollback');
$status = $rollback->start(backupbuddy_core::getBackupDirectory() . $backupFile);
if (false === $status) {
$errors = $rollback->getErrors();
if (count($errors) > 0) {
pb_backupbuddy::alert('Errors were encountered: ' . implode(', ', $errors) . ' If seeking support please click to Show Advanced Details above and provide a copy of the log.');
}
return;
}
$restoreData = $rollback->getState();
?>
<?php
_e("This will roll back this site's database to the state contained within the selected backup file. Verify details below to make sure this is the correct database to roll back to. Current database tables will be a given a temporary prefix. You will be given the opportunity to confirm changes before making them permanent. <b>Tip!</b> Create a Database or Full Backup before proceeding.", 'it-l10n-backupbuddy');
?>
<br><br>
<?php
if (isset($restoreData['dat']['wordpress_version'])) {
$wp_version = $restoreData['dat']['wordpress_version'];
} else {
$wp_version = 'Unknown';
示例14: glob
<?php
backupbuddy_core::verifyAjaxAccess();
$backupSerial = pb_backupbuddy::_POST('serial');
$profileID = pb_backupbuddy::_POST('profileID');
$thisStep = pb_backupbuddy::_POST('step');
$stepCounter = pb_backupbuddy::_POST('stepCounter');
if ('0' == $thisStep) {
$backupFiles = glob(backupbuddy_core::getBackupDirectory() . 'backup*' . $backupSerial . '*.zip');
if (!is_array($backupFiles)) {
$backupFiles = array();
}
if (count($backupFiles) > 0) {
$backupFile = $backupFiles[0];
die(json_encode(array('statusStep' => 'backupComplete', 'stepTitle' => 'Backup finished. File: ' . $backupFile . ' -- Next step start sending the file chunks to remote API server via curl.', 'nextStep' => 'sendFiles')));
}
$lastBackupStats = backupbuddy_api::getLatestBackupStats();
if ($backupSerial != $lastBackupStats['serial']) {
die(json_encode(array('stepTitle' => 'Waiting for backup to begin.', 'statusStep' => 'waitingBackupBegin')));
} else {
// Last backup stats is our deploy backup.
die(json_encode(array('stepTitle' => $lastBackupStats['processStepTitle'] . ' with profile "' . pb_backupbuddy::$options['profiles'][$profileID]['title'] . '".', 'statusStep' => 'backupStats', 'stats' => $lastBackupStats)));
}
} elseif ('sendFiles' == $thisStep) {
if ('0' == $stepCounter) {
die(json_encode(array('stepTitle' => 'FIRST SENDFILES RUN', 'statusStep' => 'sendFiles', 'nextStep' => 'sendFiles')));
} else {
die(json_encode(array('stepTitle' => 'Sending files...', 'statusStep' => 'sendFiles', 'nextStep' => 'sendFiles')));
}
} else {
die('Invalid step `' . htmlentities($thisStep) . '`.');
示例15: getZipMeta
public static function getZipMeta($file)
{
if (!isset(pb_backupbuddy::$classes['zipbuddy'])) {
require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy(backupbuddy_core::getBackupDirectory());
}
$comment_meta = array();
if (isset($file)) {
$comment = pb_backupbuddy::$classes['zipbuddy']->get_comment($file);
$comment = backupbuddy_core::normalize_comment_data($comment);
$comment_meta = array();
foreach ($comment as $comment_line_name => $comment_line_value) {
// Loop through all meta fields in the comment array to display.
if (false !== ($response = backupbuddy_core::pretty_meta_info($comment_line_name, $comment_line_value))) {
$response[0] = '<span title="' . $comment_line_name . '">' . $response[0] . '</span>';
$comment_meta[$comment_line_name] = $response;
}
}
}
if (count($comment_meta) > 0) {
return $comment_meta;
} else {
return false;
}
}