{"record":{"id":"0df6c39d0e460a7c","repo":"benbjohnson/litestream","slug":"database-already-exists-skipping","errorCode":null,"errorMessage":"database already exists, skipping","messagePattern":"database already exists, skipping","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"cmd/litestream/restore.go","lineNumber":453,"sourceCode":"\n\t# Restore latest replica for database to new /tmp directory\n\t$ litestream restore -o /tmp/db /path/to/db\n\n\t# Restore database from S3 replica URL.\n\t$ litestream restore -o /tmp/db s3://mybucket/db\n\n\t# Preview restore plan without writing a database.\n\t$ litestream restore -dry-run -o /tmp/db s3://mybucket/db\n\n\t# Continuously restore (follow) a database from a replica.\n\t$ litestream restore -f -o /tmp/read-replica.db s3://mybucket/db\n\n`[1:],\n\t\tDefaultConfigPath(),\n\t)\n}\n\nvar errSkipDBExists = errors.New(\"database already exists, skipping\")\n","sourceCodeStart":435,"sourceCodeEnd":454,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/restore.go#L435-L454","documentation":"errSkipDBExists is a sentinel returned by restore's loadFromURL/loadFromConfig when the target database file already exists and -if-db-not-exists was set. Run treats it as success: it logs \"database already exists, skipping\" and returns nil rather than overwriting an existing database.","triggerScenarios":"Running `litestream restore -if-db-not-exists` (or the library equivalent) when the output database path already exists on disk; the flag converts what would be a destructive conflict into a graceful skip.","commonSituations":"Idempotent startup scripts / systemd units that restore before launching an app, containers re-running restore against a mounted volume that already holds the database.","solutions":["No action needed if skipping is intended — this is a success path","Delete or move the existing database file if you truly want a fresh restore","Omit -if-db-not-exists if you want the default overwrite/conflict behavior instead","Check logs for \"database already exists, skipping\" to confirm idempotent skip"],"exampleFix":"// before\nlitestream restore -o /data/app.db rep  // fails if db exists\n// after (idempotent)\nlitestream restore -if-db-not-exists -o /data/app.db rep  // exits 0 if db exists","handlingStrategy":"fallback","validationCode":"if _, err := os.Stat(dbPath); err == nil {\n    slog.Info(\"db exists; restore will be skipped with -if-db-not-exists\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use -if-db-not-exists in startup scripts for idempotent boot","Check the log line 'database already exists, skipping' to confirm skip behavior","Exit code 0 means the skip was intentional, not a failure"],"tags":["restore","idempotency","sentinel-error"],"backgroundTag":"file-already-exists","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"}