aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authoronefang2021-10-14 02:52:49 +1000
committeronefang2021-10-14 02:52:49 +1000
commit9a8e3b5a93ff3985a37fc4fc5bd4611a5f42b806 (patch)
treedce0c508e4c3947aba0fe89158e65edf48234157
parentFix load iar fuckup. (diff)
downloadopensim-SC-9a8e3b5a93ff3985a37fc4fc5bd4611a5f42b806.zip
opensim-SC-9a8e3b5a93ff3985a37fc4fc5bd4611a5f42b806.tar.gz
opensim-SC-9a8e3b5a93ff3985a37fc4fc5bd4611a5f42b806.tar.bz2
opensim-SC-9a8e3b5a93ff3985a37fc4fc5bd4611a5f42b806.tar.xz
More tweaking of the backup system.
-rw-r--r--src/sledjchisl/sledjchisl.c103
1 files changed, 87 insertions, 16 deletions
diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c
index d8a7594..8e3a724 100644
--- a/src/sledjchisl/sledjchisl.c
+++ b/src/sledjchisl/sledjchisl.c
@@ -2266,7 +2266,10 @@ static int filterARs(struct dirtree *node)
2266 int l0 = strlen(node->name), l1 = strlen(list->this); 2266 int l0 = strlen(node->name), l1 = strlen(list->this);
2267 2267
2268// TODO - ignore zero sized ones. 2268// TODO - ignore zero sized ones.
2269 if ((4 < l0) && ((strncmp(&(node->name[l0 - 4]), ".iar", 4) == 0) || (strncmp(&(node->name[l0 - 4]), ".oar", 4) == 0)) && (strncmp(node->name, list->this, l1) == 0)) 2269 if ((
2270 ((4 < l0) && ((strncmp(&(node->name[l0 - 4]), ".iar", 4) == 0) || (strncmp(&(node->name[l0 - 4]), ".oar", 4) == 0)))
2271 || ((8 < l0) && ((strncmp(&(node->name[l0 - 8]), ".iar.tgz", 8) == 0) || (strncmp(&(node->name[l0 - 8]), ".oar.tgz", 8) == 0)))
2272 ) && (strncmp(node->name, list->this, l1) == 0))
2270 { 2273 {
2271 if ((list->num + 1) > list->len) 2274 if ((list->num + 1) > list->len)
2272 { 2275 {
@@ -2279,6 +2282,7 @@ static int filterARs(struct dirtree *node)
2279 return 0; 2282 return 0;
2280} 2283}
2281 2284
2285void ungitar(simData *simd, char *sim, int count, int window, int panes, int pane, int m, int member, char *last);
2282void gitar(simData *simd, char *sim, int count, int window, int panes, int pane, int m, int member, char *last) 2286void gitar(simData *simd, char *sim, int count, int window, int panes, int pane, int m, int member, char *last)
2283{ 2287{
2284 /* Work around OpenSims slow database corruption bug by using git to store all old backups. 2288 /* Work around OpenSims slow database corruption bug by using git to store all old backups.
@@ -2289,6 +2293,10 @@ void gitar(simData *simd, char *sim, int count, int window, int panes, int pane,
2289 2293
2290 Strategy - unpack the last one, unpack and commit any old I/OARs, pack up the result, delete it's working directory, THEN run the save i/oar. 2294 Strategy - unpack the last one, unpack and commit any old I/OARs, pack up the result, delete it's working directory, THEN run the save i/oar.
2291 Avoids having to sync with OpenSim finishing the current I/OAR, and as a bonus, an easy to deliver latest I/OAR for people that want it. 2295 Avoids having to sync with OpenSim finishing the current I/OAR, and as a bonus, an easy to deliver latest I/OAR for people that want it.
2296
2297TODO -
2298 Keep in mind some old files had munged names like "Tiffanie_s_Paradise-2021-06-23_05:11:38.oar"
2299 Maybe deal with those manually?
2292 */ 2300 */
2293 char *name = xstrdup(sim); 2301 char *name = xstrdup(sim);
2294 2302
@@ -2306,9 +2314,10 @@ void gitar(simData *simd, char *sim, int count, int window, int panes, int pane,
2306 } 2314 }
2307 } 2315 }
2308 2316
2309 char type = m ? 'I' : 'O'; 2317 char TYPE = m ? 'I' : 'O';
2310 char *gar = xmprintf("%s-git%cAR", name, type), *gtr = xmprintf("%s/%s.tar.xz", scBackup, gar); 2318 char type = m ? 'i' : 'o';
2311 char *dir = xmprintf("%s/temp_%c_%s", scBackup, type, name); 2319 char *gar = xmprintf("%s-git%cAR", name, TYPE), *gtr = xmprintf("%s/%s.tar.xz", scBackup, gar);
2320 char *dir = xmprintf("%s/temp_%c_%s", scBackup, TYPE, name);
2312 char *glog = xmprintf("%s/log.log", scBackup), *gerr = xmprintf("%s/errors", dir); 2321 char *glog = xmprintf("%s/log.log", scBackup), *gerr = xmprintf("%s/errors", dir);
2313 // Make sure stuff that's already compressed doesn't get compressed by git. 2322 // Make sure stuff that's already compressed doesn't get compressed by git.
2314 // Also tries to protect binaries from mangling. 2323 // Also tries to protect binaries from mangling.
@@ -2329,17 +2338,55 @@ void gitar(simData *simd, char *sim, int count, int window, int panes, int pane,
2329 if (qfile_exist(dir)) 2338 if (qfile_exist(dir))
2330 { 2339 {
2331 if (shellMeFail("echo 'Mess left over from last backup in %d, not gonna run!' >>%s", dir, gerr)) E("Cleaning up the mess!"); 2340 if (shellMeFail("echo 'Mess left over from last backup in %d, not gonna run!' >>%s", dir, gerr)) E("Cleaning up the mess!");
2332 if (shellMeFail("mv %s/*.%car %s 2>&1 >>%s", dir, tolower(type), scBackup, gerr)) E("Failed cleaning up the mess!"); 2341 if (shellMeFail("mv %s/*.%car %s 2>&1 >>%s", dir, type, scBackup, gerr)) E("Failed cleaning up the mess!");
2333 goto gitARend; 2342 goto gitARend;
2334 } 2343 }
2335 2344
2345 // Look for ancient ones first.
2346 char *fullName = qstrreplace("tn", simd->name, " ", "_");
2347 char *gar1 = xmprintf("%s_git%cAR", fullName, TYPE), *gtr1 = xmprintf("%s/%s.tar.xz", scBackup, gar1);
2348
2349// TODO - refactor this.
2350 if (qfile_exist(gtr1))
2351 {
2352 I("Found ancient gitar %s", gtr1);
2353 if (strcmp(fullName, sim) != 0)
2354 ungitar(simd, fullName, count, window, panes, pane, FLAG(m), member, last);
2355 ungitar(simd, sim, count, window, panes, pane, FLAG(m), member, last);
2356 if (!qfile_mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP, true)) E("Faild to make directory %s!", dir);
2357 if (shellMeFail("mv %s %s", gtr1, dir)) E("Failed to move %s!", gtr1);
2358 if (qfile_exist(gtr))
2359 {
2360 if (shellMeFail("mv %s %s", gtr, dir)) E("Failed to move %s!", gtr);
2361 }
2362 }
2363 free(gtr1);
2364 free(gar1);
2365 gar1 = xmprintf("%s_git%cAR", name, TYPE); gtr1 = xmprintf("%s/%s.tar.xz", scBackup, gar1);
2366 if (qfile_exist(gtr1))
2367 {
2368 I("Found ancient gitar %s", gtr1);
2369 ungitar(simd, sim, count, window, panes, pane, FLAG(m), member, last);
2370 if (!qfile_mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP, true)) E("Faild to make directory %s!", dir);
2371 if (shellMeFail("mv %s %s", gtr1, dir)) E("Failed to move %s!", gtr1);
2372 if (qfile_exist(gtr))
2373 {
2374 if (shellMeFail("mv %s %s", gtr, dir)) E("Failed to move %s!", gtr);
2375 }
2376 }
2377 free(gtr1);
2378 free(gar1);
2379
2336 // Either unpack the old gitAR, or create a new one. 2380 // Either unpack the old gitAR, or create a new one.
2337 qfile_mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP, true); 2381 if (!qfile_exist(dir))
2382 {
2383 if (!qfile_mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP, true)) E("Faild to make directory %s!", dir);
2384 }
2338 if (qfile_exist(gtr)) 2385 if (qfile_exist(gtr))
2339 { 2386 {
2340 I("Unpacking %s", gtr); 2387 I("Unpacking %s", gtr);
2341 if (shellMeFail("cd %s; ionice -c3 nice -n 19 tar -xf %s >>%s", dir, gtr, gerr)) E("Failed to unpack %s!", gtr); 2388 if (shellMeFail("cd %s; ionice -c3 nice -n 19 tar -xf %s >>%s", dir, gtr, gerr)) E("Failed to unpack %s!", gtr);
2342 char *t = xmprintf("%s/%s_git%cAR", dir, name, type); 2389 char *t = xmprintf("%s/%s_git%cAR", dir, name, TYPE);
2343 // Changed from _ to -, but deal with old archives. 2390 // Changed from _ to -, but deal with old archives.
2344 if (qfile_exist(t)) 2391 if (qfile_exist(t))
2345 { 2392 {
@@ -2377,13 +2424,40 @@ void gitar(simData *simd, char *sim, int count, int window, int panes, int pane,
2377 struct dirtree *new = dirtree_add_node(0, scBackup, 0); 2424 struct dirtree *new = dirtree_add_node(0, scBackup, 0);
2378 int i; 2425 int i;
2379 2426
2427 new->extra = (long) ourARs;
2380 ourARs->num = 0; 2428 ourARs->num = 0;
2429 if (strcmp(sim, fullName) != 0)
2430 {
2431 struct dirtree *new1 = dirtree_add_node(0, scBackup, 0);
2432
2433 new1->extra = (long) ourARs;
2434 ourARs->this = xmprintf("%s-", fullName);
2435 dirtree_handle_callback(new1, filterARs);
2436 for (i = 0; i < ourARs->num; i++)
2437 {
2438 char *t = ourARs->ARs[i];
2439 int l0 = strlen(t), l1 = strlen(ourARs->this);
2440
2441 V("Renaming %s -> %s-%s.tgz", t, name, &t[l1]);
2442 if (shellMeFail("cd %s; mv %s %s-%s.tgz", scBackup, t, name, &t[l1])) E("Failed to mv %s -> %s-%s.tgz!", t, name, &t[l1]);
2443 }
2444 free(ourARs->ARs);
2445 ourARs->ARs = NULL;
2446 ourARs->len = 0;
2447 free(ourARs->this);
2448 ourARs->num = 0;
2449 }
2381 ourARs->this = xmprintf("%s-", name); 2450 ourARs->this = xmprintf("%s-", name);
2382 new->extra = (long) ourARs;
2383 dirtree_handle_callback(new, filterARs); 2451 dirtree_handle_callback(new, filterARs);
2384 qsort(ourARs->ARs, ourARs->num, sizeof(char *), qstrcmp); 2452 qsort(ourARs->ARs, ourARs->num, sizeof(char *), qstrcmp);
2385 for (i = 0; i < ourARs->num; i++) 2453 for (i = 0; i < ourARs->num; i++)
2386 { 2454 {
2455 char *t = xstrdup(ourARs->ARs[i]);
2456 int l = strlen(t);
2457
2458 if (strcmp(".tgz", &t[l - 4]) == 0) {t[l - 4] = '\0'; l -= 4;}
2459 if (strcmp(".iar", &t[l - 4]) == 0) {t[l - 4] = '\0'; l -= 4;}
2460 if (strcmp(".oar", &t[l - 4]) == 0) {t[l - 4] = '\0'; l -= 4;}
2387 I("Adding %s to %s", ourARs->ARs[i], gtr); 2461 I("Adding %s to %s", ourARs->ARs[i], gtr);
2388 // Deal with deletions in the inventory / sim, easy method, which becomes a nop for files that stay in the git add below. 2462 // Deal with deletions in the inventory / sim, easy method, which becomes a nop for files that stay in the git add below.
2389 if (shellMeFail("cd %s/%s; rm -fr * >>%s", dir, gar, gerr)) E("Failed to rm!"); 2463 if (shellMeFail("cd %s/%s; rm -fr * >>%s", dir, gar, gerr)) E("Failed to rm!");
@@ -2410,7 +2484,7 @@ void gitar(simData *simd, char *sim, int count, int window, int panes, int pane,
2410 V("Committing changes from %s", ourARs->ARs[i]); 2484 V("Committing changes from %s", ourARs->ARs[i]);
2411 // Note this commit message has to be just the file name, as the ungitAR script uses it. 2485 // Note this commit message has to be just the file name, as the ungitAR script uses it.
2412 if (shellMeFail("cd %s/%s; git commit -a -qm \"%s\" >>%s || echo \"ERROR - Could not commit %s !\" >>%s ", 2486 if (shellMeFail("cd %s/%s; git commit -a -qm \"%s\" >>%s || echo \"ERROR - Could not commit %s !\" >>%s ",
2413 dir, gar, ourARs->ARs[i], ourARs->ARs[i], glog, gerr)) E("Failed to git commit!"); 2487 dir, gar, t, glog, t, gerr)) E("Failed to git commit!");
2414 if (hasContents(gerr)) 2488 if (hasContents(gerr))
2415 { 2489 {
2416 free(ourARs->ARs[i]); 2490 free(ourARs->ARs[i]);
@@ -2422,8 +2496,9 @@ void gitar(simData *simd, char *sim, int count, int window, int panes, int pane,
2422 } 2496 }
2423 if (!hasContents(gerr)) 2497 if (!hasContents(gerr))
2424 { 2498 {
2425 if (shellMeFail("mv %s/%s %s", scBackup, ourARs->ARs[i], dir)) E("Failed to move %s!", ourARs->ARs[i]); 2499 if (shellMeFail("mv %s/%s %s/", scBackup, ourARs->ARs[i], dir)) E("Failed to move %s!", ourARs->ARs[i]);
2426 } 2500 }
2501 free(t);
2427 free(ourARs->ARs[i]); 2502 free(ourARs->ARs[i]);
2428 } 2503 }
2429 2504
@@ -2444,6 +2519,7 @@ gitARend:
2444 { 2519 {
2445 if (shellMeFail("rm -fr %s", dir)) E("Failed to rm!"); 2520 if (shellMeFail("rm -fr %s", dir)) E("Failed to rm!");
2446 } 2521 }
2522 free(fullName);
2447 free(ourARs->ARs); 2523 free(ourARs->ARs);
2448 free(ourARs->this); 2524 free(ourARs->this);
2449 free(ourARs); 2525 free(ourARs);
@@ -2555,14 +2631,13 @@ void ungitar(simData *simd, char *sim, int count, int window, int panes, int pan
2555 { 2631 {
2556 I("Extracting %s", prev); 2632 I("Extracting %s", prev);
2557 free(prev); 2633 free(prev);
2558 prev = xmprintf("%s/%s", dir, out); 2634 prev = xmprintf("%s/%s-%s", scBackup, simd->tab, &out[l - 24]); // Converting any old full names to new names.
2559 // OpenSim insists on the archive.xml file being the very first in the tarball. 2635 // OpenSim insists on the archive.xml file being the very first in the tarball.
2560 if (shellMeFail("cd %s/%s; ionice -c3 nice -n 19 tar -c archive.xml -f %s", dir, gar, prev)) E("Failed to tar %s!", prev); 2636 if (shellMeFail("cd %s/%s; ionice -c3 nice -n 19 tar -c archive.xml -f %s", dir, gar, prev)) E("Failed to tar %s!", prev);
2561 if (shellMeFail("cd %s/%s; ionice -c3 nice -n 19 tar -r -f %s --exclude='.git*' --exclude='archive.xml' * ", 2637 if (shellMeFail("cd %s/%s; ionice -c3 nice -n 19 tar -r -f %s --exclude='.git*' --exclude='archive.xml' * ",
2562 dir, gar, prev)) E("Failed to tar %s!", prev); 2638 dir, gar, prev)) E("Failed to tar %s!", prev);
2563 // Using gzip instead of something that compresses better, coz OpenSim only knows how to deal with gzipped files. 2639 // Using gzip instead of something that compresses better, coz OpenSim only knows how to deal with gzipped files.
2564 if (shellMeFail("cd %s/%s; ionice -c3 nice -n 19 gzip -S .tgz %s", dir, gar, prev)) E("Failed to gzip %s!", prev); 2640 if (shellMeFail("cd %s/%s; ionice -c3 nice -n 19 gzip -S .tgz %s", dir, gar, prev)) E("Failed to gzip %s!", prev);
2565 if (shellMeFail("cd %s/%s; mv %s.tgz ../..", dir, gar, prev)) E("Failed to rename %s!", prev);
2566 } 2641 }
2567 else 2642 else
2568 W("NOT extracting %s, it already exists.", prev); 2643 W("NOT extracting %s, it already exists.", prev);
@@ -2690,10 +2765,6 @@ byTab has the short name as the key, simData as the value.
2690 } 2765 }
2691 else if (checkSimIsRunning(simd->tab)) 2766 else if (checkSimIsRunning(simd->tab))
2692 { 2767 {
2693// TODO - should collect names of existing backups, both tmux / ini name and proper name.
2694// Scan backups directory once before this for loop, add details to sims list.
2695// strip off the last bit of file name (YYYY-mm-dd_HH:MM:SS.oar) to get the name
2696// keep in mind some old files had munged names like "Tiffanie_s_Paradise-2021-06-23_05:11:38.oar"
2697 I("Sim %s is being backed up to %s/backups/%s-%s.oar.", simd->name, scRoot, simd->tab, date); 2768 I("Sim %s is being backed up to %s/backups/%s-%s.oar.", simd->name, scRoot, simd->tab, date);
2698 if ('\0' == rSync[0]) 2769 if ('\0' == rSync[0])
2699 { 2770 {