{"record":{"id":"c3643f8d8129334b","repo":"caddyserver/caddy","slug":"opening-output-file-v","errorCode":null,"errorMessage":"opening output file: %v","messagePattern":"opening output file: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/storagefuncs.go","lineNumber":183,"sourceCode":"\t\t}\n\t} else {\n\t\tstor = caddy.DefaultStorage\n\t}\n\n\t// enumerate all keys\n\tkeys, err := stor.List(ctx, \"\", true)\n\tif err != nil {\n\t\treturn caddy.ExitCodeFailedStartup, err\n\t}\n\n\t// setup output\n\tvar f *os.File\n\tif exportStorageCmdOutputFlag == \"-\" {\n\t\tf = os.Stdout\n\t} else {\n\t\tf, err = os.Create(exportStorageCmdOutputFlag)\n\t\tif err != nil {\n\t\t\treturn caddy.ExitCodeFailedStartup, fmt.Errorf(\"opening output file: %v\", err)\n\t\t}\n\t\tdefer f.Close()\n\t}\n\n\t// `IsTerminal: true` keys hold the values we\n\t// care about, write them out\n\ttw := tar.NewWriter(f)\n\tfor _, k := range keys {\n\t\tinfo, err := stor.Stat(ctx, k)\n\t\tif err != nil {\n\t\t\tif errors.Is(err, fs.ErrNotExist) {\n\t\t\t\tcaddy.Log().Warn(fmt.Sprintf(\"key: %s removed while export is in-progress\", k))\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\treturn caddy.ExitCodeFailedQuit, err\n\t\t}\n\n\t\tif info.IsTerminal {","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/cmd/storagefuncs.go#L165-L201","documentation":"cmdExportStorage ('caddy storage export') failed at os.Create of the --output file (unless '-' was passed for stdout). Keys were already listed from storage, but nothing has been written yet. Standard os.PathError causes: directory does not exist, permission denied, or a path that is a directory.","triggerScenarios":"Output path in a nonexistent directory (os.Create does not create parents); unwritable destination; --output pointing at a directory; invalid path characters.","commonSituations":"Exporting to /var/backups/caddy/storage.tar before creating /var/backups/caddy; unprivileged user writing to a root-owned dir; typo'd path.","solutions":["Create the parent directory: mkdir -p $(dirname <output.tar>)","Choose a writable location or run with sudo as the storage-owning user","Ensure --output names a file, not a directory","Or export to stdout: --output - > /path/storage.tar"],"exampleFix":"# before\ncaddy storage export --config caddy.json --output /var/backups/caddy/storage.tar\n# error: opening output file: open /var/backups/caddy/storage.tar: no such file or directory\n\n# after\nmkdir -p /var/backups/caddy\ncaddy storage export --config caddy.json --output /var/backups/caddy/storage.tar","handlingStrategy":"validation","validationCode":"OUT=/var/backups/caddy/storage.tar\nmkdir -p \"$(dirname \"$OUT\")\" && [ -w \"$(dirname \"$OUT\")\" ] || echo 'output dir missing/unwritable'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["mkdir -p the output directory before exporting (os.Create will not create parents)","Use absolute output paths and confirm writability in scripts","Use --output - piped to a file when directory setup is inconvenient"],"tags":["storage","export","filesystem","cli"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}