ruvnet/RuView · error · Exception

tar failed: {error_msg}

Error message

tar failed: {error_msg}

What it means

ConfigurationBackup.execute_backup() copies the configured config files (settings.py, .env, pyproject.toml, docker-compose.yml, Dockerfile) into a temp directory and tars them with asyncio.create_subprocess_exec('tar', ...). A nonzero tar exit raises Exception with tar's stderr. Typical causes: tar not installed on the host, the backup directory missing or read-only, source files unreadable, or a source file changing while tar reads it.

Source

Thrown at archive/v1/src/tasks/backup.py:263

            
            # Create tar.gz archive
            tar_cmd = [
                "tar", "-czf", str(backup_path),
                "-C", str(temp_dir),
                "."
            ]
            
            process = await asyncio.create_subprocess_exec(
                *tar_cmd,
                stdout=asyncio.subprocess.PIPE,
                stderr=asyncio.subprocess.PIPE
            )
            
            stdout, stderr = await process.communicate()
            
            if process.returncode != 0:
                error_msg = stderr.decode() if stderr else "Unknown tar error"
                raise Exception(f"tar failed: {error_msg}")
            
            backup_size_mb = self._get_file_size_mb(backup_path)
            
            # Clean up old backups
            self._cleanup_old_backups("configuration_*.tar.gz", self.retention_days)
            
            return {
                "backup_file": backup_filename,
                "backup_path": str(backup_path),
                "backup_size_mb": backup_size_mb,
                "copied_files": copied_files,
                "retention_days": self.retention_days,
            }
            
        finally:
            # Clean up temporary directory
            if temp_dir.exists():
                shutil.rmtree(temp_dir)

View on GitHub (pinned to 4685618388)

Solutions

  1. Verify tar exists on the host running the task: 'tar --version'; install it (e.g. apk add tar / apt-get install tar) in the image.
  2. Ensure the backup directory exists and is writable by the service user; create it before scheduling backups.
  3. Fix permissions on the config files listed in config_files so the service account can read them.
  4. Read the embedded stderr for the specific file tar rejected and address that path.

Example fix

# before
result = await config_backup.execute_backup(session)  # Exception: tar failed: ...

# after
import shutil
from pathlib import Path
if shutil.which('tar') is None:
    raise RuntimeError('tar is required for configuration backup')
config_backup.backup_dir.mkdir(parents=True, exist_ok=True)
result = await config_backup.execute_backup(session)
Defensive patterns

Strategy: try-catch

Validate before calling

import shutil
if shutil.which('tar') is None:
    raise RuntimeError('tar is required for backups')
config_backup.backup_dir.mkdir(parents=True, exist_ok=True)

Try / catch

try:
    result = await config_backup.execute_backup(session)
except Exception as exc:
    logger.error('configuration backup failed: %s', exc)  # stderr detail is embedded
    notify_ops(f'config backup failed: {exc}')
    raise

Prevention

When it happens

Trigger: Running the backup task in a slim container image without tar; backup_dir path not created or owned by another user; permissions on .env (often chmod 600, owner root) blocking the service user; editing config files while the nightly backup runs.

Common situations: Alpine/distroless deployment images that omit tar; first run on a fresh host before the backups directory is provisioned; containers running as non-root while mounted volumes are root-owned; devs editing docker-compose.yml during the backup window.

Related errors


AI-assisted analysis of ruvnet/RuView@4685618388 (2026-08-16). Data as JSON: /api/errors/c4511855c83e0e6a. Report an issue: GitHub.