diff --git a/norg/borg/create.nim b/norg/borg/create.nim index 4b338b4..f20ec89 100644 --- a/norg/borg/create.nim +++ b/norg/borg/create.nim @@ -7,7 +7,6 @@ import prune import os import times -import sequtils import strformat import nativesockets @@ -17,8 +16,8 @@ proc genArchiveName(): string = return fmt"{hostname}-{ts}" proc createArchive(nc: NorgConfig, repo: Repository, archivename: string, retry: int = 0): int = - let further_args = concat(nc.source_directories, nc.args.further_args) - let res = run genCreateCommand(cmd = "create", repo = archivename, stats=nc.args.stats, further_args = further_args) + let further_args = nc.args.further_args + let res = run genCreateCommand(repo = archivename, sources = nc.source_directories, stats=nc.args.stats, further_args = further_args) if res != 0: sleep 15 * 1000 # 15 seconds if retry == nc.retries: diff --git a/norg/borg/execute.nim b/norg/borg/execute.nim index 4ba0233..05b1f32 100644 --- a/norg/borg/execute.nim +++ b/norg/borg/execute.nim @@ -11,15 +11,18 @@ proc genCommand*(cmd: string, repo: string, further_args: seq[string]): string = let cmd = fmt"{BORG_BIN} {cmd} {repo} {args}" return cmd -proc genCreateCommand*(cmd: string, repo: string, stats: bool, further_args: seq[string]): string = +proc genCreateCommand*(repo: string, sources: seq[string], stats: bool, further_args: seq[string]): string = let args = further_args.join(" ") var stats_flag = "--stats" if not stats: stats_flag = "" - let cmd = fmt"{BORG_BIN} {cmd} {stats_flag} {repo} {args}" + var source_dirs = "" + for source in sources: + source_dirs &= fmt""""{source}"""" + let cmd = fmt"{BORG_BIN} create {stats_flag} {repo} {source_dirs} {args}" return cmd -proc genDeleteCommand*(cmd: string, repo: string, archive: string, further_args: seq[string]): string = +proc genDeleteCommand*(repo: string, archive: string, further_args: seq[string]): string = let args = further_args.join(" ") - let cmd = fmt"{BORG_BIN} {cmd} {repo} {archive} {args}" + let cmd = fmt"{BORG_BIN} delete {repo} {archive} {args}" return cmd diff --git a/norg/borg/prune.nim b/norg/borg/prune.nim index 44af103..0bcafc5 100644 --- a/norg/borg/prune.nim +++ b/norg/borg/prune.nim @@ -8,5 +8,5 @@ proc pruneRepo*(nc: NorgConfig, repo: Repository): int = return run cmd proc deleteArchive*(nc: NorgConfig, repo: Repository): int = - var cmd = genDeleteCommand(cmd = "delete", repo = repo.path, archive = nc.args.archive, further_args = nc.args.further_args) + var cmd = genDeleteCommand(repo = repo.path, archive = nc.args.archive, further_args = nc.args.further_args) return run cmd diff --git a/norg/restic/backup.nim b/norg/restic/backup.nim index 0c65658..9210e24 100644 --- a/norg/restic/backup.nim +++ b/norg/restic/backup.nim @@ -6,12 +6,11 @@ import prune import nativesockets import times -import sequtils import os proc createArchive(nc: NorgConfig, repo: Repository, retry: int = 0): int = - let further_args = concat(nc.source_directories, nc.args.further_args) - let res = run genCommand(cmd = "backup", repo = repo.path, further_args = further_args) + let further_args = nc.args.further_args + let res = run genBackupCommand(repo = repo.path, sources = nc.source_directories, further_args = further_args) if res != 0: sleep 15 * 1000 # 15 seconds if retry == nc.retries: diff --git a/norg/restic/execute.nim b/norg/restic/execute.nim index 4be8059..7d83edf 100644 --- a/norg/restic/execute.nim +++ b/norg/restic/execute.nim @@ -11,14 +11,22 @@ proc genCommand*(cmd: string, repo: string, further_args: seq[string]): string = let cmd = fmt"{RESTIC_BIN} {cmd} -r {repo} {args}" return cmd -proc genRestoreCommand*(cmd: string, repo_snapshot: string, destination: string, further_args: seq[string]): string = +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} {cmd} -r {repo_snapshot} --target {destination} {args}" + let cmd = fmt"{RESTIC_BIN} backup -r {repo} {sources} {args}" return cmd -proc genForgetCommand*(cmd: string, repo: string, archive: string, further_args: seq[string]): string = +proc genRestoreCommand*(repo_snapshot: string, destination: string, further_args: seq[string]): string = let args = further_args.join(" ") - let cmd = fmt"{RESTIC_BIN} {cmd} -r {repo} {archive} {args}" + 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 = diff --git a/norg/restic/prune.nim b/norg/restic/prune.nim index fb8646d..35dd5ac 100644 --- a/norg/restic/prune.nim +++ b/norg/restic/prune.nim @@ -8,5 +8,5 @@ proc pruneRepo*(nc: NorgConfig, repo: Repository): int = return run cmd proc forgetSnapshot*(nc: NorgConfig, repo: Repository): int = - var cmd = genForgetCommand(cmd = "forget", repo = repo.path, archive = nc.args.archive, further_args = nc.args.further_args) + var cmd = genForgetCommand(repo = repo.path, archive = nc.args.archive, further_args = nc.args.further_args) return run cmd diff --git a/norg/restic/restore.nim b/norg/restic/restore.nim index c893add..903e3b3 100644 --- a/norg/restic/restore.nim +++ b/norg/restic/restore.nim @@ -18,7 +18,7 @@ proc restoreSnapshot*(nc: NorgConfig, repo: Repository): int = let dir = getCurrentDir() if dir.isEmpty(): echo "Restoring..." - let ok = run genRestoreCommand(cmd = "restore", repo_snapshot = repo_snapshot, destination = nc.args.extract_destination, further_args = further_args) + let ok = run genRestoreCommand(repo_snapshot = repo_snapshot, destination = nc.args.extract_destination, further_args = further_args) return ok else: echo "Not restoring to non-empty destination\r\nPlease use the --destination flag or cd to an empty directory."