{"record":{"id":"c4511855c83e0e6a","repo":"ruvnet/RuView","slug":"tar-failed-error-msg","errorCode":null,"errorMessage":"tar failed: {error_msg}","messagePattern":"tar failed: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"archive/v1/src/tasks/backup.py","lineNumber":263,"sourceCode":"            \n            # Create tar.gz archive\n            tar_cmd = [\n                \"tar\", \"-czf\", str(backup_path),\n                \"-C\", str(temp_dir),\n                \".\"\n            ]\n            \n            process = await asyncio.create_subprocess_exec(\n                *tar_cmd,\n                stdout=asyncio.subprocess.PIPE,\n                stderr=asyncio.subprocess.PIPE\n            )\n            \n            stdout, stderr = await process.communicate()\n            \n            if process.returncode != 0:\n                error_msg = stderr.decode() if stderr else \"Unknown tar error\"\n                raise Exception(f\"tar failed: {error_msg}\")\n            \n            backup_size_mb = self._get_file_size_mb(backup_path)\n            \n            # Clean up old backups\n            self._cleanup_old_backups(\"configuration_*.tar.gz\", self.retention_days)\n            \n            return {\n                \"backup_file\": backup_filename,\n                \"backup_path\": str(backup_path),\n                \"backup_size_mb\": backup_size_mb,\n                \"copied_files\": copied_files,\n                \"retention_days\": self.retention_days,\n            }\n            \n        finally:\n            # Clean up temporary directory\n            if temp_dir.exists():\n                shutil.rmtree(temp_dir)","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/archive/v1/src/tasks/backup.py#L245-L281","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Ensure the backup directory exists and is writable by the service user; create it before scheduling backups.","Fix permissions on the config files listed in config_files so the service account can read them.","Read the embedded stderr for the specific file tar rejected and address that path."],"exampleFix":"# before\nresult = await config_backup.execute_backup(session)  # Exception: tar failed: ...\n\n# after\nimport shutil\nfrom pathlib import Path\nif shutil.which('tar') is None:\n    raise RuntimeError('tar is required for configuration backup')\nconfig_backup.backup_dir.mkdir(parents=True, exist_ok=True)\nresult = await config_backup.execute_backup(session)","handlingStrategy":"try-catch","validationCode":"import shutil\nif shutil.which('tar') is None:\n    raise RuntimeError('tar is required for backups')\nconfig_backup.backup_dir.mkdir(parents=True, exist_ok=True)","typeGuard":null,"tryCatchPattern":"try:\n    result = await config_backup.execute_backup(session)\nexcept Exception as exc:\n    logger.error('configuration backup failed: %s', exc)  # stderr detail is embedded\n    notify_ops(f'config backup failed: {exc}')\n    raise","preventionTips":["Include tar in deployment images explicitly and fail the build if 'tar --version' fails.","Provision and permission the backup directory before scheduling tasks.","Keep the config file list in sync with files that actually exist in the deployment (missing files are skipped, but unreadable ones abort tar)."],"tags":["backup","tar","configuration","archiving","ops"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}