{"record":{"id":"7f23c2c2308c3614","repo":"pulumi/pulumi","slug":"backing-up-existing-configuration-file-w","errorCode":null,"errorMessage":"backing up existing configuration file: %w","messagePattern":"backing up existing configuration file: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cmd/pulumi/config/config.go","lineNumber":668,"sourceCode":"\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If the configuration file doesn't exist, or force has been passed, save it in place.\n\t\t\tif _, err = os.Stat(configPath); os.IsNotExist(err) || force {\n\t\t\t\treturn ps.Save(configPath)\n\t\t\t}\n\n\t\t\t// Otherwise we'll create a backup, let's figure out what name to use by adding \".bak\" over and over\n\t\t\t// until we get to a name not in use.\n\t\t\tbackupFile := configPath + \".bak\"\n\t\t\tfor {\n\t\t\t\t_, err = os.Stat(backupFile)\n\t\t\t\tif os.IsNotExist(err) {\n\t\t\t\t\tif err = os.Rename(configPath, backupFile); err != nil { //nolint:forbidigo // historic os.Rename usage\n\t\t\t\t\t\treturn fmt.Errorf(\"backing up existing configuration file: %w\", err)\n\t\t\t\t\t}\n\n\t\t\t\t\tfmt.Fprintf(cmd.OutOrStdout(), \"backed up existing configuration file to %s\\n\", backupFile)\n\t\t\t\t\tbreak\n\t\t\t\t} else if err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"backing up existing configuration file: %w\", err)\n\t\t\t\t}\n\n\t\t\t\tbackupFile = backupFile + \".bak\"\n\t\t\t}\n\n\t\t\terr = ps.Save(configPath)\n\t\t\tif err == nil {\n\t\t\t\tfmt.Fprintf(cmd.OutOrStdout(), \"refreshed configuration for stack '%s'\\n\", s.Ref().Name())\n\t\t\t}\n\t\t\treturn err\n\t\t},\n\t}","sourceCodeStart":650,"sourceCodeEnd":686,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/pkg/cmd/pulumi/config/config.go#L650-L686","documentation":"Thrown by `pulumi config refresh` when it tries to back up the existing Pulumi.<stack>.yaml by renaming it to a `.bak` file, and the os.Rename call fails. Because os.Stat reported the backup path does not exist, a rename failure usually means a filesystem-level problem (permissions, the config file vanished mid-run, cross-device rename, or the path being occupied by a directory). The refresh is aborted so the existing config file is not lost.","triggerScenarios":"Run `pulumi config refresh` when Pulumi.<stack>.yaml exists (and --force is not passed) and os.Rename(configPath, configPath+\".bak\") fails: e.g. the directory is read-only, the config file was deleted by another process between the Stat and Rename, or configPath is a symlink across filesystems.","commonSituations":"CI containers running as non-root against read-only mounted project directories; another tool (git checkout, editor) deleting or locking Pulumi.<stack>.yaml while the command runs; running the command from a directory whose config is on a read-only network mount.","solutions":["Check write/execute permissions on the project directory and that you own Pulumi.<stack>.yaml; run as a user that can rename it.","Confirm Pulumi.<stack>.yaml still exists right before running (`ls -la Pulumi.*.yaml`) and no concurrent process is touching it.","Re-run with `pulumi config refresh --force` to skip the backup rename and save in place (only if the backup is not needed).","Inspect the wrapped %w error (e.g. EACCES, ENOENT, EXDEV) to identify the exact filesystem cause."],"exampleFix":"// before (shell)\npulumi config refresh   # fails: rename read-only\n// after (shell)\nchmod u+w . && pulumi config refresh\n# or, when backup is unnecessary:\npulumi config refresh --force","handlingStrategy":"validation","validationCode":"// shell\n[ -w . ] && [ -w Pulumi.dev.yaml ] && pulumi config refresh || echo 'need write access for backup'","typeGuard":null,"tryCatchPattern":"pulumi config refresh 2>&1 | grep -q 'backing up existing configuration file' && pulumi config refresh --force","preventionTips":["Ensure the project directory is writable by the user running pulumi in CI.","Use --force when backups are unnecessary.","Avoid concurrent processes touching Pulumi.<stack>.yaml during refresh."],"tags":["cli","filesystem","config-backup","permissions"],"backgroundTag":"filesystem-rename-failed","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}