4
0
mirror of https://github.com/AzuraCast/AzuraCast.git synced 2024-06-16 22:17:06 +00:00

Remove external Rotate library and rotate backups for all filesystems.

This commit is contained in:
Buster "Silver Eagle" Neece 2020-12-18 17:49:00 -06:00
parent 376d087dcc
commit cc067943ac
No known key found for this signature in database
GPG Key ID: 6D9E12FF03411F4E
5 changed files with 44 additions and 72 deletions

View File

@ -60,7 +60,6 @@
"slim/slim": "^4.2",
"spatie/flysystem-dropbox": "^1.2",
"spomky-labs/otphp": "^10.0",
"studio24/rotate": "^1.0",
"supervisorphp/supervisor": "dev-master",
"symfony/cache": "^5.2",
"symfony/console": "^5",

53
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "152d1c444de811053c2d92c6b87881ab",
"content-hash": "c7f942c7d2a7915b3ec57b10e19d824b",
"packages": [
{
"name": "aws/aws-sdk-php",
@ -5828,57 +5828,6 @@
},
"time": "2020-01-28T09:24:19+00:00"
},
{
"name": "studio24/rotate",
"version": "v1.0.1",
"source": {
"type": "git",
"url": "https://github.com/studio24/rotate.git",
"reference": "9d99d364bcf619bd9dd48f09ccf292f077c492e8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/studio24/rotate/zipball/9d99d364bcf619bd9dd48f09ccf292f077c492e8",
"reference": "9d99d364bcf619bd9dd48f09ccf292f077c492e8",
"shasum": ""
},
"require": {
"php": ">=5.6.0"
},
"require-dev": {
"phpunit/phpunit": "^5.2"
},
"type": "library",
"autoload": {
"psr-4": {
"studio24\\Rotate\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Simon R Jones",
"email": "hello@studio24.net",
"homepage": "http://simonrjones.net",
"role": "Developer"
}
],
"description": "File rotation utility which rotates and removes old files",
"homepage": "https://github.com/studio24/rotate",
"keywords": [
"delete files",
"logrotate",
"rotate"
],
"support": {
"issues": "https://github.com/studio24/rotate/issues",
"source": "https://github.com/studio24/rotate/tree/v1.0.1"
},
"time": "2019-02-02T13:04:46+00:00"
},
{
"name": "supervisorphp/supervisor",
"version": "dev-master",

View File

@ -249,8 +249,9 @@ return [
$logger->pushHandler($log_stderr);
}
$log_file = new Monolog\Handler\StreamHandler(
$log_file = new Monolog\Handler\RotatingFileHandler(
$environment->getTempDirectory() . '/app.log',
5,
$loggingLevel,
true
);

View File

@ -6,8 +6,8 @@ use App\Entity;
use App\Environment;
use App\Radio\Adapters;
use Doctrine\ORM\EntityManagerInterface;
use Jhofm\FlysystemIterator\Options\Options;
use Psr\Log\LoggerInterface;
use studio24\Rotate;
use Supervisor\Supervisor;
use Symfony\Component\Finder\Finder;
@ -60,18 +60,11 @@ class RotateLogsTask extends AbstractTask
}
}
// Rotate the main AzuraCast log.
$rotate = new Rotate\Rotate($this->environment->getTempDirectory() . '/app.log');
$rotate->keep(5);
$rotate->size('5MB');
$rotate->run();
// Rotate the automated backups.
$settings = $this->settingsRepo->readSettings();
$backups_to_keep = $settings->getBackupKeepCopies();
if ($backups_to_keep > 0) {
$copiesToKeep = $settings->getBackupKeepCopies();
if ($copiesToKeep > 0) {
$backupStorageId = (int)$settings->getBackupStorageLocation();
if ($backupStorageId > 0) {
@ -80,18 +73,48 @@ class RotateLogsTask extends AbstractTask
$backupStorageId
);
if ($storageLocation instanceof Entity\StorageLocation && $storageLocation->isLocal()) {
$fs = $storageLocation->getFilesystem();
$autoBackupPath = $fs->getFullPath('automatic_backup.zip');
$rotate = new Rotate\Rotate($autoBackupPath);
$rotate->keep($backups_to_keep);
$rotate->run();
if ($storageLocation instanceof Entity\StorageLocation) {
$this->rotateBackupStorage($storageLocation, $copiesToKeep);
}
}
}
}
protected function rotateBackupStorage(
Entity\StorageLocation $storageLocation,
int $copiesToKeep
): void {
$fs = $storageLocation->getFilesystem();
$iterator = $fs->createIterator(
'',
[
Options::OPTION_IS_RECURSIVE => false,
Options::OPTION_FILTER => function (array $item): bool {
return (isset($item['path']) && 0 === stripos($item['path'], 'automatic_backup'));
},
]
);
$backupsByTime = [];
foreach ($iterator as $backup) {
$backupsByTime[$backup['timestamp']] = $backup['path'];
}
if (count($backupsByTime) <= $copiesToKeep) {
return;
}
krsort($backupsByTime);
$backupsToDelete = array_slice($backupsByTime, $copiesToKeep);
foreach ($backupsToDelete as $backupToDelete) {
$fs->delete($backupToDelete);
$this->logger->info(sprintf('Deleted automated backup: "%s"', $backupToDelete));
}
}
/**
* Rotate logs that are not automatically rotated (currently Liquidsoap only).
*

View File

@ -143,7 +143,7 @@ class RunBackupTask extends AbstractTask
$message = new Message\BackupMessage();
$message->storageLocationId = $storageLocationId;
$message->path = 'automatic_backup.zip';
$message->path = 'automatic_backup_' . gmdate('Ymd_His') . '.zip';
$message->excludeMedia = $settings->getBackupExcludeMedia();
$this->messageBus->dispatch($message);