check / check (push) Waiting to run
A backup uploads its blobs before the manifest that lists them, and the process lock covers one user on one machine, so a prune from another host or user sharing the destination deleted a running backup's blobs. Prune now deletes an unreferenced blob only once its listed time is older than the new config key prune_grace_period (default 24h; a negative value is refused). A newer blob, or one listed with no time, is kept and counted (blobs_too_new). A backup uploads a blob already on the destination again instead of skipping it, so it gets a fresh time. The rclone backend takes each object's time from the listing (use_server_modtime). Cost: after database delete, the next backup uploads all its data again. Side effect: a rebuilt blob replaces the stored copy; if compression_level or the recipients changed since, older snapshots listing it fail verify. Model: opus-5-5
68 lines
2.1 KiB
Go
68 lines
2.1 KiB
Go
package cli
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
"sneak.berlin/go/vaultik/internal/log"
|
|
"sneak.berlin/go/vaultik/internal/vaultik"
|
|
)
|
|
|
|
// NewPruneCommand creates the prune command
|
|
func NewPruneCommand() *cobra.Command {
|
|
opts := &vaultik.PruneOptions{}
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "prune",
|
|
Short: "Tidy local database and remote storage",
|
|
Long: `Removes orphaned data from both the local index database and
|
|
unreferenced blobs from the backup destination store.
|
|
|
|
Local cleanup drops incomplete snapshots and any files, chunks, or
|
|
blobs no longer referenced by a completed snapshot. Remote cleanup
|
|
scans every snapshot manifest in the destination store, builds the
|
|
set of still-referenced blob hashes, and deletes any blob not in that
|
|
set that is older than prune_grace_period (default 24h). A newer one
|
|
is kept: it may belong to a backup still running, on this host or
|
|
another sharing the destination store, that has not yet uploaded its
|
|
manifest.
|
|
|
|
Snapshot create --prune runs the same cleanup automatically; this
|
|
command is the manual entry point for the same work (e.g. after a
|
|
crashed backup or to reclaim storage). Snapshot remove leaves blobs in
|
|
place; run this command afterwards to delete the ones no longer
|
|
referenced.`,
|
|
Args: cobra.NoArgs,
|
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
// Use unified config resolution
|
|
configPath, err := ResolveConfigPath()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Use the app framework like other commands
|
|
rootFlags := GetRootFlags()
|
|
|
|
return RunOperation(cmd.Context(), AppOptions{
|
|
ConfigPath: configPath,
|
|
LogOptions: log.Options{
|
|
Verbose: rootFlags.Verbose,
|
|
Debug: rootFlags.Debug,
|
|
Quiet: rootFlags.Quiet,
|
|
JSON: opts.JSON,
|
|
},
|
|
Mode: mutating,
|
|
}, func(v *vaultik.Vaultik) error {
|
|
return v.Prune(opts)
|
|
}, func(err error) {
|
|
log.Error("Prune operation failed", "error", err)
|
|
ReportErrorf("Prune failed: %v", err)
|
|
})
|
|
},
|
|
}
|
|
|
|
cmd.Flags().BoolVar(&opts.Force, "force", false, "Skip confirmation prompt")
|
|
cmd.Flags().BoolVar(&opts.JSON, "json", false,
|
|
"Output pruning stats as JSON; skips the confirmation prompt, as --force does")
|
|
|
|
return cmd
|
|
}
|