From 59dead5ea576d185c85a7e7a599ab720eadec6d9 Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Fri, 23 Aug 2024 15:46:35 +0100 Subject: [PATCH] removed risk of restic failing is --stats flag is passed --- norg/borg/create.nim | 2 +- norg/borg/execute.nim | 7 +++++++ norg/config/args.nim | 3 +++ todo.md | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/norg/borg/create.nim b/norg/borg/create.nim index 56cf01d..4b338b4 100644 --- a/norg/borg/create.nim +++ b/norg/borg/create.nim @@ -18,7 +18,7 @@ proc genArchiveName(): string = proc createArchive(nc: NorgConfig, repo: Repository, archivename: string, retry: int = 0): int = let further_args = concat(nc.source_directories, nc.args.further_args) - let res = run genCommand(cmd = "create", repo = archivename, further_args = further_args) + let res = run genCreateCommand(cmd = "create", repo = archivename, stats=nc.args.stats, further_args = further_args) if res != 0: sleep 15 * 1000 # 15 seconds if retry == nc.retries: diff --git a/norg/borg/execute.nim b/norg/borg/execute.nim index 37d8f48..78b8df6 100644 --- a/norg/borg/execute.nim +++ b/norg/borg/execute.nim @@ -10,6 +10,13 @@ proc genCommand*(cmd: string, repo: string, further_args: seq[string]): string = let cmd = fmt"{BORG_BIN} {cmd} {repo} {args}" return cmd +proc genCreateCommand*(cmd: string, repo: string, stats: bool, further_args: seq[string]): string = + let args = further_args.join(" ") + var stats_flag = "--stats" + if not stats: stats_flag = "" + let cmd = fmt"{BORG_BIN} {cmd} {stats_flag} {repo} {args}" + return cmd + proc genDeleteCommand*(cmd: string, repo: string, archive: string, further_args: seq[string]): string = let args = further_args.join(" ") let cmd = fmt"{BORG_BIN} {cmd} {repo} {archive} {args}" diff --git a/norg/config/args.nim b/norg/config/args.nim index d8edf78..f1cd212 100644 --- a/norg/config/args.nim +++ b/norg/config/args.nim @@ -8,6 +8,7 @@ type command*: Command repository*: string archive*: string + stats*: bool further_args*: seq[string] var norg_args*: NorgArgs = NorgArgs() @@ -19,6 +20,7 @@ proc parseArgs*() = option("-d", "--destination", help="Destination when extracting backup", required = false) option("-r", "--repository", help="Define an explicit repository to work on by either label or path.", required = false) option("-a", "--archive", help="The archive or snapshot to operate on", required = false) + flag("-s","--stats",help="Provides statistics at the end of a backup (Borg only)") arg("command", help="The command to run, defaults to 'create' which will perform a backup.", default=some("create")) arg("further_args", nargs = -1, help="Any further arguments to send onto borg or restic.") try: @@ -28,6 +30,7 @@ proc parseArgs*() = norg_args.command = opts.command.toCommand() norg_args.repository = opts.repository norg_args.archive = opts.archive + norg_args.stats = opts.stats norg_args.further_args = opts.further_args except ShortCircuit as err: if err.flag == "argparse_help": diff --git a/todo.md b/todo.md index f3eb9ce..ecdbd63 100644 --- a/todo.md +++ b/todo.md @@ -8,4 +8,5 @@ - [x] Allow to specify direct repository so mount/extract doesn't fail if multiple are available - [ ] Better workflow of using borg flags and options as it seems a little sketchy just passing them through to the command string - [ ] Add Windows support (Restic Only) +- [ ] Include/Exclude files functionality - [ ] ... and loads more