WIP: find out why --repository arg isn't working
This commit is contained in:
parent
02f8c0f98b
commit
7654fc04bf
8 changed files with 37 additions and 12 deletions
|
@ -21,4 +21,4 @@ proc extractArchive*(nc: NorgConfig, repo: Repository): int =
|
||||||
let ok = run genCommand(cmd = "extract", repo = archive, further_args = further_args)
|
let ok = run genCommand(cmd = "extract", repo = archive, further_args = further_args)
|
||||||
return ok
|
return ok
|
||||||
else:
|
else:
|
||||||
echo "Not restoring to non-empty destination\r\nPlease use the --destination flag"
|
echo "Not restoring to non-empty destination\r\nPlease use the --destination flag or cd to an empty directory."
|
||||||
|
|
|
@ -26,7 +26,6 @@ proc parseArgs*() =
|
||||||
norg_args.command = opts.command.toCommand()
|
norg_args.command = opts.command.toCommand()
|
||||||
norg_args.repository = opts.repository
|
norg_args.repository = opts.repository
|
||||||
norg_args.further_args = opts.further_args
|
norg_args.further_args = opts.further_args
|
||||||
|
|
||||||
except ShortCircuit as err:
|
except ShortCircuit as err:
|
||||||
if err.flag == "argparse_help":
|
if err.flag == "argparse_help":
|
||||||
echo err.help
|
echo err.help
|
||||||
|
|
|
@ -26,8 +26,6 @@ proc parseRepositories*(rep_conf: TomlValueRef): seq[Repository] =
|
||||||
if rtable.hasKey("tool"):
|
if rtable.hasKey("tool"):
|
||||||
repo.tool = rtable["tool"].getStr("borg").toBackupTool()
|
repo.tool = rtable["tool"].getStr("borg").toBackupTool()
|
||||||
repos.add(repo)
|
repos.add(repo)
|
||||||
if norg_config.args.repository != "":
|
|
||||||
repos = repos.findRepository(norg_config.args.repository)
|
|
||||||
return repos
|
return repos
|
||||||
|
|
||||||
proc parseEncryption*(enc_conf: TomlValueRef) =
|
proc parseEncryption*(enc_conf: TomlValueRef) =
|
||||||
|
@ -41,6 +39,9 @@ proc parseConfigFile*(file: string): NorgConfig =
|
||||||
let in_conf = parsetoml.parseFile(file)
|
let in_conf = parsetoml.parseFile(file)
|
||||||
norg_config.source_directories = parseSourceDirectories(in_conf)
|
norg_config.source_directories = parseSourceDirectories(in_conf)
|
||||||
norg_config.repositories = parseRepositories(in_conf{"repositories"})
|
norg_config.repositories = parseRepositories(in_conf{"repositories"})
|
||||||
|
if norg_config.args.repository != "":
|
||||||
|
echo "Filtering repo list to selected: ", norg_config.args.repository
|
||||||
|
norg_config.repositories = norg_config.repositories.findRepository(norg_config.args.repository)
|
||||||
parseEncryption(in_conf{"encryption"})
|
parseEncryption(in_conf{"encryption"})
|
||||||
norg_config.notifiers = parseNotifiers(in_conf)
|
norg_config.notifiers = parseNotifiers(in_conf)
|
||||||
norg_config.actions = parseActions(in_conf{"actions"})
|
norg_config.actions = parseActions(in_conf{"actions"})
|
||||||
|
|
|
@ -19,5 +19,6 @@ proc toCommand*(str: string): Command =
|
||||||
case str
|
case str
|
||||||
of "backup": return CREATE
|
of "backup": return CREATE
|
||||||
of "snapshots","archives": return LIST
|
of "snapshots","archives": return LIST
|
||||||
|
of "restore": return EXTRACT
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,3 +10,8 @@ proc genCommand*(cmd: string, repo: string, further_args: seq[string]): string =
|
||||||
let cmd = fmt"{RESTIC_BIN} {cmd} -r {repo} {args}"
|
let cmd = fmt"{RESTIC_BIN} {cmd} -r {repo} {args}"
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
proc genRestoreCommand*(cmd: string, repo_snapshot: string, destination: string, further_args: seq[string]): string =
|
||||||
|
let args = further_args.join(" ")
|
||||||
|
let cmd = fmt"{RESTIC_BIN} {cmd} -r {repo_snapshot} --target {destination} {args}"
|
||||||
|
return cmd
|
||||||
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
import ../model/config_type
|
|
||||||
|
|
||||||
proc extractArchive*(nc: NorgConfig, repo: Repository): int =
|
|
||||||
echo "Not Yet Implemented"
|
|
||||||
discard
|
|
|
@ -5,7 +5,7 @@ import init
|
||||||
import backup
|
import backup
|
||||||
import list
|
import list
|
||||||
import mount
|
import mount
|
||||||
import extract
|
import restore
|
||||||
import prune
|
import prune
|
||||||
|
|
||||||
proc execute*(nc: NorgConfig, repo: Repository) =
|
proc execute*(nc: NorgConfig, repo: Repository) =
|
||||||
|
@ -26,8 +26,8 @@ proc execute*(nc: NorgConfig, repo: Repository) =
|
||||||
discard mountSnapshot(nc, repo)
|
discard mountSnapshot(nc, repo)
|
||||||
of EXTRACT:
|
of EXTRACT:
|
||||||
run_actions(norg_config.actions.before_extract)
|
run_actions(norg_config.actions.before_extract)
|
||||||
echo "Extracting backup from ", repo.label
|
echo "Restoring snapshot from ", repo.label
|
||||||
discard extractArchive(nc, repo)
|
discard restoreSnapshot(nc, repo)
|
||||||
run_actions(norg_config.actions.after_extract)
|
run_actions(norg_config.actions.after_extract)
|
||||||
of PRUNE:
|
of PRUNE:
|
||||||
run_actions(norg_config.actions.before_prune)
|
run_actions(norg_config.actions.before_prune)
|
||||||
|
|
24
norg/restic/restore.nim
Normal file
24
norg/restic/restore.nim
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import ../model/config_type
|
||||||
|
import execute
|
||||||
|
import strformat
|
||||||
|
import os
|
||||||
|
|
||||||
|
proc isEmpty(dir: string): bool =
|
||||||
|
var count = 0
|
||||||
|
for idx, f in walkDir(dir): return false
|
||||||
|
#count += 1
|
||||||
|
return count == 0
|
||||||
|
|
||||||
|
proc restoreSnapshot*(nc: NorgConfig, repo: Repository): int =
|
||||||
|
let repo_snapshot = fmt"{repo.path} {nc.args.further_args[0]}"
|
||||||
|
var further_args = nc.args.further_args[1..^1]
|
||||||
|
if nc.args.extract_destination != "":
|
||||||
|
discard existsOrCreateDir(nc.args.extract_destination)
|
||||||
|
setCurrentDir(nc.args.extract_destination)
|
||||||
|
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)
|
||||||
|
return ok
|
||||||
|
else:
|
||||||
|
echo "Not restoring to non-empty destination\r\nPlease use the --destination flag or cd to an empty directory."
|
Loading…
Reference in a new issue