From ecefeab8d767aeb549245b08616e901d88b22752 Mon Sep 17 00:00:00 2001 From: onefang Date: Fri, 13 Aug 2021 05:00:46 +1000 Subject: Next bit of the inventory backup, actually do the backup. --- src/sledjchisl/sledjchisl.c | 48 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index 96a1cd4..112c297 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -1123,7 +1123,7 @@ struct _simList // Stuff for the looping through sims, doing things, and waiting. int doIt; float la; - char *target; + char *target, *backup; }; simList *ourSims = NULL; @@ -1356,6 +1356,7 @@ void freeSimList(simList *sims) freeLuaTree(sims->simsLua); freeLuaTree(sims->unsorted); free(sims->target); + free(sims->backup); free(sims); } @@ -1686,6 +1687,21 @@ int checkSimIsRunning(char *sim) free(path); return ret; } + +void findWindow(simData *simd, char *sim, char *type, int count, int window, int panes, int pane) +{ + snprintf(toybuf, sizeof(toybuf), "%s/IDs_%d.lua", scTemp, window); + qtreetbl_t *IDs = Lua2tree(toybuf, "IDs"); + snprintf(toybuf, sizeof(toybuf), "%d %d", window, pane); + simd->paneID = xmprintf("%s", qLuaGet(IDs, toybuf)->v.s); + freeLuaTree(IDs); + if (strcmp(backupIARsim, sim) == 0) + { + ourSims->backup = xstrdup(simd->paneID); + V("Found backup sim %s in %s", sim, simd->paneID); + } +} + void prepSims(simData *simd, char *sim, char *type, int count, int window, int panes, int pane) { char *path = xmprintf("%s/%s.shini", scEtc, simd->tab); @@ -1724,12 +1740,7 @@ void prepSims(simData *simd, char *sim, char *type, int count, int window, int p snprintf(toybuf, sizeof(toybuf), "echo '}\nreturn IDs' >>%s/IDs_%d.lua", scTemp, window); system(toybuf); - snprintf(toybuf, sizeof(toybuf), "%s/IDs_%d.lua", scTemp, window); - qtreetbl_t *IDs = Lua2tree(toybuf, "IDs"); - snprintf(toybuf, sizeof(toybuf), "%d %d", window, pane); - simd->paneID = xmprintf("%s", qLuaGet(IDs, toybuf)->v.s); - freeLuaTree(IDs); - + findWindow(simd, sim, type, count, window, panes, pane); simd->portH = 8004 + count * 2; simd->portU = 8005 + count * 2; cmd = xmprintf("rm -fr %s/sim%d; mkdir -p %s/sim%d; sed -E" @@ -1888,7 +1899,27 @@ byTab has the short name as the key, simData as the value. strftime(date, DATE_TIME_LEN, "%F_%T", localtime(&curtime)); if (FLAG(m)) { - I("Member %s is being backed up to %s/backups/%s-%s.iar.", sim, scRoot, sim, date); + char *last = strchr(sim, ' '); + + last[0] = '\0'; last++; +// TODO - double check it's a real member. + I("Member %s %s is being backed up to %s/backups/%s_%s-%s.iar in tmux windo %s.", sim, last, scRoot, sim, last, date, ourSims->backup); + snprintf(toybuf, sizeof(toybuf), "save iar -c %s %s / password %s/backups/%s_%s-%s.iar", sim, last, scRoot, sim, last, date); + if (NULL != ourSims->backup) + { + sendTmuxCmd(ourSims->backup, toybuf); +// if (0 == do) + { + snprintf(toybuf, sizeof(toybuf), "Saved archive with [[:digit:]]+ items for %s %s", sim, last); + waitTmuxText(ourSims->backup, toybuf); + I("%s is done backing up.", simd->name); +// TODO - should delete / gitAR the old ones now. +// Have a config option for delete / gitAR / rsync. + ourSims->la = waitLoadAverage(ourSims->la, loadAverageInc, simTimeOut); + } + } + else + E("Can't find backup sim."); } else if (checkSimIsRunning(simd->tab)) { @@ -7991,6 +8022,7 @@ V("Doing %s for %s '%s' %s %s", modeStrings[currentMode], FLAG(m) ? "member" : { // Do stuff with the members. ourSims->doIt = 1; + forEachSim("Doing", findWindow, NULL); forEachMember("Doing", doSimsThing, NULL); } else -- cgit v1.1