103
108
char command[512];
111
time_t time_time = time_int;
113
strftime(dirname, sizeof(dirname), "%Y_%m_%d", gmtime(&time_time));
114
strcpy(path, config.project_path("archives/%s",dirname));
115
if (mkdir(path,0775)) {
118
sprintf(errstr, "could not create directory '%s': %s\n",
119
path, strerror(errno));
125
"archives/%s/%s_%d.xml", dirname, filename_prefix, time_int
130
config.project_path("archives/%s_%d.xml", filename_prefix, time_int)
105
133
// append appropriate suffix for file type
106
sprintf(path, "../archives/%s_%d.xml", filename_prefix, time_int);
107
134
strcat(path, suffix[compression_type]);
109
136
// and construct appropriate command if needed
119
146
"Opening archive %s\n", path
122
// in the case with no compression, just open the file, else open
123
// a pipe to the compression executable.
149
if (!(f = fopen(path,"w"))) {
151
sprintf(buf, "Can't open archive file %s %s\n",
152
path, errno?strerror(errno):""
125
156
if (compression_type == COMPRESSION_NONE) {
126
if (!(f = fopen( path,"w"))) {
157
// in the case with no compression, just open the file, else open
158
// a pipe to the compression executable.
162
f = popen(command,"w");
127
164
log_messages.printf(MSG_CRITICAL,
128
"Can't open archive file %s %s\n",
129
path, errno?strerror(errno):""
165
"Can't open pipe %s %s\n",
166
command, errno?strerror(errno):""
133
} else if (!(f = popen(command,"w"))) {
134
log_messages.printf(MSG_CRITICAL,
135
"Can't open pipe %s %s\n",
136
command, errno?strerror(errno):""
141
172
// set buffering to line buffered, since we are outputing XML on a
197
// reconstruct the filename
199
time_t time_time = time_int;
201
strftime(dirname, sizeof(dirname), "%Y_%m_%d", gmtime(&time_time));
204
"archives/%s/%s_%d.xml", dirname, filename, time_int
209
config.project_path("archives/%s_%d.xml", filename, time_int)
166
212
// append appropriate file type
167
sprintf(path, "../archives/%s_%d.xml", filename, time_int);
168
213
strcat(path, suffix[compression_type]);
170
215
log_messages.printf(MSG_NORMAL,
487
539
// purge workunit from DB
489
retval= wu.delete_from_db();
491
log_messages.printf(MSG_CRITICAL,
492
"Can't delete workunit [%d] from database:%d\n", wu.id, retval
542
retval= wu.delete_from_db();
544
log_messages.printf(MSG_CRITICAL,
545
"Can't delete workunit [%d] from database:%d\n",
496
551
log_messages.printf(MSG_DEBUG,
497
552
"Purged workunit [%d] from database\n", wu.id
543
void usage(char** argv) {
598
void usage(char* name) {
545
600
"Purge workunit and result records that are no longer needed.\n\n"
546
601
"Usage: %s [options]\n"
547
" [-d N] Set verbosity level (1, 2, 3=most verbose)\n"
548
" [-min_age_days N] Purge Wus w/ mod time at least N days ago\n"
549
" [-max N] Purge at more N WUs\n"
550
" [-zip] Compuress output files using zip\n"
551
" [-gzip] Compuress output files using gzip\n"
552
" [-no_archive] Don't write output files, just purge\n"
553
" [-max_wu_per_file N] Write at most N WUs per output file\n"
554
" [-sleep N] Sleep N sec after DB scan\n"
555
" [-one_pass] Make one DB scan, then exit\n",
602
" [-d N | --debug_level N] Set verbosity level (1 to 4)\n"
603
" [--min_age_days N] Purge Wus w/ mod time at least N days ago\n"
604
" [--max N] Purge at more N WUs\n"
605
" [--zip] Compuress output files using zip\n"
606
" [--gzip] uress output files using gzip\n"
607
" [--no_archive] Don't write output files, just purge\n"
608
" [--daily_dir] Write archives in a new directory each day\n"
609
" [--max_wu_per_file N] Write at most N WUs per output file\n"
610
" [--sleep N] Sleep N sec after DB scan\n"
611
" [--one_pass] Make one DB scan, then exit\n"
612
" [--dont_delete] Don't actually delete anything from the DB (for testing only)\n"
613
" [--h | --help] Show this help text\n"
614
" [--v | --version] Show version information\n",
561
619
int main(int argc, char** argv) {
566
624
check_stop_daemons();
568
626
for (i=1; i<argc; i++) {
569
if (!strcmp(argv[i], "-one_pass")) {
627
if (is_arg(argv[i], "one_pass")) {
571
} else if (!strcmp(argv[i], "-d")) {
572
log_messages.set_debug_level(atoi(argv[++i]));
573
} else if (!strcmp(argv[i], "-min_age_days")) {
574
min_age_days = atoi(argv[++i]);
575
} else if (!strcmp(argv[i], "-max")) {
576
max_number_workunits_to_purge= atoi(argv[++i]);
577
} else if (!strcmp(argv[i], "-zip")) {
629
} else if (is_arg(argv[i], "dont_delete")) {
631
} else if (is_arg(argv[i], "d") || is_arg(argv[i], "debug_level")) {
633
log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]);
637
int dl = atoi(argv[i]);
638
log_messages.set_debug_level(dl);
639
if (dl == 4) g_print_queries = true;
640
} else if (is_arg(argv[i], "min_age_days")) {
642
log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]);
646
min_age_days = atof(argv[i]);
647
} else if (is_arg(argv[i], "max")) {
649
log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]);
653
max_number_workunits_to_purge= atoi(argv[i]);
654
} else if (is_arg(argv[i], "daily_dir")) {
656
} else if (is_arg(argv[i], "zip")) {
578
657
compression_type=COMPRESSION_ZIP;
579
} else if (!strcmp(argv[i], "-gzip")) {
658
} else if (is_arg(argv[i], "gzip")) {
580
659
compression_type=COMPRESSION_GZIP;
581
} else if (!strcmp(argv[i], "-max_wu_per_file")) {
582
max_wu_per_file = atoi(argv[++i]);
583
} else if (!strcmp(argv[i], "-no_archive")) {
660
} else if (is_arg(argv[i], "max_wu_per_file")) {
662
log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]);
666
max_wu_per_file = atoi(argv[i]);
667
} else if (is_arg(argv[i], "no_archive")) {
584
668
no_archive = true;
585
} else if (!strcmp(argv[i], "-sleep")) {
586
sleep_sec = atoi(argv[++i]);
669
} else if (is_arg(argv[i], "-sleep")) {
671
log_messages.printf(MSG_CRITICAL, "%s requires an argument\n\n", argv[--i]);
675
sleep_sec = atoi(argv[i]);
587
676
if (sleep_sec < 1 || sleep_sec > 86400) {
588
677
log_messages.printf(MSG_CRITICAL,
589
678
"Unreasonable value of sleep interval: %d seconds\n",
594
} else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
684
} else if (is_arg(argv[i], "--help") || is_arg(argv[i], "-help") || is_arg(argv[i], "-h")) {
687
} else if (is_arg(argv[i], "--version") || is_arg(argv[i], "-version")) {
688
printf("%s\n", SVN_VERSION);
597
691
log_messages.printf(MSG_CRITICAL,
598
"Unrecognized arg: %s\n", argv[i]
692
"unknown command line argument: %s\n\n", argv[i]
604
retval = config.parse_file("..");
699
retval = config.parse_file();
606
701
log_messages.printf(MSG_CRITICAL,
607
"Can't parse config file\n"
702
"Can't parse config.xml: %s\n", boincerror(retval)