add better handling of borg exit codes
This commit is contained in:
parent
fa64cf55f4
commit
d79780b98b
6 changed files with 32 additions and 14 deletions
|
@ -1 +1 @@
|
|||
Subproject commit 9b5c6dd04825d33cb27a9c6715764ad7e23182c4
|
||||
Subproject commit b7d436287a9ecbe87466babf56d81f3c9fb56959
|
|
@ -1,6 +1,6 @@
|
|||
# Package
|
||||
|
||||
version = "0.1.13"
|
||||
version = "0.1.14"
|
||||
author = "Paul Wilde"
|
||||
description = "A Borg Backup Orchestration Tool"
|
||||
license = "AGPL-3.0-or-later"
|
||||
|
|
|
@ -10,7 +10,6 @@ import mount
|
|||
import extract
|
||||
|
||||
|
||||
|
||||
proc initRepo(nc: NorgConfig, repo: Repository): int =
|
||||
return runDiscard genCommand(cmd = "init", repo = repo.path, further_args = nc.args.further_args)
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import ../model/config_type
|
||||
import ../model/state_type
|
||||
import ../model/exit_codes
|
||||
import ../model/tool_type
|
||||
import ../notifier/notifier
|
||||
import ../model/log_type
|
||||
|
||||
|
@ -16,33 +18,35 @@ proc genArchiveName(): string =
|
|||
let ts = getTime().format("yyyy-MM-dd'T'HH:mm:ss'.'ffffff")
|
||||
return fmt"{hostname}-{ts}"
|
||||
|
||||
proc createArchive(nc: NorgConfig, repo: Repository, archivename: string, retry: int = 0): int =
|
||||
proc createArchive(nc: NorgConfig, repo: Repository, archivename: string, retry: int = 0): (EXIT_CODE,string) =
|
||||
let further_args = nc.args.further_args
|
||||
let res = run genCreateCommand(repo = archivename, sources = nc.source_directories, stats=nc.args.stats, exc=nc.exclusions, further_args = further_args)
|
||||
if res != 0:
|
||||
info "Failed to run Borg. Waiting 15 seconds and trying again"
|
||||
sleep 15 * 1000 # 15 seconds
|
||||
if retry == nc.retries:
|
||||
return 1
|
||||
return (BORG_ERROR, "Max Retries Reached")
|
||||
else:
|
||||
return createArchive(nc, repo, archivename, retry + 1)
|
||||
return res
|
||||
return (res.toExitCode(BORG),"Success")
|
||||
|
||||
proc createBackup*(nc: NorgConfig, repo: Repository): int =
|
||||
proc createBackup*(nc: NorgConfig, repo: Repository): EXIT_CODE =
|
||||
let start_time = now()
|
||||
discard notify(nc.notifiers, state=Running)
|
||||
let archivename = repo.path & "::" & genArchiveName()
|
||||
debug "Creating Archive: ", archivename
|
||||
let res = createArchive(nc, repo, archivename)
|
||||
let (res,msg) = createArchive(nc, repo, archivename)
|
||||
let end_time = now()
|
||||
let total = (end_time - start_time).inMilliSeconds()
|
||||
case res
|
||||
of 0:
|
||||
of BORG_SUCCESS:
|
||||
if not repo.append_only:
|
||||
discard pruneRepo(nc, repo)
|
||||
discard notify(nc.notifiers, state=Success, runtime=total)
|
||||
of 1:
|
||||
discard notify(nc.notifiers, state=Failure, runtime=total)
|
||||
discard notify(nc.notifiers, state=Success, runtime=total, msg=msg)
|
||||
of BORG_WARNING:
|
||||
discard notify(nc.notifiers, state=Success, runtime=total, msg="Warning")
|
||||
of BORG_ERROR:
|
||||
discard notify(nc.notifiers, state=Failure, runtime=total, msg=msg)
|
||||
else:
|
||||
discard notify(nc.notifiers, state=Failure, runtime=total, msg = $res)
|
||||
return res
|
||||
|
|
15
norg/model/exit_codes.nim
Normal file
15
norg/model/exit_codes.nim
Normal file
|
@ -0,0 +1,15 @@
|
|||
import tool_type
|
||||
|
||||
import std/enumutils
|
||||
|
||||
type
|
||||
EXIT_CODE* = enum
|
||||
BORG_SUCCESS = 0
|
||||
BORG_WARNING = 1
|
||||
BORG_ERROR = 2
|
||||
OTHER = 99
|
||||
|
||||
proc toExitCode*(i: int, tool: BackupTool): EXIT_CODE =
|
||||
for code in EXIT_CODE:
|
||||
if i == ord(code): return code
|
||||
return OTHER
|
|
@ -11,7 +11,7 @@ proc run*(cmd: string): int =
|
|||
return exitcode
|
||||
except:
|
||||
error getCurrentExceptionMsg()
|
||||
return 1
|
||||
return 2
|
||||
|
||||
proc runDiscard*(cmd: string): int =
|
||||
debug fmt"Trying to run : {cmd}"
|
||||
|
@ -22,5 +22,5 @@ proc runDiscard*(cmd: string): int =
|
|||
return exitcode
|
||||
except:
|
||||
error getCurrentExceptionMsg()
|
||||
return 1
|
||||
return 2
|
||||
|
||||
|
|
Loading…
Reference in a new issue