48#define MAX_LAZY_CHANNEL 100
50#define LOG_TYPE_SCRIPT (-1)
92 int ia = strtoul(sa, (
char **) &sa, 10);
93 int ib = strtoul(sb, (
char **) &sb, 10);
119#define MAX_FILE_PATH 128
122#define LAZY_SETTINGS_STRING "\
124Maintain free space (%) = INT : 0\n\
125Stay behind = INT : 0\n\
126Alarm Class = STRING : [32]\n\
127Running condition = STRING : [128] ALWAYS\n\
128Data dir = STRING : [256] \n\
129Data format = STRING : [8] MIDAS\n\
130Filename format = STRING : [128] run%05d.mid\n\
131Backup type = STRING : [8] Tape\n\
132Execute after rewind = STRING : [64]\n\
133Path = STRING : [128] \n\
134Capacity (Bytes) = FLOAT : 5e9\n\
135List label= STRING : [128] \n\
136Execute before writing file = STRING : [64]\n\
137Execute after writing file = STRING : [64]\n\
138Modulo.Position = STRING : [8]\n\
139Copy Delay = INT : 0\n\
140Tape Data Append = BOOL : y\n\
142#define LAZY_STATISTICS_STRING "\
143Backup file = STRING : [128] none \n\
144File size (Bytes) = DOUBLE : 0.0\n\
145KBytes copied = DOUBLE : 0.0\n\
146Total Bytes copied = DOUBLE : 0.0\n\
147Copy progress (%) = DOUBLE : 0\n\
148Copy Rate (Bytes per s) = DOUBLE : 0\n\
149Backup status (%) = DOUBLE : 0\n\
150Number of Files = INT : 0\n\
151Current Lazy run = INT : 0\n\
169 char commandBefore[64];
170 char commandAfter[64];
217#define WATCHDOG_TIMEOUT 60000
239 for (
unsigned i = 0;
i < dirlog->size();
i++)
240 printf(
"%d: %s, run %d, size %12.0f\n",
242 (*dirlog)[
i].filename.c_str(),
249 printf(
"lazy has detected a STOP transition\n");
272 mstrlcpy(run_str,
name,
sizeof(run_str));
273 if (strlen(run_str) < 2)
276 for (
j = strlen(run_str) - 1;
j >= 0 && !isdigit(run_str[
j]);
j--)
279 for (
j = strlen(run_str) - 1;
j >= 0 && isdigit(run_str[
j]);
j--);
281 return atoi(run_str +
j + 1);
298 printf(
"lazy_file_remove: running in nodelete mode (-n switch), will not remove \'%s\'\n", pufile);
303 fHandle = open(pufile, O_RDONLY, 0644);
319 strcpy(
str,
"no action");
327 sprintf(
str,
"%s[%i]: (cp:%.1fs) %s %1.3lfMB file COPIED",
330 sprintf(
str,
"%s[%i]: (cp:%.1fs) %s %1.3lfMB file COPIED",
333 sprintf(
str,
"%s[%i]: (cp:%.1fs) %s %1.3lfMB file NEW",
339 sprintf(
str,
"%s[%i]: (cp:%.1fs) %s%s %1.3lfMB file NEW",
344 sprintf(
str,
"%s[%i]: (cp:%.1fs) %s/%s %1.3lfMB file NEW (position at block %d)",
352 cm_msg(
MINFO,
"Lazy",
"Exec post file write script:%s", cmd);
357 sprintf(
str,
"%i (rm:%dms) %s file REMOVED",
run, perf_time,
file);
360 sprintf(
str,
"%s run#%i entry REMOVED", label,
run);
383 if ((lrun %
lModulo) == lPosition)
408 int lModulo = 0, lPosition = 0;
410 mstrlcpy(dir, xdir,
sizeof(dir));
414 mstrlcpy(
str, fmt,
sizeof(
str));
416 fmt = strchr(fmt,
',');
420 char *s = strchr(
str,
',');
424 if (strchr(
str,
'%')) {
425 *strchr(
str,
'%') =
'*';
426 if (strchr(
str,
'.'))
427 strcpy((strchr(
str,
'*') + 1), strchr(
str,
'.'));
441 std::vector<std::string> flist;
442 for (
int j = 0;
j < nfile;
j++)
454 lPosition = atoi(dot + 1);
460 for (
unsigned j = 0 ;
j < flist.size();
j++) {
482 sort(dlist->begin(), dlist->end(),
cmp_dirlog);
484 return dlist->size();
502 INT i,
j, size, tot_nelement, nelement, temp;
515 *pdo = (
INT *) realloc(*pdo,
sizeof(
INT) * (tot_nelement + nelement));
516 size = nelement *
sizeof(
INT);
518 tot_nelement += nelement;
522 printf(
"read pdo: %d\n", tot_nelement);
523 for (
i = 0;
i < tot_nelement;
i++)
524 printf(
"%d: %d\n",
i, (*pdo)[
i]);
528 for (
i = 0;
i < tot_nelement;
i++)
530 int first = (*pdo)[
i - 1];
531 int last = -(*pdo)[
i];
532 int nruns = last - first + 1;
535 *pdo = (
INT *) realloc(*pdo,
sizeof(
INT) * (tot_nelement + nruns - 2));
536 assert(*pdo != NULL);
538 memmove((*pdo) +
i + nruns - 1, (*pdo) +
i + 1,
sizeof(
INT) * (tot_nelement -
i - 1));
540 for (
j = 1;
j < nruns;
j++)
541 (*pdo)[
i +
j - 1] = first +
j;
543 tot_nelement += nruns - 2;
547 printf(
"uncompressed pdo: %d\n", tot_nelement);
548 for (
i = 0;
i < tot_nelement;
i++)
549 printf(
"%d: %d\n",
i, (*pdo)[
i]);
553 for (
j = 0;
j < tot_nelement - 1;
j++) {
554 for (
i =
j + 1;
i < tot_nelement;
i++) {
555 if (*(*pdo +
j) > *(*pdo +
i)) {
556 memcpy(&temp, (*pdo +
i),
sizeof(
INT));
557 memcpy((*pdo +
i), (*pdo +
j),
sizeof(
INT));
558 memcpy((*pdo +
j), &temp,
sizeof(
INT));
564 printf(
"sorted pdo: %d\n", tot_nelement);
565 for (
i = 0;
i < tot_nelement;
i++)
566 printf(
" %d\n", (*pdo)[
i]);
588 char *s = fgets(
str,
sizeof(
str),
fp);
594 char *p = strchr(s,
' ');
602 d.runno = strtoul(p, &p, 0);
603 d.size = strtod(p, &p);
607 for (
unsigned i = 0;
i < dirlist->size();
i++)
608 if ((*dirlist)[
i].filename ==
d.filename) {
621 sort(dlist->begin(), dlist->end(),
cmp_dirlog);
626 std::string tmpname = fname +
".tmp";
628 FILE *
fp = fopen(tmpname.c_str(),
"w");
630 cm_msg(
MERROR,
"save_list",
"Cannot write to \'%s\', errno %d (%s)",
637 for (
unsigned i = 0;
i < dlist->size();
i++) {
638 const char *s = (*dlist)[
i].filename.c_str();
642 fprintf(
fp,
"%s %d %12.0f\n",
650 int status = rename(tmpname.c_str(), fname.c_str());
652 cm_msg(
MERROR,
"save_list",
"Cannot rename \'%s\' to \'%s\', errno %d (%s)",
698 for (
int i = 0;
i <
n;
i++)
699 for (
unsigned j = 0;
j < dlist.size();
j++)
700 if (dlist[
j].runno == pdo[
i])
701 done.push_back(dlist[
j]);
711 "Done list converted from old ODB \'/Lazy/%s/List\' format to new file-based format. ODB \'List\' renamed to \'List.converted\'",
738 "lazylogger cannot continue: found old-style done list in ODB \'/Lazy/%s/List\'. Please convert to new done list format using \'lazylogger -C\'",
746 return pdone->size();
765 sort(pdone->begin(), pdone->end(),
cmp_dirlog);
785 for (
unsigned j = 0;
j < plog->size();
j++) {
787 for (
unsigned i = 0;
i < pdone->size();
i++) {
788 if ((*plog)[
j].filename == (*pdone)[
i].filename)
793 if ((*plog)[
j].size > 0)
825 char ddir[256], ff[128], strmodulo[8];
842 if (((pLall +
i)->
hKey)) {
844 size =
sizeof(strmodulo);
849 printf(
"purge: skipping channel \'%s\' which uses modulo \'%s\'\n",
lazyinfo[
i].
name, strmodulo);
860 int len = strlen(ddir);
861 if (ddir[len - 1] !=
'/') {
867 if (strcmp(ddir, dir) != 0) {
869 printf(
"purge: skipping channel \'%s\' which uses different data dir \'%s\', we use \'%s\'\n",
875 printf(
"Loading file lists for channel \'%s\', data dir \'%s\', format \'%s\'\n",
lazyinfo[
i].
name, ddir,
885 for (
unsigned k = 0;
k < dirlists[
channel].size();
k++) {
886 bool can_delete =
true;
889 printf(
"purge: consider file \'%s\'\n", dirlists[
channel][
k].filename.c_str());
892 if (((pLall +
i)->
hKey)) {
893 bool in_dir_list =
false;
894 bool in_done_list =
false;
896 for (
unsigned j = 0;
j < dirlists[
i].size();
j++)
897 if (dirlists[
i][
j].filename == dirlists[
channel][
k].filename) {
904 printf(
"channel \'%s\': file is not in dir list, ok to delete\n",
lazyinfo[
i].
name);
908 for (
unsigned j = 0;
j < donelists[
i].size();
j++)
909 if (donelists[
i][
j].filename == dirlists[
channel][
k].filename) {
916 printf(
"channel \'%s\': file is in dirlist but not in done list, cannot delete\n",
923 printf(
"channel \'%s\': file is in dirlist and in done list, ok to delete\n",
lazyinfo[
i].
name);
928 printf(
"purge: file \'%s\' is done by all channels\n", dirlists[
channel][
k].filename.c_str());
954 char dir[256], ff[128];
955 char cdir[256], cff[128];
956 char cmodulostr[8], modulostr[8];
964 size =
sizeof(maintain);
974 size =
sizeof(modulostr);
984 size =
sizeof(modulostr);
987 if ((strcmp(dir, cdir) == 0) && (strcmp(ff, cff) == 0) && !cmodulostr[0] && !modulostr[0]) {
989 size =
sizeof(maintain);
994 size =
sizeof(maintain);
998 "Maintain free space on channel %s has been disable", (pLall +
i)->
name);
1022 printf(
"lastsz:%f - ",
lastsz);
1026 if (cploop_time == 0)
1071 char left[64], right[64];
1072 char *p = NULL, *pp, *ppl, *pc, *lp;
1080 pc = strpbrk(p,
"<=>");
1082 strncpy(
left, p, pc - p);
1083 lp =
left + (pc - p - 1);
1084 while (isspace(*lp))
1087 strncpy(right, pc + 1, (strlen(p) - strlen(
left)));
1088 right[strlen(p) - strlen(
left) - 1] =
'\0';
1091 if ((pp = strpbrk(
left,
"[(")) != NULL) {
1092 if ((ppl = strpbrk(
left,
"])")) != NULL) {
1095 index = atoi(pp + 1);
1101 value = (double) (atoi(right));
1111 size =
sizeof(lcond_value);
1114 lcond_value = std::stof(s);
1125 if (((*pc ==
'>') && ((
double) lcond_value >
value)) || ((*pc ==
'=') && ((
double) lcond_value ==
value)) ||
1126 ((*pc ==
'<') && ((
double) lcond_value <
value)))
1181 DWORD watchdog_timeout;
1182 static INT last_error = 0;
1184 BOOL watchdog_flag, exit_request =
FALSE;
1188 printf(
"lazy_copy %s to %s\n", infile, outfile);
1194 mstrlcpy(filename, outfile,
sizeof(filename));
1196 if ((
ss_time() - last_error) > 60) {
1241 cm_msg(
MINFO,
"Lazy",
"Exec pre file write script:%s", cmd);
1247 cpy_loop_time = -2000;
1288 cm_msg(
MINFO,
"Lazy",
"Abort postponed until end of copy of %s %1.0lf[%%]",
1290 exit_request =
TRUE;
1335 int no_cpy_last_time = 0;
1338 int cpy_loop_time = -2000;
1343 const int kBufSize = 1 * 1024 * 1024;
1345 int rd = fread(buf, 1, kBufSize, fpin);
1347 int wr = fwrite(buf, 1, rd, fpout);
1349 cm_msg(
MERROR,
"Lazy_disk_copy",
"Cannot write to \'%s\', errno %d (%s)", outfile, errno,
1375 }
else if (rd == 0) {
1380 cm_msg(
MERROR,
"Lazy_disk_copy",
"Cannot read from \'%s\', errno %d (%s)", infile, errno, strerror(errno));
1402INT cpy_sftp_loop_time = 0;
1404static size_t readfunc(
void *ptr,
size_t size,
size_t nmemb,
void *stream) {
1405 FILE *f = (FILE *) stream;
1408 return CURL_READFUNC_ABORT;
1410 n = fread(ptr, size, nmemb, f) * size;
1416 printf(
"readfunc (CURL) size:%ld nmemb:%ld n:%li total:%f\n", size, nmemb,
n,
lastsz);
1427long int port_number = 22;
1430static long int get_remote_file_size(
const char *remote_file) {
1432 long int remote_file_size_byte = -1;
1434 CURL *curlhandle = curl_easy_init();
1438 curl_easy_setopt(curlhandle, CURLOPT_VERBOSE, 1);
1441 curl_easy_setopt(curlhandle, CURLOPT_URL, remote_file);
1443 curl_easy_setopt(curlhandle, CURLOPT_PORT, port_number);
1447 curl_easy_setopt(curlhandle, CURLOPT_NOPROGRESS, 1);
1449 curl_easy_setopt(curlhandle, CURLOPT_NOBODY, 1);
1451 curl_easy_setopt(curlhandle, CURLOPT_HEADER, 1);
1453 curl_easy_setopt(curlhandle, CURLOPT_FILETIME, 1);
1456 result = curl_easy_perform(curlhandle);
1457 if (result == CURLE_OK) {
1460#if LIBCURL_VERSION_NUM < 0x073700
1461 result = curl_easy_getinfo(curlhandle, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &remote_file_size_byte);
1463 result = curl_easy_getinfo(curlhandle, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &remote_file_size_byte);
1469 printf(
"[%s] Remote file size: %ld byte \n", __FUNCTION__, remote_file_size_byte);
1471 }
else if (result == CURLE_REMOTE_FILE_NOT_FOUND) {
1473 printf(
"[%s] Remote file %s not existent \n", __FUNCTION__, remote_file);
1478 curl_easy_cleanup(curlhandle);
1480 return remote_file_size_byte;
1485int lazy_sftp_copy_loop(
const char *outfile,
const char *infile, FILE *fpin) {
1488 CURL *curlhandle = NULL;
1489 curl_global_init(CURL_GLOBAL_ALL);
1490 curlhandle = curl_easy_init();
1494 cpy_sftp_loop_time = 0;
1496 curl_easy_setopt(curlhandle, CURLOPT_UPLOAD, 1L);
1498 curl_easy_setopt(curlhandle, CURLOPT_URL, outfile);
1500 curl_easy_setopt(curlhandle, CURLOPT_PORT, port_number);
1506 result = curl_easy_setopt(curlhandle, CURLOPT_READFUNCTION, readfunc);
1508 curl_easy_setopt(curlhandle, CURLOPT_READDATA, fpin);
1511 result = curl_easy_setopt(curlhandle, CURLOPT_INFILESIZE,
lazyst.
file_size);
1513 result = curl_easy_setopt(curlhandle, CURLOPT_INFILESIZE_LARGE,
lazyst.
file_size);
1515 result = curl_easy_perform(curlhandle);
1517 cm_msg(
MERROR,
"SFTP_copy",
"Failed to upload due to CURL errror %d", result);
1518 printf(
"Failed to upload file '%s' with error code %d \n", infile, result);
1520 printf(
"File '%s' successfully uploaded \n", infile);
1523 curl_easy_cleanup(curlhandle);
1524 curl_global_cleanup();
1531int lazy_sftp_copy(
const char *outfile,
const char *infile) {
1533 DWORD watchdog_timeout;
1537 printf(
"lazy_sftp_copy %s to %s\n", infile, outfile);
1539 double MiB = 1024 * 1024;
1551 cm_msg(
MINFO,
"Lazy",
"Exec pre file write script:%s", cmd);
1555 FILE *fpin = fopen(infile,
"rb");
1557 cm_msg(
MERROR,
"Lazy_sftp_copy",
"Cannot read from \'%s\', errno %d (%s)", infile, errno, strerror(errno));
1565 sprintf(
str,
"Starting lazy_sftp_copy \'%s\' to \'%s\'", infile, outfile);
1577 int copy_status = lazy_sftp_copy_loop(outfile, infile, fpin);
1579 int remote_size = get_remote_file_size(outfile);
1583 printf(
" File copied incomplete (%s)\n", outfile);
1584 cm_msg(
MERROR,
"Lazy_SFTP_Copy",
"File copied incomplete (%s)\n", outfile);
1589 printf(
"*********** remove File Size: %d\n", remote_size);
1604 chmod(outfile, 0444);
1608 cm_msg(
MINFO,
"lazy_disk_copy",
"Copy finished in %.1f sec, %.1f MiBytes at %.1f MiBytes/sec", t,
1630 DWORD watchdog_timeout;
1634 printf(
"lazy_disk_copy %s to %s\n", infile, outfile);
1636 double MiB = 1024 * 1024;
1641 printf(
"output disk size %.1f MiB, free %.1f MiB\n", disk_size /
MiB, disk_free /
MiB);
1650 cm_msg(
MINFO,
"Lazy",
"Exec pre file write script:%s", cmd);
1654 FILE *fpin = fopen(infile,
"rb");
1656 cm_msg(
MERROR,
"Lazy_disk_copy",
"Cannot read from \'%s\', errno %d (%s)", infile, errno, strerror(errno));
1660 FILE *fptest = fopen(outfile,
"rb");
1664 cm_msg(
MINFO,
"Lazy_disk_copy",
"Output file \'%s\' already exists, removing", outfile);
1669 FILE *fpout = fopen(outfile,
"wb");
1671 cm_msg(
MERROR,
"Lazy_disk_copy",
"Cannot write to \'%s\', errno %d (%s)", outfile, errno, strerror(errno));
1677 setbuf(fpout, NULL);
1681 sprintf(
str,
"Starting lazy_disk_copy \'%s\' to \'%s\'", infile, outfile);
1705 cm_msg(
MERROR,
"Lazy_disk_copy",
"Cannot close \'%s\', errno %d (%s)", outfile, errno, strerror(errno));
1715 chmod(outfile, 0444);
1719 cm_msg(
MINFO,
"lazy_disk_copy",
"Copy finished in %.1f sec, %.1f MiBytes at %.1f MiBytes/sec", t,
1729INT lazy_script_copy(
char *infile)
1752 cm_msg(
MINFO,
"Lazy",
"Exec pre file write script:%s", cmd);
1757 sprintf(cmd,
"%s %s 2>&1",
lazy.
path, infile);
1760 char str[100 + 256];
1761 sprintf(
str,
"Starting lazy job \'%s\'", cmd);
1768 fin = popen(cmd,
"r");
1771 cm_msg(
MTALK,
"lazy_script_copy",
"Cannot start \'%s\', errno %d (%s)", cmd, errno, strerror(errno));
1776 int desc = fileno(fin);
1777 int flags = fcntl(desc, F_GETFL, 0);
1778 fcntl(desc, F_SETFL, flags | O_NONBLOCK);
1784 int rd =
read(fileno(fin), buf,
sizeof(buf));
1788 }
else if (rd < 0) {
1791 if (errno == EAGAIN) {
1797 cm_msg(
MERROR,
"lazy_script_copy",
"Error reading output of the backup script, errno %d (%s)", errno,
1810 char *
q = strchr(p,
'\n');
1830 cm_msg(
MERROR,
"lazy_script_copy",
"pclose() returned %d, errno %d (%s)",
status, errno, strerror(errno));
1835 cm_msg(
MERROR,
"lazy_script_copy",
"Backup script finished with exit code %d, status 0x%x", (
status >> 8),
1840 cm_msg(
MINFO,
"lazy_script_copy",
"Backup script finished in %.1f sec with exit code %d",
1867 strcat(fullfile, dir);
1869 strcat(fullfile,
file);
1894 if (freepercent < 5.0) {
1898 str +=
"is almost full, free space: ";
1900 sprintf(buf,
"%.1f%%", freepercent);
1939 printf(
"file selected for removal %s [%s]\n", f.
filename.c_str(), path.c_str());
1943 cm_msg(
MERROR,
"Lazy",
"lazy_file_remove failed on file %s", path.c_str());
1989 BOOL watchdog_flag, exit_request =
FALSE;
1990 DWORD watchdog_timeout;
2000 assert(!
"NOT REACHED");
2051 memset(&
lazyst, 0, size);
2061 cm_msg(
MERROR,
"lazy_main",
"did not find /Lazy/Lazy_%s/Statistics for zapping", pLch->
name);
2069 cm_msg(
MINFO,
"Lazy",
"Please setup Data dir for input source path!");
2079 cm_msg(
MINFO,
"Lazy",
"Please setup backup device path too!");
2104 if (tobe_backup < 0)
2108 printf(
"selected for backup: %s, run %d\n", dirlist[tobe_backup].filename.c_str(), dirlist[tobe_backup].runno);
2112 size =
sizeof(cur_acq_run);
2118 int behind_files = dirlist.size() - tobe_backup;
2119 int behind_runs = cur_acq_run - dirlist[tobe_backup].runno;
2124 bool nothing_todo =
false;
2128 nothing_todo = nothing_todo_runs;
2132 nothing_todo = nothing_todo_files;
2136 if (dirlist[tobe_backup].runno != cur_acq_run)
2137 nothing_todo =
false;
2138 else if (behind_files > 1)
2139 nothing_todo =
false;
2141 nothing_todo =
false;
2150 size =
sizeof(flag);
2155 printf(
"transition in progress, cannot backup last file\n");
2156 nothing_todo =
true;
2159 size =
sizeof(flag);
2164 printf(
"run start aborted, cannot backup last file\n");
2165 nothing_todo =
true;
2173 printf(
"run still running, cannot backup last file\n");
2174 nothing_todo =
true;
2180 printf(
"behind: %d files, %d runs, staybehind: %d, nothing_todo: files: %d, runs: %d, lazylogger: %d\n",
2181 behind_files, behind_runs,
lazy.
staybehind, nothing_todo_files, nothing_todo_runs, nothing_todo);
2190 printf(
"haveTape: %d, nothing to do.\n", haveTape);
2197 xfile += dirlist[tobe_backup].filename;
2198 mstrlcpy(inffile, xfile.c_str(),
sizeof(inffile));
2224 if (strchr(
str,
'%'))
2227 strcpy(outffile,
str);
2230 mstrlcpy(
str, outffile,
sizeof(
str));
2231 if (strchr(
str,
'#')) {
2232 *strchr(
str,
'#') =
'%';
2244 eot_reached =
FALSE;
2251 cm_msg(
MINFO,
"Lazy",
"Not enough space for next copy on backup device!");
2257 sprintf(
str,
"Tape %s is full with %d files", pre_label,
lazyst.
nfiles);
2268 "Tape full, Please remove current tape and load new one!",
2281 cm_msg(
MINFO,
"Lazy",
"Exec post-rewind script:%s", cmd.c_str());
2285 cm_msg(
MINFO,
"Lazy",
"backup device rewinding...");
2311 printf(
"in loop stop detected\n");
2330 status = lazy_script_copy(inffile);
2332 assert(!
"lazy_script_copy not supported under Windows");
2337 status = lazy_sftp_copy(outffile, inffile);
2339 assert(!
"SFTP copying requires CURL to be installed! Install CURL, re-run cmake, and re-compile!");
2364 donelist.push_back(dirlist[tobe_backup]);
2380 exit_request =
TRUE;
2402 str +=
"_recover.odb";
2406 str +=
"_recover.odb";
2421 assert(
info != NULL);
2423 int size =
sizeof(
lazy);
2442 char channel_name[32];
2447 DWORD last_time_kb = 0;
2448 setbuf(stdout, NULL);
2449 setbuf(stderr, NULL);
2454 channel_name[0] = 0;
2463 for (
i = 1;
i < argc;
i++) {
2464 if (argv[
i][0] ==
'-' && argv[
i][1] ==
'd')
2466 else if (argv[
i][0] ==
'-' && argv[
i][1] ==
'n')
2468 else if (argv[
i][0] ==
'-' && argv[
i][1] ==
'D')
2470 else if (strncmp(argv[
i],
"-C", 2) == 0)
2472 else if (strncmp(argv[
i],
"-z", 2) == 0)
2474 else if (strncmp(argv[
i],
"-t", 2) == 0)
2476 else if (argv[
i][0] ==
'-') {
2477 if (
i + 1 >= argc || argv[
i + 1][0] ==
'-')
2479 if (strncmp(argv[
i],
"-e", 2) == 0)
2481 else if (strncmp(argv[
i],
"-h", 2) == 0)
2483 else if (strncmp(argv[
i],
"-c", 2) == 0)
2484 strcpy(channel_name, argv[++
i]);
2487 printf(
"Lazylogger: Multi channel background data copier\n");
2489 printf(
"Usage: lazylogger [-d] [-n] [-D] [-h <Hostname>] [-e <Experiment>] [-z] [-t] [-C] -c <channel name>\n");
2491 printf(
"Options:\n");
2492 printf(
" -c <channel name> - specify lazylogger channel name\n");
2493 printf(
" -C - convert old-format done list to new file-based format\n");
2494 printf(
" -d - enable debug printout\n");
2495 printf(
" -n - do not delete any files (for testing \"Maintain free space\")\n");
2496 printf(
" -D - start as a daemon\n");
2497 printf(
" -h - connect to experiment on another machine\n");
2498 printf(
" -e - connect to non-default experiment\n");
2499 printf(
" -z - clear /Lazy/channel/Statistics\n");
2500 printf(
" -t - permit lazy logger to TALK (see mlxspeaker)\n");
2502 printf(
"Quick man :\n");
2503 printf(
"The Lazy/Settings tree is composed of the following parameters:\n");
2504 printf(
"Maintain free space (%%)(0): purge source device to maintain free space on the source directory\n");
2505 printf(
" (0) : no purge \n");
2506 printf(
"Stay behind (0) : If negative number : lazylog runs starting from the OLDEST\n");
2507 printf(
" run file sitting in the 'Dir data' to the current acquisition\n");
2508 printf(
" run minus the 'Stay behind number'\n");
2509 printf(
" If positive number : lazylog starts from the current\n");
2510 printf(
" acquisition run minus 'Stay behind number' \n");
2511 printf(
" Zero : no stay-behind - files are saved as soon as they are closed\n");
2512 printf(
"Alarm Class : Specify the Class to be used in case of Tape Full condition\n");
2513 printf(
"Running condition : active/deactive lazylogger under given condition i.e:\n");
2514 printf(
" 'ALWAYS' (default) : Independent of the ACQ state ...\n");
2515 printf(
" 'NEVER' : ...\n");
2516 printf(
" 'WHILE_ACQ_NOT_RUNNING': ...\n");
2517 printf(
" '/alias/max_rate < 200' (max_rate is a link)\n");
2518 printf(
" '/equipment/scaler/variables/scal[4] < 23.45'\n");
2519 printf(
" '/equipment/trigger/statistics/events per sec. < 400'\n");
2520 printf(
"Data dir : MIDAS Data Directory (same as \"/Logger/Data Dir\")\n");
2521 printf(
"Data format : Data format (MIDAS)\n");
2522 printf(
"Filename format : Run format i.e. \"run%%05d.mid\", or \"*.mid.gz\" or \"*.mid.gz,*.xml\" \n");
2523 printf(
"List label : Label of destination save_set.\n");
2524 printf(
" Prevent lazylogger to run if not given.\n");
2525 printf(
" Will be reset if maximum capacity reached.\n");
2526 printf(
"Execute after rewind : Execute the command <cmd> after rewind complete\n");
2527 printf(
" : args passed are: 'device path' 'channel name' 'list label'\n");
2528 printf(
" : The actual command will look like: <cmd> /dev/nst0 Tape Data_2000\n");
2529 printf(
"Backup type : Destination device type (Disk, Tape, Script, SFTP, FTP)\n");
2530 printf(
"Path : Destination path (file.ext, /dev/nst0, ftp...)\n");
2531 printf(
" in case of SFTP type, the 'Path' entry should be:\n");
2532 printf(
" sftp://username@host/path\n");
2533 printf(
" in case of FTP type, the 'Path' entry should be:\n");
2534 printf(
" host, port, user, password, directory, run%%05d.mid\n");
2535 printf(
"Capacity (Bytes) : Maximum capacity of the destination device.\n");
2536 printf(
"modulo : Enable multiple lazy on same source. Ex: 3ch : 3.0, 3.1, 3.2\n");
2537 printf(
"tapeAppend : Enable positioning of the TAPE to EOD before each lazy copy\n");
2544 signal(SIGPIPE, SIG_IGN);
2547 printf(
"Becoming a daemon...\n");
2572 std::string strclient;
2573 strclient +=
"Lazy_";
2588 if (channel_name[0] != 0)
2602 if (channel_name[0] == 0) {
2604 printf(
" Available Lazy channels to connect to:\n");
2615 printf(
"Enter client number or new lazy client name: ");
2617 if ((
i == 0) && ((strlen(
str) == 0) || (strncmp(
str,
" ", 1) == 0))) {
2618 cm_msg(
MERROR,
"Lazy",
"Please specify a valid channel name (%s)",
str);
2639 " already running!",
2651 mstrlcpy(
str, channel_name,
sizeof(
str));
2662 std::string strclient;
2663 strclient +=
"Lazy_";
2727 cm_msg(
MERROR,
"Lazy",
"Cannot delete /Programs/Lazy");
2736 ftp_debug((
int (*)(
const char *)) puts, (
int (*)(
const char *)) puts);
2739 printf(
"Lazy_%s starting... "
2748 memset(&
lazyst, 0, size);
2761 cm_msg(
MERROR,
"Lazy",
"cannot open /runinfo/state record");
2785 size =
sizeof(
lazy);
2809 printf(
"Failed to start local RPC server");
2839 DWORD max_period = 30 * 60 * 1000;
2840 if (period > max_period)
2841 period = max_period;
2842 cm_msg(
MINFO,
"lazy",
"Will try again after %d seconds", period);
2857 if ((
char) ch ==
'!')
INT lModulo
Global var for testing passed at BOR.
void ftp_debug(int(*debug_func)(const char *message), int(*error_func)(const char *message))
INT al_reset_alarm(const char *alarm_name)
INT al_trigger_alarm(const char *alarm_name, const char *alarm_message, const char *default_class, const char *cond_str, INT type)
INT cm_register_transition(INT transition, INT(*func)(INT, char *), INT sequence_number)
INT cm_yield(INT millisec)
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
INT cm_get_watchdog_params(BOOL *call_watchdog, DWORD *timeout)
INT cm_connect_experiment1(const char *host_name, const char *default_exp_name, const char *client_name, void(*func)(char *), INT odb_size, DWORD watchdog_timeout)
INT cm_disconnect_experiment(void)
std::string cm_get_path()
INT cm_get_environment(char *host_name, int host_name_size, char *exp_name, int exp_name_size)
INT cm_set_watchdog_params(BOOL call_watchdog, DWORD timeout)
INT cm_exist(const char *name, BOOL bUnique)
INT md_file_wclose(INT handle, INT type, INT data_fmt, char *destination)
INT md_file_ropen(char *infile, INT data_fmt, INT openzip, INT max_event_size)
INT md_physrec_get(INT data_fmt, void **precord, DWORD *readn)
INT md_file_wopen(INT type, INT data_fmt, char *filename, INT *hDev)
INT md_log_write(INT handle, INT data_fmt, INT type, void *prec, DWORD nbytes)
INT md_file_rclose(INT data_fmt)
#define MAX_STRING_LENGTH
double ss_disk_size(const char *path)
INT ss_semaphore_create(const char *name, HNDLE *semaphore_handle)
INT ss_getchar(BOOL reset)
INT ss_tape_close(INT channel)
double ss_disk_free(const char *path)
INT ss_tape_get_blockn(INT channel)
double ss_file_size(const char *path)
INT ss_semaphore_release(HNDLE semaphore_handle)
INT ss_tape_spool(INT channel)
INT ss_file_remove(const char *path)
INT ss_daemon_init(BOOL keep_stdout)
INT ss_sleep(INT millisec)
INT ss_tape_unmount(INT channel)
INT ss_semaphore_wait_for(HNDLE semaphore_handle, DWORD timeout_millisec)
INT ss_tape_open(char *path, INT oflag, INT *channel)
char * ss_gets(char *string, int size)
INT ss_system(const char *command)
INT ss_file_find(const char *path, const char *pattern, char **plist)
INT cm_msg1(INT message_type, const char *filename, INT line, const char *facility, const char *routine, const char *format,...)
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
BOOL equal_ustring(const char *str1, const char *str2)
INT db_get_data_index(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT idx, DWORD type)
INT db_send_changed_records()
INT db_get_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, void *data, INT *buf_size, DWORD type, BOOL create)
INT db_open_record(HNDLE hDB, HNDLE hKey, void *ptr, INT rec_size, WORD access_mode, void(*dispatcher)(INT, INT, void *), void *info)
INT db_get_record1(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, INT align, const char *rec_str)
INT db_get_data(HNDLE hDB, HNDLE hKey, void *data, INT *buf_size, DWORD type)
INT db_set_mode(HNDLE hDB, HNDLE hKey, WORD mode, BOOL recurse)
INT db_save(HNDLE hDB, HNDLE hKey, const char *filename, BOOL bRemote)
INT db_get_key(HNDLE hDB, HNDLE hKey, KEY *key)
INT db_watch(HNDLE hDB, HNDLE hKey, void(*dispatcher)(INT, INT, INT, void *), void *info)
INT db_delete(HNDLE hDB, HNDLE hKeyRoot, const char *odb_path)
INT db_sprintf(char *string, const void *data, INT data_size, INT idx, DWORD type)
INT db_set_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, const void *data, INT data_size, INT num_values, DWORD type)
INT db_find_key(HNDLE hDB, HNDLE hKey, const char *key_name, HNDLE *subhKey)
INT db_rename_key(HNDLE hDB, HNDLE hKey, const char *name)
INT db_open_record1(HNDLE hDB, HNDLE hKey, void *ptr, INT rec_size, WORD access_mode, void(*dispatcher)(INT, INT, void *), void *info, const char *rec_str)
INT db_set_record(HNDLE hDB, HNDLE hKey, void *data, INT buf_size, INT align)
INT db_enum_key(HNDLE hDB, HNDLE hKey, INT idx, HNDLE *subkey_handle)
INT db_create_record(HNDLE hDB, HNDLE hKey, const char *orig_key_name, const char *init_str)
static std::string q(const char *s)
int lazy_disk_copy_loop(const char *outfile, const char *infile, FILE *fpout, FILE *fpin)
INT lazy_run_extract(const char *name)
BOOL lazy_condition_check(void)
INT lazy_log_update(INT action, INT run, const char *label, const char *file, DWORD perf_time)
void lazy_maintain_check(HNDLE hKey, LAZY_INFO *pLall)
INT lazy_copy(char *dev, char *file, int max_event_size)
int find_next_file(const DIRLOGLIST *plog, const DIRLOGLIST *pdone)
INT lazy_maintain_free_space(LAZY_INFO *pLch, LAZY_INFO *pLall)
void convert_done_list(HNDLE hLch)
INT build_log_list(const char *fmt, const char *dir, DIRLOGLIST *plog)
LAZY_INFO lazyinfo[MAX_LAZY_CHANNEL]
INT lazy_load_params(HNDLE hDB, HNDLE hKey)
#define LAZY_SETTINGS_STRING
INT lazy_disk_copy(const char *outfile, const char *infile)
void load_done_list(const char *lazyname, const DIRLOGLIST *dirlist, DIRLOGLIST *dlist)
void lazy_statistics_update(INT cploop_time)
char lazylog[MAX_STRING_LENGTH]
BOOL debug
debug printouts
BOOL lazy_file_exists(char *dir, char *file)
INT lazy_main(INT, LAZY_INFO *, int max_event_size)
std::vector< DIRLOG > DIRLOGLIST
#define LAZY_STATISTICS_STRING
INT lazy_file_remove(const char *pufile)
static void watch_settings(HNDLE hDB, HNDLE hKey, HNDLE index, void *info)
void lazy_settings_hotlink(HNDLE hDB, HNDLE hKey, void *info)
INT save_done_list(HNDLE hLch, DIRLOGLIST *pdone)
bool cmp_dirlog1(const DIRLOG &a, const DIRLOG &b)
bool cmp_dirlog(const DIRLOG &a, const DIRLOG &b)
void print_dirlog(const DIRLOGLIST *dirlog)
INT lazy_select_purge(HNDLE hKey, INT channel, LAZY_INFO *pLall, const char *fmt, const char *dir, DIRLOG *f)
BOOL condition_test(char *string)
INT build_done_list_odb(HNDLE, INT **)
std::string list_filename(const char *lazyname, const char *listname)
INT moduloCheck(INT lModulo, INT lPosition, INT lrun)
INT build_done_list(HNDLE hLch, const DIRLOGLIST *pdirlist, DIRLOGLIST *pdone)
INT lazy_trstop(INT rn, char *error)
int save_list(const char *lazyname, const char *listname, const DIRLOGLIST *dlist)
char host_name[HOST_NAME_LENGTH]
char expt_name[NAME_LENGTH]
#define DIR_SEPARATOR_STR
#define DEFAULT_MAX_EVENT_SIZE
static int left(const struct frozen *f)
char backfmt[MAX_FILE_PATH]
char backlabel[MAX_FILE_PATH]
char backfile[MAX_FILE_PATH]
static te_expr * list(state *s)