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}`); } }