aboutsummaryrefslogtreecommitdiffstats
path: root/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php')
-rw-r--r--core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php41
1 files changed, 16 insertions, 25 deletions
diff --git a/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php b/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php
index e90cb73eb42..d1ecc08ca4b 100644
--- a/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php
+++ b/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php
@@ -3,31 +3,14 @@
declare(strict_types=1);
/**
- * @copyright 2018 Morris Jobke <hey@morrisjobke.de>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Morris Jobke <hey@morrisjobke.de>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Core\BackgroundJobs;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\QueuedJob;
+use OCP\Files;
use OCP\IConfig;
use Psr\Log\LoggerInterface;
@@ -46,17 +29,20 @@ class BackgroundCleanupUpdaterBackupsJob extends QueuedJob {
* @param array $argument
*/
public function run($argument): void {
+ $this->log->info('Running background job to clean-up outdated updater backups');
+
$updateDir = $this->config->getSystemValue('updatedirectory', null) ?? $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data');
$instanceId = $this->config->getSystemValue('instanceid', null);
if (!is_string($instanceId) || empty($instanceId)) {
+ $this->log->error('Skipping updater backup clean-up - instanceId is missing!');
return;
}
$updaterFolderPath = $updateDir . '/updater-' . $instanceId;
$backupFolderPath = $updaterFolderPath . '/backups';
if (file_exists($backupFolderPath)) {
- $this->log->info("$backupFolderPath exists - start to clean it up");
+ $this->log->debug("Updater backup folder detected: $backupFolderPath");
$dirList = [];
$dirs = new \DirectoryIterator($backupFolderPath);
@@ -70,6 +56,8 @@ class BackgroundCleanupUpdaterBackupsJob extends QueuedJob {
$realPath = $dir->getRealPath();
if ($realPath === false) {
+ $pathName = $dir->getPathname();
+ $this->log->warning("Skipping updater backup folder: $pathName (not found)");
continue;
}
@@ -79,15 +67,18 @@ class BackgroundCleanupUpdaterBackupsJob extends QueuedJob {
ksort($dirList);
// drop the newest 3 directories
$dirList = array_slice($dirList, 0, -3);
- $this->log->info("List of all directories that will be deleted: " . json_encode($dirList));
+ $this->log->debug('Updater backup folders that will be deleted: ' . json_encode($dirList));
foreach ($dirList as $dir) {
$this->log->info("Removing $dir ...");
- \OC_Helper::rmdirr($dir);
+ $result = Files::rmdirr($dir);
+ if (!$result) {
+ $this->log->error('Could not remove updater backup folder $dir');
+ }
}
- $this->log->info("Cleanup finished");
+ $this->log->info('Background job to clean-up updater backups has finished');
} else {
- $this->log->info("Could not find updater directory $backupFolderPath - cleanup step not needed");
+ $this->log->warning("Skipping updater backup clean-up - could not find updater backup folder $backupFolderPath");
}
}
}