2024-08-19 03:21:46 +02:00
|
|
|
import strutils
|
|
|
|
import strformat
|
|
|
|
|
2024-08-23 10:50:53 +02:00
|
|
|
import ../model/command_type
|
2024-09-03 16:20:44 +02:00
|
|
|
import ../model/exclusions_type
|
2024-11-25 12:15:15 +01:00
|
|
|
import ../model/log_type
|
2024-08-23 10:50:53 +02:00
|
|
|
import ../utils/run
|
|
|
|
export run
|
2024-08-19 03:21:46 +02:00
|
|
|
|
2024-08-24 23:32:10 +02:00
|
|
|
|
2024-08-23 13:04:27 +02:00
|
|
|
proc genCommand*(cmd: string, repo: string, further_args: seq[string]): string =
|
|
|
|
let args = further_args.join(" ")
|
2024-08-19 03:21:46 +02:00
|
|
|
let cmd = fmt"{BORG_BIN} {cmd} {repo} {args}"
|
2024-11-25 12:15:15 +01:00
|
|
|
debug("Borg Command: " & cmd)
|
2024-08-19 03:21:46 +02:00
|
|
|
return cmd
|
|
|
|
|
2024-09-03 16:20:44 +02:00
|
|
|
proc genCreateCommand*(repo: string, sources: seq[string], stats: bool, exc: Exclusions, further_args: seq[string]): string =
|
2024-08-23 16:46:35 +02:00
|
|
|
let args = further_args.join(" ")
|
|
|
|
var stats_flag = "--stats"
|
|
|
|
if not stats: stats_flag = ""
|
2024-08-27 20:27:36 +02:00
|
|
|
var source_dirs = ""
|
|
|
|
for source in sources:
|
2024-08-27 21:29:56 +02:00
|
|
|
source_dirs &= fmt""""{source}" """
|
2024-09-03 16:20:44 +02:00
|
|
|
var cmd = fmt"{BORG_BIN} create {stats_flag} {repo} {source_dirs}"
|
|
|
|
if exc.exclude_file != "":
|
|
|
|
cmd = fmt"{cmd} --exclude-from {exc.exclude_file}"
|
|
|
|
if exc.patterns_file != "":
|
|
|
|
cmd = fmt"{cmd} --pattern-from {exc.patterns_file}"
|
|
|
|
for exclude in exc.excludes:
|
|
|
|
cmd = fmt"{cmd} --exclude {exclude}"
|
|
|
|
for pattern in exc.patterns:
|
|
|
|
cmd = fmt"{cmd} --pattern {pattern}"
|
|
|
|
cmd = fmt"{cmd} {args}"
|
2024-11-25 12:15:15 +01:00
|
|
|
debug("Borg Command: " & cmd)
|
2024-08-23 16:46:35 +02:00
|
|
|
return cmd
|
|
|
|
|
2024-08-27 20:27:36 +02:00
|
|
|
proc genDeleteCommand*(repo: string, archive: string, further_args: seq[string]): string =
|
2024-08-23 15:08:14 +02:00
|
|
|
let args = further_args.join(" ")
|
2024-08-27 20:27:36 +02:00
|
|
|
let cmd = fmt"{BORG_BIN} delete {repo} {archive} {args}"
|
2024-11-25 12:15:15 +01:00
|
|
|
debug("Borg Command: " & cmd)
|
2024-08-23 15:08:14 +02:00
|
|
|
return cmd
|
|
|
|
|