{"record":{"id":"d0aee8579c2c49b8","repo":"benbjohnson/litestream","slug":"cannot-specify-once-flag-with-exec","errorCode":null,"errorMessage":"cannot specify -once flag with -exec","messagePattern":"cannot specify -once flag with -exec","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream/replicate.go","lineNumber":165,"sourceCode":"\t\tc.Config.Exec = *execFlag\n\t}\n\n\t// Apply restore-if-db-not-exists flag to all databases if specified.\n\t// This allows the CLI flag to work with config files.\n\tif *restoreIfDBNotExists {\n\t\tfor _, dbConfig := range c.Config.DBs {\n\t\t\tdbConfig.RestoreIfDBNotExists = true\n\t\t}\n\t}\n\n\t// Set one-shot replication flags and validate their usage.\n\tc.once = *onceFlag\n\tc.forceSnapshot = *forceSnapshotFlag\n\tc.enforceRetention = *enforceRetentionFlag\n\n\t// Validate flag combinations.\n\tif c.once && c.Config.Exec != \"\" {\n\t\treturn fmt.Errorf(\"cannot specify -once flag with -exec\")\n\t}\n\tif c.forceSnapshot && !c.once {\n\t\treturn fmt.Errorf(\"cannot specify -force-snapshot flag without -once\")\n\t}\n\tif c.enforceRetention && !c.once {\n\t\treturn fmt.Errorf(\"cannot specify -enforce-retention flag without -once\")\n\t}\n\n\treturn nil\n}\n\n// Run loads all databases specified in the configuration.\nfunc (c *ReplicateCommand) Run(ctx context.Context) (err error) {\n\t// Display version information.\n\tslog.Info(\"litestream\", \"version\", Version, \"level\", c.Config.Logging.Level)\n\n\t// Start MCP server if enabled\n\tif c.Config.MCPAddr != \"\" {","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/replicate.go#L147-L183","documentation":"The `-once` flag runs a single replication pass and exits, while `-exec` keeps Litestream alive as a supervisor wrapping a subprocess. These lifecycles are incompatible: `-once` would exit after one sync while the exec'd process may still be running. ParseFlags rejects the combination up front.","triggerScenarios":"Invoking `litestream replicate -once -exec \"some-command\" ...` — both c.once set and Config.Exec non-empty after flag parsing.","commonSituations":"One-shot backup scripts that also want to run a quick command alongside; users combining a container entrypoint pattern with a one-shot restore/replicate.","solutions":["Drop the `-once` flag if you need the exec subprocess supervision","Drop the `-exec` argument if you only want a single replication pass","Run two separate litestream invocations: one `-once` replicate and one that runs your command"],"exampleFix":"// before\nlitestream replicate -once -exec \"./backup-hook.sh\" db.sqlite s3://bucket/db\n// after\nlitestream replicate -exec \"./backup-hook.sh\" db.sqlite s3://bucket/db\n# or\nlitestream replicate -once db.sqlite s3://bucket/db","handlingStrategy":"validation","validationCode":"# reject incompatible flag combos before exec\nset -e\nfor a in \"$@\"; do\n  if [ \"$a\" = \"-once\" ] && printf '%s' \"$CMDLINE\" | grep -q -- '-exec'; then\n    echo \"-once cannot be combined with -exec\" >&2; exit 1\n  fi\ndone","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember: -once means exit-after-one-sync; -exec means long-running supervisor — never both","Keep one-shot backup scripts and exec-supervised services as separate invocations","Lint wrapper scripts for known flag combinations"],"tags":["cli","flags","validation"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}