From 94068ea910537b3501ed694c1d73a3d85594fdd9 Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Tue, 27 Aug 2024 19:03:56 +0100 Subject: [PATCH] some restic prune fixes --- norg/restic/execute.nim | 13 +++++++++++++ norg/restic/prune.nim | 13 +------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/norg/restic/execute.nim b/norg/restic/execute.nim index cdaed87..4be8059 100644 --- a/norg/restic/execute.nim +++ b/norg/restic/execute.nim @@ -2,6 +2,7 @@ import strutils import strformat import ../model/command_type +import ../model/maintenance_type import ../utils/run export run @@ -19,3 +20,15 @@ proc genForgetCommand*(cmd: string, repo: string, archive: string, further_args: let args = further_args.join(" ") let cmd = fmt"{RESTIC_BIN} {cmd} -r {repo} {archive} {args}" return cmd + +proc genPruneCommand*(repo: string, further_args: seq[string], maintenance: Maintenance): string = + let args = further_args.join(" ") + let cmd = fmt"""{RESTIC_BIN} forget --prune \ + --keep-hourly {maintenance.keep_hourly} \ + --keep-daily {maintenance.keep_daily} \ + --keep-weekly {maintenance.keep_weekly} \ + --keep-monthly {maintenance.keep_monthly} \ + --keep-yearly {maintenance.keep_yearly} \ + -r {repo} {args} + """ + return cmd diff --git a/norg/restic/prune.nim b/norg/restic/prune.nim index 64cc683..fb8646d 100644 --- a/norg/restic/prune.nim +++ b/norg/restic/prune.nim @@ -1,21 +1,10 @@ import ../model/config_type -import strformat - import execute -proc addPruneOptions(cmd: var string, maintenance: Maintenance) = - cmd = fmt"""{cmd} \ - --keep-hourly {maintenance.keep_hourly} \ - --keep-daily {maintenance.keep_daily} \ - --keep-weekly {maintenance.keep_weekly} \ - --keep-monthly {maintenance.keep_monthly} \ - --keep-yearly {maintenance.keep_yearly} \ - """ proc pruneRepo*(nc: NorgConfig, repo: Repository): int = - var cmd = genCommand(cmd = "forget --prune", repo = repo.path, further_args = nc.args.further_args) - cmd.addPruneOptions(nc.maintenance) + var cmd = genPruneCommand(repo = repo.path, further_args = nc.args.further_args, nc.maintenance) return run cmd proc forgetSnapshot*(nc: NorgConfig, repo: Repository): int =