{"record":{"id":"b093e04b0ebefa8b","repo":"VictoriaMetrics/VictoriaMetrics","slug":"cannot-create-file-q-w","errorCode":null,"errorMessage":"cannot create file %q: %w","messagePattern":"cannot create file %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/backup/fsremote/fsremote.go","lineNumber":168,"sourceCode":"\t}\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot download data from %q: %w\", path, err)\n\t}\n\tif uint64(n) != p.Size {\n\t\treturn fmt.Errorf(\"wrong data size downloaded from %q; got %d bytes; want %d bytes\", path, n, p.Size)\n\t}\n\treturn nil\n}\n\n// UploadPart uploads p from r to fs.\nfunc (fs *FS) UploadPart(p common.Part, r io.Reader) error {\n\tpath := fs.path(p)\n\tif err := fs.mkdirAll(path); err != nil {\n\t\treturn err\n\t}\n\tw, err := os.Create(path)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot create file %q: %w\", path, err)\n\t}\n\tn, err := io.Copy(w, r)\n\tif err := w.Sync(); err != nil {\n\t\treturn fmt.Errorf(\"cannot fsync file: %q: %w\", w.Name(), err)\n\t}\n\tif err1 := w.Close(); err1 != nil && err == nil {\n\t\terr = err1\n\t}\n\tif err != nil {\n\t\t_ = os.RemoveAll(path)\n\t\treturn fmt.Errorf(\"cannot upload data to %q: %w\", path, err)\n\t}\n\tif uint64(n) != p.Size {\n\t\t_ = os.RemoveAll(path)\n\t\treturn fmt.Errorf(\"wrong data size uploaded to %q; got %d bytes; want %d bytes\", path, n, p.Size)\n\t}\n\treturn nil\n}","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/backup/fsremote/fsremote.go#L150-L186","documentation":"UploadPart creates the destination part file with os.Create after ensuring its parent directory exists. This error wraps any failure from os.Create — most commonly permission denied on the target directory, or the path is a directory / read-only filesystem. It is thrown before any bytes are copied.","triggerScenarios":"Calling UploadPart when the remote dir path exists but is not writable by the process user, a file/symlink already exists at the target path with restrictive permissions, the target name collides with an existing directory, or the underlying filesystem is read-only (e.g. read-only mount).","commonSituations":"Backup destination mounted read-only (failed-over NFS/S3-fs mount); fsremote dir owned by a different user than the vmbackup process (container running as non-root vs dir created by root); path collision because a part filename was created as a directory by accident; SELinux/AppArmor denial.","solutions":["Check permissions on the remote dir and chown/chmod it so the process user can write (dir is created with 0700)","Verify the target path is not an existing directory: `ls -la` the parent dir for the offending name","Remount the destination read-write if it is a read-only mount","Check container security contexts / SELinux denials (audit2allow, `dmesg`)"],"exampleFix":"// before: dir created by root, process runs as non-root\nsudo mkdir -p /backups/vm && sudo chmod 755 /backups/vm\n// after: give the backup user ownership\nsudo chown -R vmbackup:vmbackup /backups/vm && sudo chmod 700 /backups/vm","handlingStrategy":"validation","validationCode":"import \"os\"\nfunc ensureRemoteWritable(dir string) error {\n\tif info, err := os.Stat(dir); err != nil {\n\t\treturn err\n\t} else if !info.IsDir() {\n\t\treturn fmt.Errorf(\"%s is not a directory\", dir)\n\t}\n\tprobe := filepath.Join(dir, \".write-probe\")\n\tif err := os.WriteFile(probe, []byte(\"ok\"), 0600); err != nil {\n\t\treturn fmt.Errorf(\"remote dir %s not writable: %w\", dir, err)\n\t}\n\treturn os.Remove(probe)\n}","typeGuard":null,"tryCatchPattern":"err := fsRemote.UploadPart(part, r)\nif errors.Is(err, os.ErrPermission) {\n\t// fix ownership/permissions of remote dir or run as correct user\n} else if err != nil {\n\treturn fmt.Errorf(\"upload failed: %w\", err)\n}","preventionTips":["Run the backup process as the same user that owns the remote dir (dir is created 0700)","Check the destination is not a read-only mount before the backup starts","Probe writability with a temp file as a pre-flight check","Avoid placing remote dirs where part names may collide with existing paths"],"tags":["backup","filesystem","permissions","os-create"],"backgroundTag":"permission-denied","analyzedSha":"5079fb58f1e8e62113f90c945ad71586c797d770","analyzedAt":"2026-09-03T18:10:26.153Z","contentChangedAt":"2026-09-03T18:10:26.153Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}