Skip to content

Commit e4ed80c

Browse files
cmd/utils: add --only-history flag to rm-state command (#20899)
Adds `--only-history` (alias `--history`) to `erigon seg rm-state`. When set, restricts deletion to history files (`SnapHistory` + `SnapIdx`) only — leaving domain data (`.kv` files in `SnapDomain`, accessor files) untouched. Useful when combined with `--step from-to` to prune old history without touching domain snapshots.
1 parent fd74bee commit e4ed80c

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

cmd/integration/Readme.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,19 @@ integration stage_custom_trace --domain=receipt,rcache,logtopics,logaddrs,traces
142142
integration stage_custom_trace --domain=receipt,rcache,logtopics,logaddrs,tracesfrom,tracesto
143143
```
144144

145+
## How to remove history snapshots only (keep domain data)
146+
147+
```sh
148+
# Remove all history files (SnapHistory + SnapIdx + SnapAccessors) without touching domain data (.kv files):
149+
erigon snapshots rm-state --only-history
150+
151+
# Remove a specific step range of history files only:
152+
erigon snapshots rm-state --only-history --step=0-900
153+
154+
# Dry-run first to see what would be deleted:
155+
erigon snapshots rm-state --only-history --step=0-900 --dry-run
156+
```
157+
145158
## How to re-gen bor checkpoints
146159

147160
```sh

cmd/utils/app/snapshots_cmd.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ var snapshotCommand = cli.Command{
322322
&cli.BoolFlag{Name: "recentStep", Aliases: []string{"latest", "latestStep", "recent"}, Usage: "remove minimal possible recent/latest files: and Domain and History. Useful when have 1 corrupted recent file"},
323323
&cli.BoolFlag{Name: "dry-run"},
324324
&cli.StringSliceFlag{Name: "domain"},
325+
&cli.BoolFlag{Name: "only-history", Aliases: []string{"history"}, Usage: "remove only history files (SnapHistory+SnapIdx), not domain data"},
325326
},
326327
),
327328
},
@@ -699,6 +700,7 @@ type DeleteStateSnapshotsArgs struct {
699700
DryRun bool
700701
StepRange string
701702
OnlyDomain bool
703+
OnlyHistory bool
702704
DomainNames []string
703705
}
704706

@@ -728,6 +730,8 @@ func DeleteStateSnapshots(args DeleteStateSnapshotsArgs) error {
728730
scanDirs := []string{dirs.SnapIdx, dirs.SnapHistory, dirs.SnapDomain, dirs.SnapAccessors, dirs.SnapForkable}
729731
if args.OnlyDomain {
730732
scanDirs = []string{dirs.SnapDomain}
733+
} else if args.OnlyHistory {
734+
scanDirs = []string{dirs.SnapHistory, dirs.SnapIdx, dirs.SnapAccessors}
731735
}
732736
for _, dirPath := range scanDirs {
733737
filePaths, err := dir2.ListFiles(dirPath)
@@ -1034,6 +1038,7 @@ func doRmStateSnapshots(cliCtx *cli.Context) error {
10341038
stepRange := cliCtx.String("step")
10351039
domainNames := cliCtx.StringSlice("domain")
10361040
dryRun := cliCtx.Bool("dry-run")
1041+
onlyHistory := cliCtx.Bool("only-history")
10371042
promptUser := true // CLI should always prompt the user
10381043
return DeleteStateSnapshots(DeleteStateSnapshotsArgs{
10391044
Dirs: dirs,
@@ -1042,6 +1047,7 @@ func doRmStateSnapshots(cliCtx *cli.Context) error {
10421047
DryRun: dryRun,
10431048
StepRange: stepRange,
10441049
DomainNames: domainNames,
1050+
OnlyHistory: onlyHistory,
10451051
})
10461052
}
10471053

0 commit comments

Comments
 (0)