fixes for source directories with spaces in their names
This commit is contained in:
parent
94068ea910
commit
52e3e7a2ab
7 changed files with 26 additions and 17 deletions
|
@ -7,7 +7,6 @@ import prune
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import times
|
import times
|
||||||
import sequtils
|
|
||||||
import strformat
|
import strformat
|
||||||
import nativesockets
|
import nativesockets
|
||||||
|
|
||||||
|
@ -17,8 +16,8 @@ proc genArchiveName(): string =
|
||||||
return fmt"{hostname}-{ts}"
|
return fmt"{hostname}-{ts}"
|
||||||
|
|
||||||
proc createArchive(nc: NorgConfig, repo: Repository, archivename: string, retry: int = 0): int =
|
proc createArchive(nc: NorgConfig, repo: Repository, archivename: string, retry: int = 0): int =
|
||||||
let further_args = concat(nc.source_directories, nc.args.further_args)
|
let further_args = nc.args.further_args
|
||||||
let res = run genCreateCommand(cmd = "create", repo = archivename, stats=nc.args.stats, further_args = further_args)
|
let res = run genCreateCommand(repo = archivename, sources = nc.source_directories, stats=nc.args.stats, further_args = further_args)
|
||||||
if res != 0:
|
if res != 0:
|
||||||
sleep 15 * 1000 # 15 seconds
|
sleep 15 * 1000 # 15 seconds
|
||||||
if retry == nc.retries:
|
if retry == nc.retries:
|
||||||
|
|
|
@ -11,15 +11,18 @@ proc genCommand*(cmd: string, repo: string, further_args: seq[string]): string =
|
||||||
let cmd = fmt"{BORG_BIN} {cmd} {repo} {args}"
|
let cmd = fmt"{BORG_BIN} {cmd} {repo} {args}"
|
||||||
return cmd
|
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(" ")
|
let args = further_args.join(" ")
|
||||||
var stats_flag = "--stats"
|
var stats_flag = "--stats"
|
||||||
if not stats: stats_flag = ""
|
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
|
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 args = further_args.join(" ")
|
||||||
let cmd = fmt"{BORG_BIN} {cmd} {repo} {archive} {args}"
|
let cmd = fmt"{BORG_BIN} delete {repo} {archive} {args}"
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
|
|
@ -8,5 +8,5 @@ proc pruneRepo*(nc: NorgConfig, repo: Repository): int =
|
||||||
return run cmd
|
return run cmd
|
||||||
|
|
||||||
proc deleteArchive*(nc: NorgConfig, repo: Repository): int =
|
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
|
return run cmd
|
||||||
|
|
|
@ -6,12 +6,11 @@ import prune
|
||||||
|
|
||||||
import nativesockets
|
import nativesockets
|
||||||
import times
|
import times
|
||||||
import sequtils
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
proc createArchive(nc: NorgConfig, repo: Repository, retry: int = 0): int =
|
proc createArchive(nc: NorgConfig, repo: Repository, retry: int = 0): int =
|
||||||
let further_args = concat(nc.source_directories, nc.args.further_args)
|
let further_args = nc.args.further_args
|
||||||
let res = run genCommand(cmd = "backup", repo = repo.path, further_args = further_args)
|
let res = run genBackupCommand(repo = repo.path, sources = nc.source_directories, further_args = further_args)
|
||||||
if res != 0:
|
if res != 0:
|
||||||
sleep 15 * 1000 # 15 seconds
|
sleep 15 * 1000 # 15 seconds
|
||||||
if retry == nc.retries:
|
if retry == nc.retries:
|
||||||
|
|
|
@ -11,14 +11,22 @@ 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 =
|
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 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
|
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 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
|
return cmd
|
||||||
|
|
||||||
proc genPruneCommand*(repo: string, further_args: seq[string], maintenance: Maintenance): string =
|
proc genPruneCommand*(repo: string, further_args: seq[string], maintenance: Maintenance): string =
|
||||||
|
|
|
@ -8,5 +8,5 @@ proc pruneRepo*(nc: NorgConfig, repo: Repository): int =
|
||||||
return run cmd
|
return run cmd
|
||||||
|
|
||||||
proc forgetSnapshot*(nc: NorgConfig, repo: Repository): int =
|
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
|
return run cmd
|
||||||
|
|
|
@ -18,7 +18,7 @@ proc restoreSnapshot*(nc: NorgConfig, repo: Repository): int =
|
||||||
let dir = getCurrentDir()
|
let dir = getCurrentDir()
|
||||||
if dir.isEmpty():
|
if dir.isEmpty():
|
||||||
echo "Restoring..."
|
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
|
return ok
|
||||||
else:
|
else:
|
||||||
echo "Not restoring to non-empty destination\r\nPlease use the --destination flag or cd to an empty directory."
|
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