From 9450217cc28d95a0a97934f5c5fe3db99e2d1aae Mon Sep 17 00:00:00 2001 From: Alexander Sabino <32822107+asabino2@users.noreply.github.com> Date: Thu, 7 May 2026 11:14:53 +0100 Subject: [PATCH] =?UTF-8?q?Ajusta=20o=20tratamento=20de=20c=C3=B3digos=20d?= =?UTF-8?q?e=20sa=C3=ADda=20em=20comandos=20de=20container=20e=20modifica?= =?UTF-8?q?=20a=20l=C3=B3gica=20de=20tar=20para=20aceitar=20avisos=20como?= =?UTF-8?q?=20sucesso?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backupService.js | 11 +++++++---- src/dockerService.js | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/backupService.js b/src/backupService.js index 700bbfc..d695c0c 100644 --- a/src/backupService.js +++ b/src/backupService.js @@ -457,25 +457,28 @@ class BackupService { } const tarParts = [ - 'set -eu', + 'set -u', 'umask 077', 'echo "__DBKP_TAR_BEGIN__" 1>&2', ]; + // GNU tar: exit 0 = ok, exit 1 = avisos (arquivos mudaram, permissão negada), exit 2 = erro fatal. + // Aceitamos exit 1 como sucesso para não descartar archives válidos com avisos menores. if (backupScope === 'container') { tarParts.push( - `tar --warning=no-file-changed --ignore-failed-read ${tarIncrementalFlag} -czvf - -C / --exclude=proc --exclude=sys --exclude=dev --exclude=run --exclude=tmp .` + `tar --ignore-failed-read ${tarIncrementalFlag} -czvf - -C / --exclude=proc --exclude=sys --exclude=dev --exclude=run --exclude=tmp .; TAR_RC=$?; [ $TAR_RC -le 1 ] || exit $TAR_RC` ); } else { tarParts.push( - `tar --warning=no-file-changed --ignore-failed-read ${tarIncrementalFlag} -czvf - -C / ${relSourcePaths.map((item) => shellQuote(item)).join(' ')}` + `tar --ignore-failed-read ${tarIncrementalFlag} -czvf - -C / ${relSourcePaths.map((item) => shellQuote(item)).join(' ')}; TAR_RC=$?; [ $TAR_RC -le 1 ] || exit $TAR_RC` ); } updateFileProgress(); pushLog('Iniciando compactacao tar do container.', 'gerando-tar'); - await this.dockerService.streamContainerCommandToFile(containerId, tarParts.join(' && '), absoluteArchivePath, { + await this.dockerService.streamContainerCommandToFile(containerId, tarParts.join('; '), absoluteArchivePath, { + maxOkExitCode: 1, onOutput: (line, stream) => { const normalizedLine = String(line || '').trim(); if (!normalizedLine || stream !== 'stderr' || normalizedLine.startsWith('__DBKP_TAR_BEGIN__')) { diff --git a/src/dockerService.js b/src/dockerService.js index 87f6f90..a4e6c14 100644 --- a/src/dockerService.js +++ b/src/dockerService.js @@ -265,6 +265,7 @@ class DockerService { async streamContainerCommandToFile(containerId, cmd, targetFilePath, options = {}) { const onOutput = typeof options.onOutput === 'function' ? options.onOutput : () => {}; + const maxOkExitCode = typeof options.maxOkExitCode === 'number' ? options.maxOkExitCode : 0; const container = this.docker.getContainer(containerId); const exec = await container.exec({ AttachStdout: true, @@ -323,7 +324,7 @@ class DockerService { }), ]); - if (info.ExitCode !== 0) { + if (info.ExitCode > maxOkExitCode) { throw new Error(`Comando de stream em container terminou com codigo ${info.ExitCode}`); } }