diff --git a/norg/borg/create.nim b/norg/borg/create.nim index a7d8475..46eff5e 100644 --- a/norg/borg/create.nim +++ b/norg/borg/create.nim @@ -30,7 +30,7 @@ proc createArchive(nc: NorgConfig, repo: Repository, archivename: string, retry: proc createBackup*(nc: NorgConfig, repo: Repository): int = let start_time = now() - notify(nc.notifiers, state=Running) + discard notify(nc.notifiers, state=Running) let archivename = repo.path & "::" & genArchiveName() debug "Creating Archive: ", archivename let res = createArchive(nc, repo, archivename) @@ -40,9 +40,9 @@ proc createBackup*(nc: NorgConfig, repo: Repository): int = of 0: if not repo.append_only: discard pruneRepo(nc, repo) - notify(nc.notifiers, state=Success, runtime=total) + discard notify(nc.notifiers, state=Success, runtime=total) of 1: - notify(nc.notifiers, state=Failure, runtime=total) + discard notify(nc.notifiers, state=Failure, runtime=total) else: - notify(nc.notifiers, state=Failure, runtime=total, msg = $res) + discard notify(nc.notifiers, state=Failure, runtime=total, msg = $res) return res diff --git a/norg/config/init.nim b/norg/config/init.nim index 59ce548..19011ee 100644 --- a/norg/config/init.nim +++ b/norg/config/init.nim @@ -100,7 +100,6 @@ proc generateConfigFile*(file: string) = 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() diff --git a/norg/model/log_type.nim b/norg/model/log_type.nim index 29caf2f..0ceccf5 100644 --- a/norg/model/log_type.nim +++ b/norg/model/log_type.nim @@ -18,9 +18,6 @@ proc initLogger*(level: Level = lvlInfo, strfmt: string = "[$levelname] ", log_f filelogger = newFileLogger(log_file, levelThreshold=level, fmtStr=str) filelogger.log(lvlNotice, "Log Level: ", $level) -#proc initLoggerThread*(level: Level = lvlInfo, strfmt: string = "[$levelname] ") = -# initLogThread(strfmt, level) -# threadlogging.notice("Log Level: ", $level) proc newLogInfo*(): LogInfo = var log = LogInfo() diff --git a/norg/notifier/notifier.nim b/norg/notifier/notifier.nim index 15387a5..581b9ec 100644 --- a/norg/notifier/notifier.nim +++ b/norg/notifier/notifier.nim @@ -1,7 +1,7 @@ import ../model/state_type import ../model/notifier_types -proc notify*(notifiers: Notifiers, state: State, runtime: int = 0, msg: string = ""): int {.discardable.} = +proc notify*(notifiers: Notifiers, state: State, runtime: int = 0, msg: string = ""): int = if notifiers.uptimekuma.base_url != "" and state in notifiers.uptimekuma.states: - notifiers.uptimekuma.send_notify(state, runtime, msg) + return notifiers.uptimekuma.send_notify(state, runtime, msg) diff --git a/norg/notifier/uptimekuma_notifier.nim b/norg/notifier/uptimekuma_notifier.nim index 7784191..57d31aa 100644 --- a/norg/notifier/uptimekuma_notifier.nim +++ b/norg/notifier/uptimekuma_notifier.nim @@ -21,9 +21,12 @@ proc send_notify*(uk: UptimeKuma, state: State, runtime: int = 0, msg: string = let url = fmt"{uk.base_url}?status={status}&msg={message}&ping={runtime}" debug "Sending notification to " & url - let res = sendHttpRequest(HttpGet, url) - if res.status == $Http200: - return 0 - else: - return 1 + try: + let res = sendHttpRequest(HttpGet, url) + if res.status == $Http200: + return 0 + else: + return 1 + except: + error(getCurrentExceptionMsg()) diff --git a/norg/restic/backup.nim b/norg/restic/backup.nim index d03aa8a..a4e19e9 100644 --- a/norg/restic/backup.nim +++ b/norg/restic/backup.nim @@ -21,7 +21,7 @@ proc createArchive(nc: NorgConfig, repo: Repository, retry: int = 0): int = proc createBackup*(nc: NorgConfig, repo: Repository): int = let start_time = now() - notify(nc.notifiers, state=Running) + discard notify(nc.notifiers, state=Running) let res = createArchive(nc, repo) let end_time = now() let total = (end_time - start_time).inMilliSeconds() @@ -29,9 +29,9 @@ proc createBackup*(nc: NorgConfig, repo: Repository): int = of 0: if not repo.append_only: discard pruneRepo(nc, repo) - notify(nc.notifiers, state=Success, runtime=total) + discard notify(nc.notifiers, state=Success, runtime=total) of 1: - notify(nc.notifiers, state=Failure, runtime=total) + discard notify(nc.notifiers, state=Failure, runtime=total) else: - notify(nc.notifiers, state=Failure, runtime=total, msg = $res) + discard notify(nc.notifiers, state=Failure, runtime=total, msg = $res) return res diff --git a/norg_backup.toml b/norg_backup.toml new file mode 100644 index 0000000..62f0fb7 --- /dev/null +++ b/norg_backup.toml @@ -0,0 +1,112 @@ +## Defines what folders you would like to back up +#source_directories = [ +# "/home/me", +# "/opt/other_things" +#] +# +## Defines your backup repository/repositories +#[[repositories]] +#label = "LocalBorgBackup" +#path = "/path/to/backup" +## You can define to backup tool here, default is "borg" +#tool = "borg" +# +## You can add more repositories of varying types. +## When defining multiple repositories, a new backup will run for each repository +## defined. +#[[repositories]] +#label = "RemoteBorgBase" +#path = "ssh://1234abcd@1234abcd.repo.borgbase.com/./repo" +#tool = "borg" +# +#[[repositories]] +#label = "LocalResticBackup +#path = "/path/to/another/backup" +# +## You can define restic as a backup tool +#tool = "restic" +# +## if a repository is append-only, you can tell norg not to try and prune it +## Note: This does not set the actual repository as append-only, only informs Norg +## so the prune step does not run which can cause failed notifications with restic +#append_only = true +# +## Defines encryption information i.e. backup encryption passphrase +## If a passphrase is not set or is incorrect, borg/restic will prompt you for one +## which is likely to cause your backups to not run. +#[encryption] +## Set a string variable for the passphrase +#encryption_passphrase = "MyVeryS3curePassphrase!" +# +## Get the passphrase from the result of a command +## encryption_passcommand = "cat my_passphrase.txt" +# +## These actions can be configured to run scripts (i.e. back up a database) +## at various times throughout the running process +#[actions] +## "everything" means before or after every possible option for all repositories +#before_everything = ["echo before everything"] +#after_everything = ["echo after everything"] +## "actions" means before any action, per repository +#before_actions = ["echo before actions"] +#after_actions = ["echo after actions"] +## before or after the backup process per repository +#before_backup = ["echo before backup"] +#after_backup = ["echo after backup"] +## before or after the extract process per repository +#before_extract = ["echo before extract"] +#after_extract = ["echo after extract"] +## before or after the prune process per repository +#before_prune = ["echo before prune"] +#after_prune = ["echo after prune"] +## before or after the compact process per respository +#before_compact = ["echo before compact"] +#after_compact = ["echo after compact"] +## before or after the check processs per repository +#before_check = ["echo before check"] +#after_check = ["echo after check"] +# +## Send a status update to Uptime Kuma +## more status monitor tools are planned to be supported in the future +#[uptimekuma] +## The base/push url of your Uptime Kuma monitor - without the query string. +## The query string will be generated at run time and will change dependant on the state of your backup. +#base_url = "https://uptime.kuma.url/api/push/1234abcd" +# +## what backup states you wish to send an alert for, defaults to Success, Failure and Running +#states = ["Success","Failure", "Running"] +# +## Set locations of the borg or restic binaries if you need to. +## Norg will check some common locations and use the first one it finds, but +## if you have them installed in a non-standard location, set that location here +#[binaries] +#borg_bin = "/usr/local/bin/borg" +#restic_bin = "/usr/local/bin/restic" +# +## Logging configuration - will output to console +#[logging] +## Log level options are below, each option includes the logs from the one before it +## "notice", "info", "warn", "error", "fatal", "debug" +#log_level = "info" +# +## Exclude (or include) files/folders based on filenames or patterns. +#[exclusions] +## Exclude files or folders matching paths +#excludes = [ +# "/etc/file_i_dont_want", +# "/folder_i_dont_want" +#] +# +## Put all your exlusions in a plain text file and they can be linked to here +#exclude_file = "/home/me/exclusions.txt" +# +## Include or Exclude based on patterns (Borg Only) +## is a direct reference to borg-patterns: https://manpages.debian.org/testing/borgbackup/borg-patterns.1.en.html +#patterns = [ +# "/home/*/junk" +#] +# +## Or use a patterns file (Borg Only) +#patterns_file = "/home/me/patterns.lst" +# +#