Skip to content

Commit

Permalink
feat(rclone): 🙈 Ignore stderr lines to consider a backup as successful
Browse files Browse the repository at this point in the history
  • Loading branch information
p-bizouard committed Jan 5, 2024
1 parent 708ad46 commit 8220765
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
31 changes: 31 additions & 0 deletions migrations/Version20240105231602.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240105231602 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE backup_configuration ADD std_err_ignore TEXT DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE backup_configuration DROP std_err_ignore');
}
}
5 changes: 5 additions & 0 deletions src/Controller/Admin/BackupConfigurationCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ public function configureFields(string $pageName): iterable
->addCssClass('blur-input backupConfigurationType-field ssh-cmd')
->setHelp('Command to clean the remote host after backup'),

TextField::new('stdErrIgnore')
->hideOnIndex()
->addCssClass('backupConfigurationType-field rclone')
->setHelp('Regex to ignore errors in stderr. If all lines are ignored, the backup will be considered as successful'),

TextField::new('customExtension')
->hideOnIndex()
->setHelp('Suffix the backup with custom extension')
Expand Down
17 changes: 17 additions & 0 deletions src/Entity/BackupConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ class BackupConfiguration implements Stringable
*/
private ?string $customExtension = null;

/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $stdErrIgnore = null;

/**
* @ORM\Column(type="smallint", nullable=true)
*/
Expand Down Expand Up @@ -525,4 +530,16 @@ public function setRcloneFlags(?string $rcloneFlags): self

return $this;
}

public function getStdErrIgnore(): ?string
{
return $this->stdErrIgnore;
}

public function setStdErrIgnore(?string $stdErrIgnore): static
{
$this->stdErrIgnore = $stdErrIgnore;

return $this;
}
}
8 changes: 8 additions & 0 deletions src/Service/BackupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,14 @@ public function uploadBackup(Backup $backup): void
$process->run();

if (!$process->isSuccessful()) {
if ($backup->getBackupConfiguration()->getStdErrIgnore()) {
if ('' === preg_replace('/^\s+/m', '', preg_replace($backup->getBackupConfiguration()->getStdErrIgnore(), '', $process->getErrorOutput()))) {
$this->log($backup, Log::LOG_WARNING, sprintf('Warning executing backup - rclone sync - %s', $process->getErrorOutput()));

break;
}
}

$this->log($backup, Log::LOG_ERROR, sprintf('Error executing backup - rclone sync - %s', $process->getErrorOutput()));
throw new ProcessFailedException($process);
} else {
Expand Down

0 comments on commit 8220765

Please sign in to comment.