Ajusta o tratamento de códigos de saída em comandos de container e modifica a lógica de tar para aceitar avisos como sucesso

This commit is contained in:
Alexander Sabino 2026-05-07 11:14:53 +01:00
parent f1931271b7
commit 9450217cc2
2 changed files with 9 additions and 5 deletions

View File

@ -457,25 +457,28 @@ class BackupService {
} }
const tarParts = [ const tarParts = [
'set -eu', 'set -u',
'umask 077', 'umask 077',
'echo "__DBKP_TAR_BEGIN__" 1>&2', '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') { if (backupScope === 'container') {
tarParts.push( 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 { } else {
tarParts.push( 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(); updateFileProgress();
pushLog('Iniciando compactacao tar do container.', 'gerando-tar'); 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) => { onOutput: (line, stream) => {
const normalizedLine = String(line || '').trim(); const normalizedLine = String(line || '').trim();
if (!normalizedLine || stream !== 'stderr' || normalizedLine.startsWith('__DBKP_TAR_BEGIN__')) { if (!normalizedLine || stream !== 'stderr' || normalizedLine.startsWith('__DBKP_TAR_BEGIN__')) {

View File

@ -265,6 +265,7 @@ class DockerService {
async streamContainerCommandToFile(containerId, cmd, targetFilePath, options = {}) { async streamContainerCommandToFile(containerId, cmd, targetFilePath, options = {}) {
const onOutput = typeof options.onOutput === 'function' ? options.onOutput : () => {}; const onOutput = typeof options.onOutput === 'function' ? options.onOutput : () => {};
const maxOkExitCode = typeof options.maxOkExitCode === 'number' ? options.maxOkExitCode : 0;
const container = this.docker.getContainer(containerId); const container = this.docker.getContainer(containerId);
const exec = await container.exec({ const exec = await container.exec({
AttachStdout: true, 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}`); throw new Error(`Comando de stream em container terminou com codigo ${info.ExitCode}`);
} }
} }