kopia/kopia · error

action script file ( ) too long: , max allowed

Error message

action script file (%v) too long: %v, max allowed %d

What it means

Raised by setActionCommandFromFlags when the script file supplied via --action-command-script-file is larger than maxScriptLength. Kopia refuses to store oversized action scripts in the policy to keep policy documents small. The error message includes the file path, its byte length, and the maximum allowed size.

Solutions

  1. Shrink the script: move large data or helper code out of the action script and keep only the orchestration logic.
  2. Have the script reference external files on disk instead of embedding their content.
  3. Check the size with `wc -c <file>` and compare with the 'max allowed' value in the error message to confirm the overage.
  4. If the file was picked by mistake, point the flag at the intended, small script file.

Example fix

// before: embedding 2MB of data in the action script
kopia policy set --global --action-command-script-file ./huge-script-with-embedded-data.sh
// error: action script file (./huge-script-with-embedded-data.sh) too long: 2048000, max allowed 65536

// after: keep the script small, reference external data
head -c 100 huge-script-with-embedded-data.sh > action.sh  # or rewrite it to read /var/lib/kopia/data at runtime
kopia policy set --global --action-command-script-file ./action.sh
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
const MAX_SCRIPT_LENGTH = 65536; // confirm against the limit in the error message
function validateScriptSize(path) {
  const size = fs.statSync(path).size;
  if (size > MAX_SCRIPT_LENGTH) {
    throw new Error(`Script ${path} is ${size} bytes; max ${MAX_SCRIPT_LENGTH}`);
  }
  return true;
}

Try / catch

try {
  run(['kopia', 'policy', 'set', '--global', '--action-command-script-file', scriptPath]);
} catch (err) {
  if (/too long: \d+, max allowed (\d+)/.test(String(err.stderr))) {
    const max = Number(err.stderr.match(/max allowed (\d+)/)[1]);
    console.error(`Shrink script to <= ${max} bytes`);
  }
  throw err;
}

Prevention

When it happens

Trigger: Running `kopia policy set ... --action-command-script-file <path>` where the file's byte size exceeds maxScriptLength. Check `wc -c <path>` against the limit shown in the error message.

Common situations: Pointing the flag at a large payload/data file by mistake, bundling a whole library into the action script, or auto-generated scripts that grew over time.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


AI-assisted analysis of kopia/kopia@82495e54b5 (2026-09-07). Data as JSON: /api/errors/9a55373e1d5cd39c. Report an issue: GitHub.

Appendix: source

Thrown at cli/command_policy_set_actions.go:89

		return nil
	}

	*cmd = &policy.ActionCommand{
		TimeoutSeconds: int(c.policySetActionCommandTimeout.Seconds()),
		Mode:           c.policySetActionCommandMode,
	}

	*changeCount++

	if c.policySetPersistActionScript {
		script, err := os.ReadFile(value) //nolint:gosec
		if err != nil {
			return errors.Wrap(err, "unable to read script file")
		}

		if len(script) > maxScriptLength {
			return errors.Errorf("action script file (%v) too long: %v, max allowed %d", value, len(script), maxScriptLength)
		}

		log(ctx).Infof(" - setting %v (%v) action script from file %v (%v bytes) with timeout %v", actionName, c.policySetActionCommandMode, value, len(script), c.policySetActionCommandTimeout)

		(*cmd).Script = string(script)

		return nil
	}

	// parse path as CSV as if space was the separator, this automatically takes care of quotations
	r := csv.NewReader(strings.NewReader(value))
	r.Comma = ' ' // space

	fields, err := r.Read()
	if err != nil {
		return errors.Wrapf(err, "error parsing %v command", actionName)
	}

View on GitHub (pinned to 82495e54b5)