import strutils import strformat import ../model/command_type import ../model/maintenance_type import ../utils/run export run proc genCommand*(cmd: string, repo: string, further_args: seq[string]): string = let args = further_args.join(" ") let cmd = fmt"{RESTIC_BIN} {cmd} -r {repo} {args}" return cmd proc genBackupCommand*(repo: string, sources: seq[string], further_args: seq[string]): string = var source_dirs = "" for source in sources: source_dirs &= fmt""""{source}" """ let args = further_args.join(" ") let cmd = fmt"{RESTIC_BIN} backup -r {repo} {source_dirs} {args}" return cmd proc genRestoreCommand*(repo_snapshot: string, destination: string, further_args: seq[string]): string = let args = further_args.join(" ") 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}" return cmd proc genPruneCommand*(repo: string, further_args: seq[string], maintenance: Maintenance): string = let args = further_args.join(" ") 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} """ return cmd