{"record":{"id":"85e27a549331d72c","repo":"benbjohnson/litestream","slug":"post-restore-integrity-check-w","errorCode":null,"errorMessage":"post-restore integrity check: %w","messagePattern":"post-restore integrity check: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"replica.go","lineNumber":777,"sourceCode":"\t}\n\n\t// Copy file to final location.\n\tr.Logger().Debug(\"renaming database from temporary location\")\n\tif err := os.Rename(tmpOutputPath, opt.OutputPath); err != nil {\n\t\treturn err\n\t}\n\tif err := internal.FsyncDir(filepath.Dir(opt.OutputPath)); err != nil {\n\t\treturn fmt.Errorf(\"sync restore output dir: %w\", err)\n\t}\n\n\tif opt.IntegrityCheck != IntegrityCheckNone {\n\t\tif err := checkIntegrity(ctx, opt.OutputPath, opt.IntegrityCheck); err != nil {\n\t\t\tif ctx.Err() == nil {\n\t\t\t\t_ = os.Remove(opt.OutputPath)\n\t\t\t\t_ = os.Remove(opt.OutputPath + \"-shm\")\n\t\t\t\t_ = os.Remove(opt.OutputPath + \"-wal\")\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"post-restore integrity check: %w\", err)\n\t\t}\n\t\tr.Logger().Info(\"post-restore integrity check passed\")\n\t}\n\n\t// Enter follow mode if enabled, continuously applying new LTX files.\n\tif opt.Follow {\n\t\tfor _, rd := range rdrs {\n\t\t\tif closer, ok := rd.(io.Closer); ok {\n\t\t\t\t_ = closer.Close()\n\t\t\t}\n\t\t}\n\t\trdrs = nil\n\n\t\tmaxTXID := infos[len(infos)-1].MaxTXID\n\t\tif err := WriteTXIDFile(opt.OutputPath, maxTXID); err != nil {\n\t\t\treturn fmt.Errorf(\"write initial txid file: %w\", err)\n\t\t}\n\t\treturn r.follow(ctx, opt.OutputPath, maxTXID, opt.FollowInterval)","sourceCodeStart":759,"sourceCodeEnd":795,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/replica.go#L759-L795","documentation":"The optional post-restore integrity check (PRAGMA integrity_check / quick_check) failed on the newly restored database. The restored image is corrupt or inconsistent; Litestream removes the output (and -shm/-wal) so a bad database isn't left behind, unless the context was cancelled.","triggerScenarios":"Thrown at replica.go:777 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the restore; if it persists the replica's LTX history is corrupt","Inspect and repair replica files (litestream ltx, delete bad files)","Restore to an earlier timestamp that predates the corruption"],"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-14T00:17:10.932Z"}