pulumi/pulumi · error

backing up existing configuration file

Error message

backing up existing configuration file: %w

What it means

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.

Solutions

  1. Check write/execute permissions on the project directory and that you own Pulumi.<stack>.yaml; run as a user that can rename it.
  2. Confirm Pulumi.<stack>.yaml still exists right before running (`ls -la Pulumi.*.yaml`) and no concurrent process is touching it.
  3. Re-run with `pulumi config refresh --force` to skip the backup rename and save in place (only if the backup is not needed).
  4. Inspect the wrapped %w error (e.g. EACCES, ENOENT, EXDEV) to identify the exact filesystem cause.

Example fix

// before (shell)
pulumi config refresh   # fails: rename read-only
// after (shell)
chmod u+w . && pulumi config refresh
# or, when backup is unnecessary:
pulumi config refresh --force
Defensive patterns

Strategy: validation

Validate before calling

// shell
[ -w . ] && [ -w Pulumi.dev.yaml ] && pulumi config refresh || echo 'need write access for backup'

Try / catch

pulumi config refresh 2>&1 | grep -q 'backing up existing configuration file' && pulumi config refresh --force

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31). Data as JSON: /api/errors/7f23c2c2308c3614. Report an issue: GitHub.

Appendix: source

Thrown at pkg/cmd/pulumi/config/config.go:668

				if err != nil {
					return err
				}
			}

			// If the configuration file doesn't exist, or force has been passed, save it in place.
			if _, err = os.Stat(configPath); os.IsNotExist(err) || force {
				return ps.Save(configPath)
			}

			// Otherwise we'll create a backup, let's figure out what name to use by adding ".bak" over and over
			// until we get to a name not in use.
			backupFile := configPath + ".bak"
			for {
				_, err = os.Stat(backupFile)
				if os.IsNotExist(err) {
					if err = os.Rename(configPath, backupFile); err != nil { //nolint:forbidigo // historic os.Rename usage
						return fmt.Errorf("backing up existing configuration file: %w", err)
					}

					fmt.Fprintf(cmd.OutOrStdout(), "backed up existing configuration file to %s\n", backupFile)
					break
				} else if err != nil {
					return fmt.Errorf("backing up existing configuration file: %w", err)
				}

				backupFile = backupFile + ".bak"
			}

			err = ps.Save(configPath)
			if err == nil {
				fmt.Fprintf(cmd.OutOrStdout(), "refreshed configuration for stack '%s'\n", s.Ref().Name())
			}
			return err
		},
	}

View on GitHub (pinned to 793f7b2e16)