48#define MAX_LAZY_CHANNEL 100
50#define LOG_TYPE_SCRIPT (-1)
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",
249 printf(
"lazy has detected a STOP transition\n");
298 printf(
"lazy_file_remove: running in nodelete mode (-n switch), will not remove \'%s\'\n",
pufile);
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);
441 std::vector<std::string>
flist;
460 for (
unsigned j = 0 ;
j <
flist.size();
j++) {
484 return dlist->size();
530 int first = (*pdo)[
i - 1];
531 int last = -(*pdo)[
i];
607 for (
unsigned i = 0;
i <
dirlist->size();
i++)
608 if ((*
dirlist)[
i].filename ==
d.filename) {
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();
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++)
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();
785 for (
unsigned j = 0;
j <
plog->size();
j++) {
787 for (
unsigned i = 0;
i <
pdone->size();
i++) {
793 if ((*
plog)[
j].size > 0)
861 if (
ddir[len - 1] !=
'/') {
869 printf(
"purge: skipping channel \'%s\' which uses different data dir \'%s\', we use \'%s\'\n",
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);
954 char dir[256],
ff[128];
998 "Maintain free space on channel %s has been disable", (
pLall +
i)->
name);
1181 DWORD watchdog_timeout;
1241 cm_msg(
MINFO,
"Lazy",
"Exec pre file write script:%s", cmd);
1288 cm_msg(
MINFO,
"Lazy",
"Abort postponed until end of copy of %s %1.0lf[%%]",
1343 const int kBufSize = 1 * 1024 * 1024;
1375 }
else if (
rd == 0) {
1416 printf(
"readfunc (CURL) size:%ld nmemb:%ld n:%li total:%f\n", size,
nmemb,
n,
lastsz);
1460#if LIBCURL_VERSION_NUM < 0x073700
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);
1533 DWORD watchdog_timeout;
1539 double MiB = 1024 * 1024;
1551 cm_msg(
MINFO,
"Lazy",
"Exec pre file write script:%s", cmd);
1608 cm_msg(
MINFO,
"lazy_disk_copy",
"Copy finished in %.1f sec, %.1f MiBytes at %.1f MiBytes/sec", t,
1630 DWORD watchdog_timeout;
1636 double MiB = 1024 * 1024;
1650 cm_msg(
MINFO,
"Lazy",
"Exec pre file write script:%s", cmd);
1664 cm_msg(
MINFO,
"Lazy_disk_copy",
"Output file \'%s\' already exists, removing",
outfile);
1719 cm_msg(
MINFO,
"lazy_disk_copy",
"Copy finished in %.1f sec, %.1f MiBytes at %.1f MiBytes/sec", t,
1752 cm_msg(
MINFO,
"Lazy",
"Exec pre file write script:%s", cmd);
1760 char str[100 + 256];
1761 sprintf(
str,
"Starting lazy job \'%s\'", cmd);
1788 }
else if (
rd < 0) {
1797 cm_msg(
MERROR,
"lazy_script_copy",
"Error reading output of the backup script, errno %d (%s)",
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",
1898 str +=
"is almost full, free space: ";
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());
1990 DWORD watchdog_timeout;
2000 assert(!
"NOT REACHED");
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!");
2150 size =
sizeof(
flag);
2155 printf(
"transition in progress, cannot backup last file\n");
2159 size =
sizeof(
flag);
2164 printf(
"run start aborted, cannot backup last file\n");
2173 printf(
"run still running, cannot backup last file\n");
2180 printf(
"behind: %d files, %d runs, staybehind: %d, nothing_todo: files: %d, runs: %d, lazylogger: %d\n",
2251 cm_msg(
MINFO,
"Lazy",
"Not enough space for next copy on backup device!");
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");
2332 assert(!
"lazy_script_copy not supported under Windows");
2339 assert(!
"SFTP copying requires CURL to be installed! Install CURL, re-run cmake, and re-compile!");
2402 str +=
"_recover.odb";
2406 str +=
"_recover.odb";
2423 int size =
sizeof(
lazy);
2466 else if (
argv[
i][0] ==
'-' &&
argv[
i][1] ==
'n')
2468 else if (
argv[
i][0] ==
'-' &&
argv[
i][1] ==
'D')
2476 else if (
argv[
i][0] ==
'-') {
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");
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");
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");
2547 printf(
"Becoming a daemon...\n");
2604 printf(
" Available Lazy channels to connect to:\n");
2615 printf(
"Enter client number or new lazy client name: ");
2618 cm_msg(
MERROR,
"Lazy",
"Please specify a valid channel name (%s)",
str);
2639 " already running!",
2731 cm_msg(
MERROR,
"Lazy",
"Cannot delete /Programs/Lazy");
2745 printf(
"Lazy_%s starting... "
2767 cm_msg(
MERROR,
"Lazy",
"cannot open /runinfo/state record");
2791 size =
sizeof(
lazy);
2815 printf(
"Failed to start local RPC server");
2848 cm_msg(
MINFO,
"lazy",
"Will try again after %d seconds", period);
2863 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_delete_key(HNDLE hDB, HNDLE hKey, BOOL follow_links)
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_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)
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
char backfmt[MAX_FILE_PATH]
char backlabel[MAX_FILE_PATH]
char backfile[MAX_FILE_PATH]
static te_expr * list(state *s)