diff --git a/norg/borg/borg.nim b/norg/borg/borg.nim index cee47cc..2eeaaf7 100644 --- a/norg/borg/borg.nim +++ b/norg/borg/borg.nim @@ -64,3 +64,5 @@ proc execute*(nc: NorgConfig, repo: Repository): int {.discardable.} = run_actions(norg_config.actions.before_check) discard checkRepo(nc, repo) run_actions(norg_config.actions.after_check) + else: + discard diff --git a/norg/borg/execute.nim b/norg/borg/execute.nim index 32a4b75..0037bbd 100644 --- a/norg/borg/execute.nim +++ b/norg/borg/execute.nim @@ -3,6 +3,7 @@ import strformat import ../model/command_type import ../model/exclusions_type +import ../model/log_type import ../utils/run export run @@ -10,6 +11,7 @@ export run proc genCommand*(cmd: string, repo: string, further_args: seq[string]): string = let args = further_args.join(" ") let cmd = fmt"{BORG_BIN} {cmd} {repo} {args}" + debug("Borg Command: " & cmd) return cmd proc genCreateCommand*(repo: string, sources: seq[string], stats: bool, exc: Exclusions, further_args: seq[string]): string = @@ -29,10 +31,12 @@ proc genCreateCommand*(repo: string, sources: seq[string], stats: bool, exc: Exc for pattern in exc.patterns: cmd = fmt"{cmd} --pattern {pattern}" cmd = fmt"{cmd} {args}" + debug("Borg Command: " & cmd) return cmd proc genDeleteCommand*(repo: string, archive: string, further_args: seq[string]): string = let args = further_args.join(" ") let cmd = fmt"{BORG_BIN} delete {repo} {archive} {args}" + debug("Borg Command: " & cmd) return cmd diff --git a/norg/config/args.nim b/norg/config/args.nim index 86a6c16..4ad5afc 100644 --- a/norg/config/args.nim +++ b/norg/config/args.nim @@ -5,7 +5,7 @@ var norg_args*: NorgArgs = newNorgArgs() proc parseArgs*() = var p = newParser: - help("Norg -- " & VERSION & "\r\nA portable borg backup wrapper utility.") + help("Norg -- " & VERSION & "\r\nA portable borg backup and restic orchestration tool.") option("-c", "--config", help="Config file to use.") 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) diff --git a/norg/config/init.nim b/norg/config/init.nim index 0c71308..59ce548 100644 --- a/norg/config/init.nim +++ b/norg/config/init.nim @@ -1,4 +1,6 @@ import parsetoml +import streams +import os import ../model/config_type import ../model/command_type @@ -86,3 +88,24 @@ proc parseConfigFile*(file: string): NorgConfig = norg_config.parseLogging(in_conf{"logging"}) return norg_config +const SAMPLE_CONFIG = staticRead("../../docs/static/downloads/norg.toml.sample") +proc generateConfigFile*(file: string) = + if fileExists(file): + echo "Sensibly not overwriting existing file: " & file + echo "Exiting" + return + echo "Generating Configuration to " & file + var r_strm = newStringStream(SAMPLE_CONFIG) + var w_strm = newFileStream(file, fmWrite) + var line = "" + if r_strm != nil and w_strm != nil: + while r_strm.readLine(line): + echo line + w_strm.writeLine("#" & line) + r_strm.close() + w_strm.close() + echo "Done. Now edit " & file & " to your requirements and run:" + echo "norg -c " & file & " init" + else: + echo "Error writing sample config file" + diff --git a/norg/model/command_type.nim b/norg/model/command_type.nim index 565562e..eb44201 100644 --- a/norg/model/command_type.nim +++ b/norg/model/command_type.nim @@ -13,6 +13,7 @@ type DELETE = "delete" CHECK = "check", COMPACT = "compact" + GEN_CONF = "generate_config" var BORG_BIN* = "borg" var RESTIC_BIN* = "restic" diff --git a/norg/norg.nim b/norg/norg.nim index ffd094a..101f296 100644 --- a/norg/norg.nim +++ b/norg/norg.nim @@ -19,6 +19,11 @@ proc start() = norg_config.args = norg_args if norg_args.show_version: showVersion() + elif norg_args.command == GEN_CONF: + var config_file = "norg_backup.toml" + if norg_args.config_file != "": + config_file = norg_args.config_file + generateConfigFile(config_file) elif norg_args.config_file != "": norg_config = parseConfigFile(norg_args.config_file) echo norg_config.log_info.level diff --git a/norg/utils/run.nim b/norg/utils/run.nim index 53b31b3..974e210 100644 --- a/norg/utils/run.nim +++ b/norg/utils/run.nim @@ -6,6 +6,7 @@ proc run*(cmd: string): int = debug fmt"Trying to run : {cmd}" try: let res = execCmd(cmd) + debug("Run Command Exist Code: " & $res) return res except: error getCurrentExceptionMsg() @@ -15,6 +16,7 @@ proc runDiscard*(cmd: string): int = debug fmt"Trying to run : {cmd}" try: let res = execCmd(cmd) + debug("Run Command Exist Code: " & $res) return res except: error getCurrentExceptionMsg() diff --git a/readme.md b/readme.md index 0b37159..c285064 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # Norg -A simple, portable, wrapper for the [borg backup](https://www.borgbackup.org) and [restic](https://restic.net) utilities written in Nim. +A simple, portable, orchestration tool for the [borg backup](https://www.borgbackup.org) and [restic](https://restic.net) utilities written in Nim. Full documentation on the [Norg Backup Website](https://norgbackup.net/)