protected function _prepare()
{
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, __CLASS__ . " :: Processing parameters");
// Get the DB connection parameters
if (is_array($this->_parametersArray)) {
$driver = array_key_exists('driver', $this->_parametersArray) ? $this->_parametersArray['driver'] : 'mysql';
$host = array_key_exists('host', $this->_parametersArray) ? $this->_parametersArray['host'] : '';
$port = array_key_exists('port', $this->_parametersArray) ? $this->_parametersArray['port'] : '';
$username = array_key_exists('username', $this->_parametersArray) ? $this->_parametersArray['username'] : '';
$username = array_key_exists('user', $this->_parametersArray) ? $this->_parametersArray['user'] : $username;
$password = array_key_exists('password', $this->_parametersArray) ? $this->_parametersArray['password'] : '';
$database = array_key_exists('database', $this->_parametersArray) ? $this->_parametersArray['database'] : '';
$prefix = array_key_exists('prefix', $this->_parametersArray) ? $this->_parametersArray['prefix'] : '';
}
$options = array('driver' => $driver, 'host' => $host . ($port != '' ? ':' . $port : ''), 'user' => $username, 'password' => $password, 'database' => $database, 'prefix' => is_null($prefix) ? '' : $prefix);
$db = AEFactory::getDatabase($options);
$driverType = $db->getDriverType();
$className = 'AEDumpNative' . ucfirst($driverType);
// Check if we have a native dump driver
if (!class_exists($className, true)) {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, __CLASS__ . " :: Native database dump engine {$className} not found; trying Reverse Engineering instead");
// Native driver nor found, I will try falling back to reverse engineering
$className = 'AEDumpReverse' . ucfirst($driverType);
}
if (!class_exists($className, true)) {
$this->setState('error', 'Akeeba Engine does not have a native dump engine for ' . $driverType . ' databases');
} else {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, __CLASS__ . " :: Instanciating new native database dump engine {$className}");
$this->_engine = new $className();
$this->_engine->setup($this->_parametersArray);
$this->_engine->callStage('_prepare');
$this->setState($this->_engine->getState(), $this->_engine->getError());
}
}
开发者ID:01J,项目名称:topm,代码行数:34,代码来源:native.php
示例4: download
public function download()
{
AEPlatform::getInstance()->load_configuration(AEPlatform::getInstance()->get_active_profile());
$tag = JRequest::getCmd('tag', null);
$filename = AEUtilLogger::logName($tag);
@ob_end_clean();
// In case some braindead plugin spits its own HTML
header("Cache-Control: no-cache, must-revalidate");
// HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
// Date in the past
header("Content-Description: File Transfer");
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename="Akeeba Backup Debug Log.txt"');
echo "WARNING: Do not copy and paste lines from this file!\r\n";
echo "You are supposed to ZIP and attach it in your support forum post.\r\n";
echo "If you fail to do so, your support request will receive minimal priority.\r\n";
echo "\r\n";
echo "--- START OF RAW LOG --\r\n";
@readfile($filename);
// The at sign is necessary to skip showing PHP errors if the file doesn't exist or isn't readable for some reason
echo "--- END OF RAW LOG ---\r\n";
flush();
JFactory::getApplication()->close();
}
/**
* Updates the multipart status of the current backup attempt's statistics record
*
* @param int $multipart The new multipart status
*/
public function updateMultipart($multipart)
{
if ($this->multipart_lock) {
return;
}
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, 'Updating multipart status to ' . $multipart);
// Cache this change and commit to db only after the backup is done, or failed
$registry = AEFactory::getConfiguration();
$registry->set('volatile.statistics.multipart', $multipart);
}
开发者ID:01J,项目名称:topm,代码行数:15,代码来源:statistics.php
示例6: echoRawLog
public function echoRawLog()
{
$tag = $this->getState('tag', '');
echo "WARNING: Do not copy and paste lines from this file!\r\n";
echo "You are supposed to ZIP and attach it in your support forum post.\r\n";
echo "If you fail to do so, your support request will receive minimal priority.\r\n";
echo "\r\n";
echo "--- START OF RAW LOG --\r\n";
@readfile(AEUtilLogger::logName($tag));
// The at sign is necessary to skip showing PHP errors if the file doesn't exist or isn't readable for some reason
echo "--- END OF RAW LOG ---\r\n";
}
开发者ID:01J,项目名称:topm,代码行数:12,代码来源:logs.php
示例7: runAnalysis
public function runAnalysis()
{
$ret_array = array();
$ajaxTask = $this->getState('ajax');
$log = $this->getState('log');
switch ($ajaxTask) {
case 'start':
$tag = 'alice';
AliceUtilLogger::WriteLog(true);
AliceUtilLogger::WriteLog(_AE_LOG_INFO, 'Starting analysis');
AliceCoreKettenrad::reset(array('maxrun' => 0));
AliceUtilTempvars::reset($tag);
$kettenrad = AliceCoreKettenrad::load($tag);
$options = array('logToAnalyze' => AEUtilLogger::logName($log));
$kettenrad->setup($options);
$kettenrad->tick();
if ($kettenrad->getState() != 'running') {
$kettenrad->tick();
}
$ret_array = $kettenrad->getStatusArray();
$kettenrad->resetWarnings();
// So as not to have duplicate warnings reports
AliceCoreKettenrad::save($tag);
break;
case 'step':
$tag = 'alice';
$kettenrad = AliceCoreKettenrad::load($tag);
$kettenrad->tick();
$ret_array = $kettenrad->getStatusArray();
$kettenrad->resetWarnings();
// So as not to have duplicate warnings reports
AliceCoreKettenrad::save($tag);
if ($ret_array['HasRun'] == 1) {
// Let's get tests result
$config = AliceFactory::getConfiguration();
$feedback = $config->get('volatile.alice.feedback');
$ret_array['Results'] = json_encode($feedback);
// Clean up
AliceFactory::nuke();
AliceUtilTempvars::reset($tag);
}
break;
default:
break;
}
return $ret_array;
}
/**
* Enforce the minimum execution time
*
* @param bool $log Should I log what I'm doing? Default is true.
*/
public function enforce_min_exec_time($log = true)
{
// Try to get a sane value for PHP's maximum_execution_time INI parameter
if (@function_exists('ini_get')) {
$php_max_exec = @ini_get("maximum_execution_time");
} else {
$php_max_exec = 10;
}
if ($php_max_exec == "" || $php_max_exec == 0) {
$php_max_exec = 10;
}
// Decrease $php_max_exec time by 500 msec we need (approx.) to tear down
// the application, as well as another 500msec added for rounding
// error purposes. Also make sure this is never gonna be less than 0.
$php_max_exec = max($php_max_exec * 1000 - 1000, 0);
// Get the "minimum execution time per step" Akeeba Backup configuration variable
$configuration = AEFactory::getConfiguration();
$minexectime = $configuration->get('akeeba.tuning.min_exec_time', 0);
if (!is_numeric($minexectime)) {
$minexectime = 0;
}
// Make sure we are not over PHP's time limit!
if ($minexectime > $php_max_exec) {
$minexectime = $php_max_exec;
}
// Get current running time
$elapsed_time = $this->getRunningTime() * 1000;
// Only run a sleep delay if we haven't reached the minexectime execution time
if ($minexectime > $elapsed_time && $elapsed_time > 0) {
$sleep_msec = $minexectime - $elapsed_time;
if (function_exists('usleep')) {
if ($log) {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Sleeping for {$sleep_msec} msec, using usleep()");
}
usleep(1000 * $sleep_msec);
} elseif (function_exists('time_nanosleep')) {
if ($log) {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Sleeping for {$sleep_msec} msec, using time_nanosleep()");
}
$sleep_sec = floor($sleep_msec / 1000);
$sleep_nsec = 1000000 * ($sleep_msec - $sleep_sec * 1000);
time_nanosleep($sleep_sec, $sleep_nsec);
} elseif (function_exists('time_sleep_until')) {
if ($log) {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Sleeping for {$sleep_msec} msec, using time_sleep_until()");
}
$until_timestamp = time() + $sleep_msec / 1000;
time_sleep_until($until_timestamp);
} elseif (function_exists('sleep')) {
$sleep_sec = ceil($sleep_msec / 1000);
if ($log) {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Sleeping for {$sleep_sec} seconds, using sleep()");
}
sleep($sleep_sec);
}
} elseif ($elapsed_time > 0) {
// No sleep required, even if user configured us to be able to do so.
if ($log) {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "No need to sleep; execution time: {$elapsed_time} msec; min. exec. time: {$minexectime} msec");
}
}
}
开发者ID:01J,项目名称:topm,代码行数:67,代码来源:timer.php
示例11: _createNewPart
/**
* Creates a new archive part
* @param bool $finalPart Set to true if it is the final part (therefore has the .jps extension)
*/
private function _createNewPart($finalPart = false)
{
// Push the previous part if we have to post-process it immediately
$configuration = AEFactory::getConfiguration();
if ($configuration->get('engine.postproc.common.after_part', 0)) {
$this->finishedPart[] = $this->_dataFileName;
}
$this->_totalFragments++;
$this->_currentFragment = $this->_totalFragments;
if ($finalPart) {
$this->_dataFileName = $this->_dataFileNameBase . '.jps';
} else {
$this->_dataFileName = $this->_dataFileNameBase . '.j' . sprintf('%02d', $this->_currentFragment);
}
AEUtilLogger::WriteLog(_AE_LOG_INFO, 'Creating new JPS part #' . $this->_currentFragment . ', file ' . $this->_dataFileName);
// Inform that we have chenged the multipart number
$statistics = AEFactory::getStatistics();
$statistics->updateMultipart($this->_totalFragments);
// Try to remove any existing file
@unlink($this->_dataFileName);
// Touch the new file
$result = @touch($this->_dataFileName);
if (function_exists('chmod')) {
chmod($this->_dataFileName, 0666);
}
return $result;
}
/**
* Try to pack some files in the $file_list, restraining ourselves not to reach the max
* number of files or max fragment size while doing so. If this process is over and we are
* left without any more files, reset $done_scanning to false in order to instruct the class
* to scan for more files.
*
* @return bool True if there were files packed, false otherwise (empty filelist)
*/
private function pack_files()
{
// Get a reference to the archiver and the timer classes
$archiver = AEFactory::getArchiverEngine();
$timer = AEFactory::getTimer();
$configuration = AEFactory::getConfiguration();
// If post-processing after part creation is enabled, make sure we do post-process each part before moving on
if ($configuration->get('engine.postproc.common.after_part', 0)) {
if (!empty($archiver->finishedPart)) {
$filename = array_shift($archiver->finishedPart);
AEUtilLogger::WriteLog(_AE_LOG_INFO, 'Preparing to post process ' . basename($filename));
$post_proc = AEFactory::getPostprocEngine();
$result = $post_proc->processPart($filename);
$this->propagateFromObject($post_proc);
if ($result === false) {
$this->setWarning('Failed to process file ' . basename($filename));
} else {
AEUtilLogger::WriteLog(_AE_LOG_INFO, 'Successfully processed file ' . basename($filename));
}
// Should we delete the file afterwards?
if ($configuration->get('engine.postproc.common.delete_after', false) && $post_proc->allow_deletes && $result !== false) {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, 'Deleting already processed file ' . basename($filename));
AEPlatform::getInstance()->unlink($filename);
}
if ($post_proc->break_after && $result !== false) {
$configuration->set('volatile.breakflag', true);
return true;
}
// This is required to let the backup continue even after a post-proc failure
$this->resetErrors();
$this->setState('running');
}
}
// If the archiver has work to do, make sure it finished up before continuing
if ($configuration->get('volatile.engine.archiver.processingfile', false)) {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Continuing file packing from previous step");
$result = $archiver->addFile('', '', '');
$this->propagateFromObject($archiver);
if ($this->getError()) {
return false;
}
// If that was the last step, mark a file done
if (!$configuration->get('volatile.engine.archiver.processingfile', false)) {
$this->progressMarkFileDone();
}
}
// Did it finish, or does it have more work to do?
if ($configuration->get('volatile.engine.archiver.processingfile', false)) {
// More work to do. Let's just tell our parent that we finished up successfully.
return true;
}
// Normal file backup loop; we keep on processing the file list, packing files as we go.
if (count($this->file_list) == 0) {
// No files left to pack -- This should never happen! We catch this condition at the end of this method!
$this->done_scanning = false;
$this->progressMarkFolderDone();
return false;
} else {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Packing files");
$packedSize = 0;
$numberOfFiles = 0;
list($usec, $sec) = explode(" ", microtime());
$opStartTime = (double) $usec + (double) $sec;
while (count($this->file_list) > 0) {
$file = @array_shift($this->file_list);
$size = 0;
if (file_exists($file)) {
$size = @filesize($file);
}
// Anticipatory file size algorithm
if ($numberOfFiles > 0 && $size > AELargeFileThreshold) {
if (!AEFactory::getConfiguration()->get('akeeba.tuning.nobreak.beforelargefile', 0)) {
// If the file is bigger than the big file threshold, break the step
// to avoid potential timeouts
$this->setBreakFlag();
AEUtilLogger::WriteLog(_AE_LOG_INFO, "Breaking step _before_ large file: " . $file . " - size: " . $size);
// Push the file back to the list.
array_unshift($this->file_list, $file);
// Mark that we are not done packing files
$this->done_scanning = true;
return true;
}
}
// Proactive potential timeout detection
// Rough estimation of packing speed in bytes per second
list($usec, $sec) = explode(" ", microtime());
$opEndTime = (double) $usec + (double) $sec;
if ($opEndTime - $opStartTime == 0) {
$_packSpeed = 0;
} else {
$_packSpeed = $packedSize / ($opEndTime - $opStartTime);
}
//.........这里部分代码省略.........
/**
* The most basic file transaction: add a single entry (file or directory) to
* the archive.
*
* @param bool $isVirtual If true, the next parameter contains file data instead of a file name
* @param string $sourceNameOrData Absolute file name to read data from or the file data itself is $isVirtual is true
* @param string $targetName The (relative) file name under which to store the file in the archive
* @return True on success, false otherwise
*/
protected function _addFile($isVirtual, &$sourceNameOrData, $targetName)
{
if (!is_object($this->zip)) {
return false;
}
if (!$isVirtual) {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "AEArchiverZipnative :: Adding {$sourceNameOrData}");
if (is_dir($sourceNameOrData)) {
$result = $this->zip->addEmptyDir($targetName);
} else {
$this->runningSum += filesize($sourceNameOrData);
$result = $this->zip->addFile($sourceNameOrData, $targetName);
}
} else {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, ' Virtual add:' . $targetName . ' (' . strlen($sourceNameOrData) . ')');
$this->runningSum += strlen($sourceNameOrData);
if (empty($sourceNameOrData)) {
$result = $this->zip->addEmptyDir($targetName);
} else {
$result = $this->zip->addFromString($targetName, $sourceNameOrData);
}
}
$this->zip->close();
$this->__bootstrap_code();
return true;
}
/**
* Transforms a JPA archive (containing an installer) to the native archive format
* of the class. It actually extracts the source JPA in memory and instructs the
* class to include each extracted file.
*
* @param integer $index The index in the source JPA archive's list currently in use
* @param integer $offset The source JPA archive's offset to use
*
* @return boolean False if an error occurred, true otherwise
*/
public final function transformJPA($index, $offset)
{
static $totalSize = 0;
// Do we have to open the file?
if (!$this->_xform_fp) {
// Get the source path
$registry = AEFactory::getConfiguration();
$embedded_installer = $registry->get('akeeba.advanced.embedded_installer');
// Fetch the name of the installer image
$installerDescriptors = AEUtilInihelper::getInstallerList();
$xform_source = AEPlatform::getInstance()->get_installer_images_path() . DIRECTORY_SEPARATOR . 'foobar.jpa';
// We need this as a "safe fallback"
if (array_key_exists($embedded_installer, $installerDescriptors)) {
$packages = $installerDescriptors[$embedded_installer]['package'];
if (empty($packages)) {
// No installer package specified. Pretend we are done!
$retArray = array("filename" => '', "data" => '', "index" => 0, "offset" => 0, "skip" => false, "done" => true, "filesize" => 0);
return $retArray;
} else {
$packages = explode(',', $packages);
$totalSize = 0;
$pathPrefix = AEPlatform::getInstance()->get_installer_images_path() . DIRECTORY_SEPARATOR;
foreach ($packages as $package) {
$filePath = $pathPrefix . $package;
$totalSize += (int) @filesize($filePath);
}
if (count($packages) < $index) {
$this->setError(__CLASS__ . ":: Installer package index {$index} not found for embedded installer {$embedded_installer}");
return false;
}
$package = $packages[$index];
// A package is specified, use it!
$xform_source = $pathPrefix . $package;
}
}
// 2.3: Try to use sane default if the indicated installer doesn't exist
if (!file_exists($xform_source) && basename($xform_source) != 'angie.jpa') {
if ($index == 0) {
$this->setWarning(__CLASS__ . ":: Selected embedded installer not found, using ANGIE instead");
$xform_source = dirname($xform_source) . '/angie.jpa';
} else {
$this->setError(__CLASS__ . ":: Installer package {$xform_source} not found.");
return false;
}
}
// Try opening the file
if (file_exists($xform_source)) {
$this->_xform_fp = @fopen($xform_source, 'r');
if ($this->_xform_fp === false) {
$this->setError(__CLASS__ . ":: Can't seed archive with installer package " . $xform_source);
return false;
}
} else {
$this->setError(__CLASS__ . ":: Installer package " . $xform_source . " does not exist!");
return false;
}
}
$headerDataLength = 0;
if (!$offset) {
// First run detected!
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, 'Initializing with JPA package ' . $xform_source);
$offset = 0;
// Skip over the header and check no problem exists
$offset = $this->_xformReadHeader();
if ($offset === false) {
$this->setError('JPA package file was not read');
return false;
// Oops! The package file doesn't exist or is corrupt
}
$headerDataLength = $offset;
}
$ret = $this->_xformExtract($offset);
$ret['index'] = $index;
if (is_array($ret)) {
$ret['chunkProcessed'] = $headerDataLength + $ret['offset'] - $offset;
$offset = $ret['offset'];
if (!$ret['skip'] && !$ret['done']) {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, ' Adding ' . $ret['filename'] . '; Next offset:' . $offset);
$this->addVirtualFile($ret['filename'], '', $ret['data']);
if ($this->getError()) {
return false;
}
} elseif ($ret['done']) {
$registry = AEFactory::getConfiguration();
$embedded_installer = $registry->get('akeeba.advanced.embedded_installer');
$installerDescriptors = AEUtilInihelper::getInstallerList();
$packages = $installerDescriptors[$embedded_installer]['package'];
$packages = explode(',', $packages);
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, ' Done with package ' . $packages[$index]);
if (count($packages) > $index + 1) {
//.........这里部分代码省略.........
/**
* Applies the size and count quotas
*
* @return bool
*/
private function get_remote_quotas()
{
// Get all records with a remote filename
$allRecords = AEPlatform::getInstance()->get_valid_remote_records();
// Bail out if no records found
if (empty($allRecords)) {
return array();
}
// Try to find the files to be deleted due to quota settings
$statistics = AEFactory::getStatistics();
$latestBackupId = $statistics->getId();
// Filter out the current record
$temp = array();
foreach ($allRecords as $item) {
if ($item['id'] == $latestBackupId) {
continue;
}
$item['files'] = $this->get_remote_files($item['remote_filename'], $item['multipart']);
$temp[] = $item;
}
$allRecords = $temp;
// Bail out if only the current backup was included in the list
if (count($allRecords) == 0) {
return array();
}
// Get quota values
$registry = AEFactory::getConfiguration();
$countQuota = $registry->get('akeeba.quota.count_quota');
$sizeQuota = $registry->get('akeeba.quota.size_quota');
$useCountQuotas = $registry->get('akeeba.quota.enable_count_quota');
$useSizeQuotas = $registry->get('akeeba.quota.enable_size_quota');
$useDayQuotas = $registry->get('akeeba.quota.maxage.enable');
$daysQuota = $registry->get('akeeba.quota.maxage.maxdays');
$preserveDay = $registry->get('akeeba.quota.maxage.keepday');
$leftover = array();
$ret = array();
$killids = array();
if ($useDayQuotas) {
$killDatetime = new DateTime();
$killDatetime->modify('-' . $daysQuota . ($daysQuota == 1 ? ' day' : ' days'));
$killTS = $killDatetime->format('U');
foreach ($allRecords as $def) {
$backupstart = new DateTime($def['backupstart']);
$backupTS = $backupstart->format('U');
$backupDay = $backupstart->format('d');
// Is this on a preserve day?
if ($preserveDay > 0) {
if ($preserveDay == $backupDay) {
$leftover[] = $def;
continue;
}
}
// Otherwise, check the timestamp
if ($backupTS < $killTS) {
$ret[] = $def['files'];
$killids[] = $def['id'];
} else {
$leftover[] = $def;
}
}
}
// Do we need to apply count quotas?
if ($useCountQuotas && $countQuota >= 1 && !$useDayQuotas) {
$countQuota--;
// Are there more files than the quota limit?
if (!(count($allRecords) > $countQuota)) {
// No, effectively skip the quota checking
$leftover = $allRecords;
} else {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Processing remote count quotas");
// Yes, apply the quota setting.
$totalRecords = count($allRecords);
for ($count = 0; $count <= $totalRecords; $count++) {
$def = array_pop($allRecords);
if (count($leftover) >= $countQuota) {
$ret[] = $def['files'];
$killids[] = $def['id'];
} else {
$leftover[] = $def;
}
}
unset($allRecords);
}
} else {
// No count quotas are applied
$leftover = $allRecords;
}
// Do we need to apply size quotas?
if ($useSizeQuotas && $sizeQuota > 0 && count($leftover) > 0 && !$useDayQuotas) {
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Processing remote size quotas");
// OK, let's start counting bytes!
$runningSize = 0;
while (count($leftover) > 0) {
// Each time, remove the last element of the backup array and calculate
// running size. If it's over the limit, add the archive to the $ret array.
//.........这里部分代码省略.........
public function processPart($absolute_filename, $upload_as = null)
{
// Retrieve engine configuration data
$config = AEFactory::getConfiguration();
$accesskey = trim($config->get('engine.postproc.googlestorage.accesskey', ''));
$secret = trim($config->get('engine.postproc.googlestorage.secretkey', ''));
$usessl = $config->get('engine.postproc.googlestorage.usessl', 0) == 0 ? false : true;
$bucket = $config->get('engine.postproc.googlestorage.bucket', '');
$directory = $config->get('volatile.postproc.directory', null);
$lowercase = $config->get('engine.postproc.googlestorage.lowercase', 1);
if (empty($directory)) {
$directory = $config->get('engine.postproc.googlestorage.directory', 0);
}
// Sanity checks
if (empty($accesskey)) {
$this->setError('You have not set up your Google Storage Access Key');
return false;
}
if (empty($secret)) {
$this->setError('You have not set up your Google Storage Secret Key');
return false;
}
if (empty($bucket)) {
$this->setError('You have not set up your Google Storage Bucket');
return false;
} else {
// Remove any slashes from the bucket
$bucket = str_replace('/', '', $bucket);
if ($lowercase) {
$bucket = strtolower($bucket);
}
}
// Create an S3 instance with the required credentials
$s3 = AEUtilAmazons3::getInstance($accesskey, $secret, $usessl);
$s3->defaultHost = 'commondatastorage.googleapis.com';
// If we are here, we'll have to start uploading the file. Let's prepare ourselves for that.
// Fix the directory name, if required
if (!empty($directory)) {
$directory = trim($directory);
$directory = ltrim(AEUtilFilesystem::TranslateWinPath($directory), '/');
} else {
$directory = '';
}
// Parse tags
$directory = AEUtilFilesystem::replace_archive_name_variables($directory);
$config->set('volatile.postproc.directory', $directory);
// Calculate relative remote filename
$filename = empty($upload_as) ? basename($absolute_filename) : $upload_as;
if (!empty($directory) && $directory != '/') {
$filename = $directory . '/' . $filename;
}
// Store the absolute remote path in the class property
$this->remote_path = $filename;
// Do we have to upload in one go or do a multipart upload instead?
$filesize = @filesize($absolute_filename);
AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Google Storage -- Uploading " . basename($absolute_filename));
// Legacy single part uploads
$result = $s3->putObject(AEUtilAmazons3::inputFile($absolute_filename, false), $bucket, $filename, AEUtilAmazons3::ACL_BUCKET_OWNER_FULL_CONTROL, array(), array());
// Return the result
$this->propagateFromObject($s3);
return $result;
}
/**
* Resets the Kettenrad state, wipping out any pending backups and/or stale
* temporary data.
*
* @param array $config Configuration parameters for the reset operation
*/
public static function reset($config = array())
{
$default_config = array('global' => true, 'log' => false, 'maxrun' => 0);
$config = (object) array_merge($default_config, $config);
// Pause logging if so desired
if (!$config->log) {
AEUtilLogger::WriteLog(false, '');
}
$tag = null;
if (!$config->global) {
// If we're not resetting globally, get a list of running backups per tag
$tag = AEPlatform::getInstance()->get_backup_origin();
}
// Cache the factory before proceeding
$factory = AEFactory::serialize();
$runningList = AEPlatform::getInstance()->get_running_backups($tag);
// Origins we have to clean
$origins = array(AEPlatform::getInstance()->get_backup_origin());
// 1. Detect failed backups
if (is_array($runningList) && !empty($runningList)) {
// The current timestamp
$now = time();
// Mark running backups as failed
foreach ($runningList as $running) {
if (empty($tag)) {
// Check the timestamp of the log file to decide if it's stuck,
// but only if a tag is not set
$tstamp = @filemtime(AEUtilLogger::logName($running['origin']));
if ($tstamp !== false) {
// We can only check the timestamp if it's returned. If not, we assume the backup is stale
$difference = abs($now - $tstamp);
// Backups less than 3 minutes old are not considered stale
if ($difference < $config->maxrun) {
continue;
}
}
}
$filenames = AEUtilStatistics::get_all_filenames($running, false);
// Process if there are files to delete...
if (!is_null($filenames)) {
// Delete the failed backup's archive, if exists
foreach ($filenames as $failedArchive) {
AEPlatform::getInstance()->unlink($failedArchive);
}
}
// Mark the backup failed
$running['status'] = 'fail';
$running['multipart'] = 0;
$dummy = null;
AEPlatform::getInstance()->set_or_update_statistics($running['id'], $running, $dummy);
$origins[] = $running['origin'];
}
}
if (!empty($origins)) {
$origins = array_unique($origins);
foreach ($origins as $tag) {
AECoreKettenrad::load($tag);
// Remove temporary files
AEUtilTempfiles::deleteTempFiles();
// Delete any stale temporary data
AEUtilTempvars::reset($tag);
}
}
// Reload the factory
AEFactory::unserialize($factory);
unset($factory);
// Unpause logging if it was previously paused
if (!$config->log) {
AEUtilLogger::WriteLog(true, '');
}
}
请发表评论