use rsync to verify sources exist in dests.

master
itwrx 1 year ago
parent 7e33cb5773
commit 19f0c072eb
  1. 32
      views/routine_list.nim

@ -36,6 +36,8 @@ proc rsyncThread(list: RoutineListState) {.thread.} =
#i'm not sure if using threadvar here is needed, but doing it just in case. :) #i'm not sure if using threadvar here is needed, but doing it just in case. :)
var rsyncRunCmd {.threadvar.}: string var rsyncRunCmd {.threadvar.}: string
var rsyncRun {.threadvar.}: tuple[output: string, exitCode: int] var rsyncRun {.threadvar.}: tuple[output: string, exitCode: int]
var rsyncCheckCmd {.threadvar.}: string
var rsyncCheckRun {.threadvar.}: tuple[output: string, exitCode: int]
var rsyncErrors: seq[string] var rsyncErrors: seq[string]
var routineRunCount: int var routineRunCount: int
@ -48,9 +50,6 @@ proc rsyncThread(list: RoutineListState) {.thread.} =
routineRuncount += 1 routineRuncount += 1
for source in routine.sources: for source in routine.sources:
for destination in routine.destinations: for destination in routine.destinations:
#per source/dest combo msgs still don't seem to be working right.
#maybe it requires a separate thread per combo? deprioritized.
#list.runStatus = "<span color=\"#FFE97B\" size=\"large\">Bkup " & source & " to " & destination & "...</span>"
#try without requiring superuser privs by default. #try without requiring superuser privs by default.
rsyncRunCmd = "rsync -aq " & source & " " & destination rsyncRunCmd = "rsync -aq " & source & " " & destination
rsyncRun = execCmdEx(rsyncRunCmd) rsyncRun = execCmdEx(rsyncRunCmd)
@ -66,10 +65,31 @@ proc rsyncThread(list: RoutineListState) {.thread.} =
rsyncRun = execCmdEx(rsyncRunCmd) rsyncRun = execCmdEx(rsyncRunCmd)
if rsyncRun.exitCode != 0: if rsyncRun.exitCode != 0:
rsyncErrors.add("EZ-Bkup's rsync process(es) returned error (" & $rsyncRun.output & ") while attempting to back up " & source & " to " & destination) rsyncErrors.add("EZ-Bkup's rsync process(es) returned error (" & $rsyncRun.output & ") while attempting to back up " & source & " to " & destination)
#handle non-perms related error.
else: else:
rsyncErrors.add("EZ-Bkup's rsync process(es) returned error (" & $rsyncRun.output & ") while attempting to back up " & source & " to " & destination) rsyncErrors.add("EZ-Bkup's rsync process(es) returned error (" & $rsyncRun.output & ") while attempting to back up " & source & " to " & destination)
#explicitly check that sources were copied to destinations.
#just using file names, mod times, and size (same as bkup run itself).
rsyncCheckCmd = "rsync -rn " & source & " " & destination
rsyncCheckRun = execCmdEx(rsyncCheckCmd)
if rsyncCheckRun.exitCode != 0:
#handle permission denied error.
if rsyncCheckRun.exitCode == 23:
rsyncCheckRun.exitCode = 0
if getAskPassPath() == "":
let err = "No ssh-askpass binary found. Please install an ssh-askpass package for your distro, and let us know if EZ-Bkup still can't detect it's location."
rsyncErrors.add(err)
else:
rsyncCheckCmd = "SUDO_ASKPASS=" & getAskPassPath() & " sudo -A rsync -rn " & source & " " & destination
rsyncCheckRun = execCmdEx(rsyncCheckCmd)
if rsyncCheckRun.exitCode != 0:
rsyncErrors.add("EZ-Bkup's rsync process(es) returned error (" & $rsyncRun.output & ") while attempting to verify that " & source & " got backed up to " & destination)
#handle non-perms related error.
else:
rsyncErrors.add("EZ-Bkup's rsync process(es) returned error (" & $rsyncRun.output & ") while attempting to verify that " & source & " got backed up to " & destination)
if rsyncErrors.len > 0: if rsyncErrors.len > 0:
list.runStatus = "<span color=\"#ff6b6b\" size=\"large\">Error! Please see the log at ~/.ez-bkup/errors.log</span>" list.runStatus = "<span color=\"#ff6b6b\" size=\"large\">Error! Please see ~/.ez-bkup/errors.log</span>"
for err in rsyncErrors: for err in rsyncErrors:
logger.log(lvlError, err) logger.log(lvlError, err)
elif routineRunCount == 0: elif routineRunCount == 0:
@ -214,8 +234,8 @@ method view(list: RoutineListState): Widget =
xAlign = 0 xAlign = 0
useMarkup = true useMarkup = true
proc clicked() = proc clicked() =
#check that every source and destination exists for each routine or don't run bkup and show dialog. #check that every source and destination exists for each routine or don't run bkup and show err status.
#locations not found will be logged. see shared.nim #locations not found will be logged. see routine.nim
var allLocationsExist: seq[bool] var allLocationsExist: seq[bool]
for routine in list.routineModel.routineSeq(): for routine in list.routineModel.routineSeq():
if routine.id in list.selected: if routine.id in list.selected:

Loading…
Cancel
Save