2024-08-23 10:50:53 +02:00
|
|
|
import strutils
|
|
|
|
import strformat
|
|
|
|
|
|
|
|
import ../model/command_type
|
2024-08-27 20:03:56 +02:00
|
|
|
import ../model/maintenance_type
|
2024-09-03 16:20:44 +02:00
|
|
|
import ../model/exclusions_type
|
2024-08-23 10:50:53 +02:00
|
|
|
import ../utils/run
|
|
|
|
export run
|
|
|
|
|
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-23 11:30:36 +02:00
|
|
|
let cmd = fmt"{RESTIC_BIN} {cmd} -r {repo} {args}"
|
2024-08-23 10:50:53 +02:00
|
|
|
return cmd
|
|
|
|
|
2024-09-03 16:20:44 +02:00
|
|
|
proc genBackupCommand*(repo: string, sources: seq[string], exc: Exclusions, further_args: seq[string]): string =
|
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-08-23 13:31:43 +02:00
|
|
|
let args = further_args.join(" ")
|
2024-09-03 16:20:44 +02:00
|
|
|
var cmd = fmt"{RESTIC_BIN} backup -r {repo} {source_dirs}"
|
|
|
|
if exc.exclude_file != "":
|
|
|
|
cmd = fmt"{cmd} --exclude-file={exc.exclude_file}"
|
|
|
|
for exclude in exc.excludes:
|
|
|
|
cmd = fmt"{cmd} --exclude={exclude}"
|
|
|
|
cmd = fmt"{cmd} {args}"
|
2024-08-23 13:31:43 +02:00
|
|
|
return cmd
|
|
|
|
|
2024-08-27 20:27:36 +02:00
|
|
|
proc genRestoreCommand*(repo_snapshot: string, destination: string, further_args: seq[string]): string =
|
2024-08-23 15:12:59 +02:00
|
|
|
let args = further_args.join(" ")
|
2024-08-27 20:27:36 +02:00
|
|
|
let cmd = fmt"{RESTIC_BIN} restore -r {repo_snapshot} --target {destination} {args}"
|
|
|
|
return cmd
|
|
|
|
|
|
|
|
proc genForgetCommand*(repo: string, archive: string, further_args: seq[string]): string =
|
|
|
|
let args = further_args.join(" ")
|
|
|
|
let cmd = fmt"{RESTIC_BIN} forget -r {repo} {archive} {args}"
|
2024-08-23 15:12:59 +02:00
|
|
|
return cmd
|
2024-08-27 20:03:56 +02:00
|
|
|
|
|
|
|
proc genPruneCommand*(repo: string, further_args: seq[string], maintenance: Maintenance): string =
|
|
|
|
let args = further_args.join(" ")
|
2024-08-27 21:36:43 +02:00
|
|
|
let cmd = fmt"""{RESTIC_BIN} forget --prune --keep-hourly {maintenance.keep_hourly} --keep-daily {maintenance.keep_daily} --keep-weekly {maintenance.keep_weekly} --keep-monthly {maintenance.keep_monthly} --keep-yearly {maintenance.keep_yearly} -r {repo} {args}"""
|
2024-08-27 20:03:56 +02:00
|
|
|
return cmd
|