Backup aborts when a file disappears during archiving (ENOENT from os.Lstat in writeTarball)

Abierto
#908 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@ciltocruz ya está trabajando en esto.

Desde el 25/11/2026.

  • #909 de @ciltocruz — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
20/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
docker, go
Área
backend

Línea de trabajo

Start with cmd/backup/archive.go around writeTarball and inspect how compress() handles its errors; also review cmd/backup/create_archive.go to understand failures during the initial walk. Check the linked pull request #909 for work already underway. Done means missing files during the walk or archive write no longer abort the backup, with tests covering the race and the resulting archive.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

enhancement pr welcome

What happens

If a file is removed or replaced while the archive is being written, the backup aborts completely and the resulting archive is discarded.

This is easy to hit when backing up live application data: a database sidecar file, a session snapshot or a rotating log that changes mid-run is enough to kill the whole backup, after minutes of compression.

Version

  • Running: v2.50.1
  • Code reviewed in: v2.50.2 (same code path)

Expected behavior

A file that no longer exists at archiving time should be skipped (optionally logged as a warning), and the backup should complete with the files that do exist. One transient file is not a reason to discard the entire archive.

Actual behavior

The first ENOENT from os.Lstat aborts the whole run:

  • cmd/backup/create_archive.go:60 — filepath.WalkDir builds the list of paths to archive; any walk error aborts.
  • cmd/backup/archive.go:77 — compress() returns on the first writeTarball error.
  • cmd/backup/archive.go:127 — writeTarball calls os.Lstat(path) and returns the error, including ENOENT.

Error shape:

main.compress: error writing <path> to archive:
main.writeTarball: error getting file info for <path>:
lstat <path>: no such file or directory

The only special cases handled today are sockets (skipped) and symlinks (resolved).

Suggested fix

In writeTarball, treat ENOENT (and optionally ESTALE) as skippable:

fileInfo, err := os.Lstat(path)
if err != nil {
    if errors.Is(err, os.ErrNotExist) {
        // file disappeared between walk and archive; skip it
        return nil
    }
    returnErr = errwrap.Wrap(err, fmt.Sprintf("error getting file info for %s", path))
    return
}

The same guard is needed around os.Open(path), since a file can vanish between Lstat and Open. A warning-level log line per skipped file keeps it observable.

If fail-fast should stay the default, an opt-in variable (e.g. BACKUP_SKIP_MISSING_FILES) would also solve it.

Workarounds tried

  • BACKUP_EXCLUDE_REGEXP — mitigates known paths, but cannot cover files created with unpredictable names at unpredictable times.
  • BACKUP_FROM_SNAPSHOT — deprecated in the current release, and the pre-copy phase walks the tree with lstat too, so the race remains (it also doubles required disk space).
  • BACKUP_STOP_DURING_BACKUP_LABEL — only covers containers, not host processes writing to mounted directories.
  • Filesystem snapshots — not available on every host.

Impact

For anyone backing up live application directories, a single transient file can prevent every backup from completing.

Lenguaje dominante
Go
Estrellas
4.1k
Forks
157
Merge medio
4 h 35 min
PR fusionados (30 d)
15

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de offen/docker-volume-backup

Todos los issues de offen/docker-volume-backup

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.