Add snapshot create --dry-run to show what excludes keep and drop (closes #436)
check / check (push) Waiting to run
check / check (push) Waiting to run
The dry run scans the source paths, reads the local index to tell unchanged files from new and changed ones, and prints the files examined, to back up and unchanged, their sizes, and the count of excluded entries. With --verbose it prints each excluded entry and the pattern that matched it. It writes nothing to the local index or the destination, takes no lock, and refuses --prune. Model: opus-5-5
This commit is contained in:
1 parent
d747ddef3a
commit
95add7fc38
8 files changed
+492
-58
No files matched your search
+35
-19
@@ -99,6 +99,13 @@ on Linux), then /etc/vaultik/config.yml.`,
|
||||
|
||||
// Use the backup functionality from cli package
|
||||
rootFlags := GetRootFlags()
|
||||
opts.ListExcluded = rootFlags.Verbose
|
||||
|
||||
// A dry run writes nothing, so it does not take the lock.
|
||||
mode := mutating
|
||||
if opts.DryRun {
|
||||
mode = readOnly
|
||||
}
|
||||
|
||||
// --cron suppression is wired through v.UI by setupGlobals.
|
||||
return RunOperation(cmd.Context(), AppOptions{
|
||||
@@ -109,28 +116,11 @@ on Linux), then /etc/vaultik/config.yml.`,
|
||||
Cron: opts.Cron,
|
||||
Quiet: rootFlags.Quiet,
|
||||
},
|
||||
Mode: mutating,
|
||||
Mode: mode,
|
||||
}, func(v *vaultik.Vaultik) error {
|
||||
return v.CreateSnapshot(opts)
|
||||
}, func(err error) {
|
||||
if errors.Is(err, vaultik.ErrPostBackupPruneFailed) {
|
||||
log.Info("Post-backup prune failed", "error", err)
|
||||
ReportErrorf("Backup completed, but %v", err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if errors.Is(err, vaultik.ErrFilesUnreadable) ||
|
||||
errors.Is(err, vaultik.ErrSourcePathEmpty) ||
|
||||
errors.Is(err, vaultik.ErrVolumeNotMounted) {
|
||||
log.Info("Backup completed with an error", "error", err)
|
||||
ReportErrorf("Backup completed, but %v", err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
log.Info("Snapshot creation failed", "error", err)
|
||||
ReportErrorf("Snapshot creation failed: %v", err)
|
||||
reportSnapshotCreateFailure(opts.DryRun, err)
|
||||
})
|
||||
},
|
||||
}
|
||||
@@ -149,10 +139,36 @@ on Linux), then /etc/vaultik/config.yml.`,
|
||||
"With --prune: keep snapshots newer than this duration "+
|
||||
"(e.g. 30d, 4w, 6mo, 1y; m is minutes, mo is months) "+
|
||||
"instead of only the latest")
|
||||
cmd.Flags().BoolVar(&opts.DryRun, "dry-run", false,
|
||||
"Scan the snapshot source paths and print what a backup would store, "+
|
||||
"writing nothing to the local index or the backup destination; "+
|
||||
"with --verbose, also print each excluded entry and the exclude "+
|
||||
"pattern that matched it")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// reportSnapshotCreateFailure shows the user the error `snapshot create`
|
||||
// failed with. dryRun says whether it was given --dry-run.
|
||||
func reportSnapshotCreateFailure(dryRun bool, err error) {
|
||||
switch {
|
||||
case dryRun:
|
||||
log.Info("Dry run failed", "error", err)
|
||||
ReportErrorf("Dry run failed: %v", err)
|
||||
case errors.Is(err, vaultik.ErrPostBackupPruneFailed):
|
||||
log.Info("Post-backup prune failed", "error", err)
|
||||
ReportErrorf("Backup completed, but %v", err)
|
||||
case errors.Is(err, vaultik.ErrFilesUnreadable) ||
|
||||
errors.Is(err, vaultik.ErrSourcePathEmpty) ||
|
||||
errors.Is(err, vaultik.ErrVolumeNotMounted):
|
||||
log.Info("Backup completed with an error", "error", err)
|
||||
ReportErrorf("Backup completed, but %v", err)
|
||||
default:
|
||||
log.Info("Snapshot creation failed", "error", err)
|
||||
ReportErrorf("Snapshot creation failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// newSnapshotListCommand creates the 'snapshot list' subcommand
|
||||
func newSnapshotListCommand() *cobra.Command {
|
||||
var jsonOutput bool
|
||||
|
||||
Reference in new issue
Block a user