From 1abf1aafc82159bcd4828099000daea9dd9f995c Mon Sep 17 00:00:00 2001 From: Winfried Plappert Date: Mon, 3 Mar 2025 06:56:03 +0000 Subject: [PATCH] restic backup - remove unneeded code and improve error information remove unneded field RepoSizeMax Improve code at the end of the run showing if repository capacity has been exceeded and give current value. --- cmd/restic/cmd_backup.go | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index 5853bf903..c0058d7c7 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -116,8 +116,7 @@ type BackupOptions struct { ReadConcurrency uint NoScan bool SkipIfUnchanged bool - RepoMaxSizeString string - RepoSizeMax uint64 + RepoMaxSize string } func (opts *BackupOptions) AddFlags(f *pflag.FlagSet) { @@ -158,7 +157,7 @@ func (opts *BackupOptions) AddFlags(f *pflag.FlagSet) { f.BoolVar(&opts.ExcludeCloudFiles, "exclude-cloud-files", false, "excludes online-only cloud files (such as OneDrive Files On-Demand)") } f.BoolVar(&opts.SkipIfUnchanged, "skip-if-unchanged", false, "skip snapshot creation if identical to parent snapshot") - f.StringVar(&opts.RepoMaxSizeString, "max-repo-size", "", "`limit` maximum size of repository - absolute value in bytes with suffixes m/M, g/G, t/T, default unlimited") + f.StringVar(&opts.RepoMaxSize, "max-repo-size", "", "`limit` maximum size of repository - absolute value in bytes with suffixes m/M, g/G, t/T, default unlimited") // parse read concurrency from env, on error the default value will be used readConcurrency, _ := strconv.ParseUint(os.Getenv("RESTIC_READ_CONCURRENCY"), 10, 32) @@ -522,8 +521,8 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter } } - if len(opts.RepoMaxSizeString) > 0 { - size, err := ui.ParseBytes(opts.RepoMaxSizeString) + if len(opts.RepoMaxSize) > 0 { + size, err := ui.ParseBytes(opts.RepoMaxSize) if err != nil { return err } @@ -721,21 +720,23 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter return errors.Fatalf("unable to save snapshot: %v", err) } + if repo.MaxCapacityExceeded() { + Printf("\n=========================================\n") + Printf("repository maximum size has been exceeded\n") + curRepoSize, err := repo.CurrentRepositorySize(ctx) + if err != nil { + return err + } + Printf("Current repository size is %s\n", ui.FormatBytes(curRepoSize)) + Printf("=========================================\n\n") + } + // Report finished execution progressReporter.Finish(id, summary, opts.DryRun) if !success { return ErrInvalidSourceData } - if repo.MaxCapacityExceeded() { - Verbosef("repository maximum size has been exceeded\n") - curRepoSize, err := repo.CurrentRepositorySize(ctx) - if err != nil { - return err - } - Verbosef("Current repository size is %s\n", ui.FormatBytes(curRepoSize)) - } - // Return error if any return werr }