{"record":{"id":"adf1874a18c8feff","repo":"benbjohnson/litestream","slug":"restore-failed-w","errorCode":null,"errorMessage":"restore failed: %w","messagePattern":"restore failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream/replicate.go","lineNumber":511,"sourceCode":"\t}\n\n\t// Create replica from config (nil db since we're just restoring)\n\tr, err := NewReplicaFromConfig(rc, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot create replica for restore: %w\", err)\n\t}\n\n\t// Attempt restore\n\topt := litestream.NewRestoreOptions()\n\topt.OutputPath = dbPath\n\n\tslog.Info(\"attempting restore before replication\", \"path\", dbPath)\n\tif err := r.Restore(ctx, opt); errors.Is(err, litestream.ErrTxNotAvailable) {\n\t\t// No backup exists yet (first start) - this is OK\n\t\tslog.Info(\"no backup found, starting fresh\", \"path\", dbPath)\n\t\treturn nil\n\t} else if err != nil {\n\t\treturn fmt.Errorf(\"restore failed: %w\", err)\n\t}\n\n\tslog.Info(\"restore completed\", \"path\", dbPath)\n\treturn nil\n}\n\n// Usage prints the help screen to STDOUT.\nfunc (c *ReplicateCommand) Usage() {\n\tfmt.Printf(`\nThe replicate command starts a server to monitor & replicate databases.\nYou can specify your database & replicas in a configuration file or you can\nreplicate a single database file by specifying its path and its replicas in the\ncommand line arguments.\n\nUsage:\n\n\tlitestream replicate [arguments]\n","sourceCodeStart":493,"sourceCodeEnd":529,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/replicate.go#L493-L529","documentation":"The initial restore attempt in restoreIfNeeded failed with an error other than ErrTxNotAvailable (which is tolerated on first start). The replica could not produce a consistent database — plan calculation, download, or compaction failed.","triggerScenarios":"Thrown at cmd/litestream/replicate.go:511 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped error to identify whether planning, download, or decode failed","Check replica credentials/connectivity and that backups exist (litestream ltx)","Fix the underlying issue and restart so restore is retried"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}