2004-11-20 07:32:32 +00:00
|
|
|
static volatile const char *BOINCrcsid="$Id$";
|
2003-07-01 20:37:09 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2003-01-29 23:03:19 +00:00
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
2003-07-01 20:37:09 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2003-08-15 00:45:25 +00:00
|
|
|
//
|
2003-01-29 23:03:19 +00:00
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
2003-08-15 00:45:25 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2003-01-29 23:03:19 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
2003-07-01 20:37:09 +00:00
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2003-08-15 00:45:25 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2003-01-29 23:03:19 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2003-01-30 23:03:52 +00:00
|
|
|
// db_dump: dump database views in XML format
|
|
|
|
//
|
2004-06-21 05:03:56 +00:00
|
|
|
// usage: [-d n] db_dump -dump_spec file
|
|
|
|
// -d debug level (1,2,3)
|
2003-01-30 23:03:52 +00:00
|
|
|
//
|
2004-06-21 05:03:56 +00:00
|
|
|
// dump_spec file:
|
|
|
|
// <boinc_db_dump_spec>
|
|
|
|
// <output_dir>x</output_dir>
|
|
|
|
// <final_output_dir>x</final_output_dir>
|
|
|
|
// <enumeration>
|
|
|
|
// <table>user</table>
|
|
|
|
// <filename>x</filename>
|
|
|
|
// <sort>x</sort> x = id, total_credit, expavg_credit
|
|
|
|
// <output>
|
|
|
|
// [<recs_per_file>n</recs_per_file>]
|
|
|
|
// [<detail/>]
|
|
|
|
// [<compression>x</compression> ] x = zip or gzip
|
|
|
|
// </output>
|
|
|
|
// ...
|
|
|
|
// </enumeration>
|
|
|
|
// ...
|
|
|
|
// </boinc_db_dump_spec>
|
2003-01-29 23:03:19 +00:00
|
|
|
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstdlib>
|
2003-01-30 23:03:52 +00:00
|
|
|
#include <unistd.h>
|
2004-06-21 05:03:56 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2003-11-25 23:34:00 +00:00
|
|
|
#include <string>
|
2004-06-21 05:03:56 +00:00
|
|
|
#include <vector>
|
2003-01-29 23:03:19 +00:00
|
|
|
|
2003-04-07 19:06:00 +00:00
|
|
|
#include "boinc_db.h"
|
2004-10-13 00:21:50 +00:00
|
|
|
#include "filesys.h"
|
2003-01-30 23:03:52 +00:00
|
|
|
#include "util.h"
|
2004-06-21 05:03:56 +00:00
|
|
|
#include "error_numbers.h"
|
2004-04-18 18:40:13 +00:00
|
|
|
#include "md5_file.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "parse.h"
|
|
|
|
|
2003-08-15 00:45:25 +00:00
|
|
|
#include "sched_config.h"
|
2003-03-08 00:09:40 +00:00
|
|
|
#include "sched_util.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "sched_msgs.h"
|
2003-01-29 23:03:19 +00:00
|
|
|
|
2004-06-30 18:17:21 +00:00
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
2003-02-10 19:51:32 +00:00
|
|
|
#define LOCKFILE "db_dump.out"
|
|
|
|
|
2004-06-21 05:03:56 +00:00
|
|
|
#define COMPRESSION_NONE 0
|
|
|
|
#define COMPRESSION_GZIP 1
|
|
|
|
#define COMPRESSION_ZIP 2
|
|
|
|
|
2004-08-24 00:15:14 +00:00
|
|
|
#define SORT_NONE 0
|
|
|
|
#define SORT_ID 1
|
|
|
|
#define SORT_TOTAL_CREDIT 2
|
|
|
|
#define SORT_EXPAVG_CREDIT 3
|
2004-06-21 05:03:56 +00:00
|
|
|
|
|
|
|
#define TABLE_USER 0
|
|
|
|
#define TABLE_TEAM 1
|
|
|
|
#define TABLE_HOST 2
|
|
|
|
|
|
|
|
// must match the above
|
|
|
|
char* table_name[3] = {"user", "team", "host"};
|
|
|
|
char* tag_name[3] = {"users", "teams", "hosts"};
|
|
|
|
|
|
|
|
struct OUTPUT {
|
|
|
|
int recs_per_file;
|
|
|
|
bool detail;
|
|
|
|
int compression;
|
|
|
|
class ZFILE* zfile;
|
|
|
|
class NUMBERED_ZFILE* nzfile;
|
|
|
|
int parse(FILE*);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ENUMERATION {
|
|
|
|
int table;
|
|
|
|
int sort;
|
|
|
|
char filename[256];
|
|
|
|
vector<OUTPUT> outputs;
|
|
|
|
int parse(FILE*);
|
|
|
|
int make_it_happen(char*);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DUMP_SPEC {
|
|
|
|
char output_dir[256];
|
|
|
|
char final_output_dir[256];
|
|
|
|
vector<ENUMERATION> enumerations;
|
|
|
|
int parse(FILE*);
|
|
|
|
};
|
2003-03-18 20:29:59 +00:00
|
|
|
|
2004-06-21 05:03:56 +00:00
|
|
|
int OUTPUT::parse(FILE* in) {
|
|
|
|
char buf[256], buf2[256];
|
|
|
|
|
|
|
|
recs_per_file = 0;
|
|
|
|
detail = false;
|
|
|
|
compression = COMPRESSION_NONE;
|
|
|
|
zfile = 0;
|
|
|
|
nzfile = 0;
|
|
|
|
while (fgets(buf, 256, in)) {
|
|
|
|
if (match_tag(buf, "</output>")) return 0;
|
|
|
|
if (parse_int(buf, "<recs_per_file>", recs_per_file)) continue;
|
|
|
|
if (match_tag(buf, "<detail/>")) {
|
|
|
|
detail = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (parse_str(buf, "<compression>", buf2, sizeof(buf2))) {
|
|
|
|
if (!strcmp(buf2, "gzip")) {
|
|
|
|
compression = COMPRESSION_GZIP;
|
|
|
|
} else if (!strcmp(buf2, "zip")) {
|
|
|
|
compression = COMPRESSION_ZIP;
|
|
|
|
} else {
|
2004-09-24 20:48:07 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
|
|
|
"unrecognized compression type: %s", buf
|
|
|
|
);
|
2004-06-21 05:03:56 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2004-09-24 20:48:07 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
|
|
|
"OUTPUT::parse: unrecognized: %s", buf
|
|
|
|
);
|
2004-06-21 05:03:56 +00:00
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ENUMERATION::parse(FILE* in) {
|
|
|
|
char buf[256], buf2[256];
|
|
|
|
int retval, i;
|
|
|
|
|
|
|
|
table = -1;
|
2004-08-24 00:15:14 +00:00
|
|
|
sort = SORT_NONE;
|
2004-06-21 05:03:56 +00:00
|
|
|
strcpy(filename, "");
|
|
|
|
while (fgets(buf, 256, in)) {
|
|
|
|
if (match_tag(buf, "</enumeration>")) {
|
|
|
|
if (table == -1) return ERR_XML_PARSE;
|
|
|
|
if (sort == -1) return ERR_XML_PARSE;
|
|
|
|
if (!strlen(filename)) return ERR_XML_PARSE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (match_tag(buf, "<output>")) {
|
|
|
|
OUTPUT output;
|
|
|
|
retval = output.parse(in);
|
|
|
|
if (!retval) outputs.push_back(output);
|
|
|
|
}
|
|
|
|
if (parse_str(buf, "<filename>", filename, sizeof(filename))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (parse_str(buf, "<table>", buf2, sizeof(buf2))) {
|
|
|
|
for (i=0; i<3; i++) {
|
|
|
|
if (!strcmp(buf2, table_name[i])) {
|
|
|
|
table = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (parse_str(buf, "<sort>", buf2, sizeof(buf2))) {
|
|
|
|
if (!strcmp(buf2, "id")) sort = SORT_ID;
|
|
|
|
if (!strcmp(buf2, "total_credit")) sort = SORT_TOTAL_CREDIT;
|
|
|
|
if (!strcmp(buf2, "expavg_credit")) sort = SORT_EXPAVG_CREDIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
2003-01-30 23:03:52 +00:00
|
|
|
|
2004-06-21 05:03:56 +00:00
|
|
|
int DUMP_SPEC::parse(FILE* in) {
|
|
|
|
char buf[256];
|
|
|
|
int retval;
|
2003-12-07 19:29:56 +00:00
|
|
|
|
2004-06-21 05:03:56 +00:00
|
|
|
while (fgets(buf, 256, in)) {
|
|
|
|
if (match_tag(buf, "</boinc_db_dump_spec>")) return 0;
|
|
|
|
if (match_tag(buf, "<enumeration>")) {
|
|
|
|
ENUMERATION e;
|
|
|
|
retval = e.parse(in);
|
|
|
|
if (!retval) enumerations.push_back(e);
|
|
|
|
}
|
|
|
|
if (parse_str(buf, "<output_dir", output_dir, sizeof(output_dir))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (parse_str(buf, "<final_output_dir", final_output_dir, sizeof(final_output_dir))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
2003-12-07 19:29:56 +00:00
|
|
|
}
|
2003-08-15 21:12:36 +00:00
|
|
|
|
|
|
|
// class that automatically compresses on close
|
2004-02-05 21:35:48 +00:00
|
|
|
//
|
2003-08-15 21:12:36 +00:00
|
|
|
class ZFILE {
|
|
|
|
protected:
|
2003-12-07 19:29:56 +00:00
|
|
|
string tag; // enclosing XML tag
|
2004-06-21 05:03:56 +00:00
|
|
|
char current_path[256];
|
|
|
|
int compression;
|
2003-08-15 21:12:36 +00:00
|
|
|
public:
|
2004-06-21 05:03:56 +00:00
|
|
|
FILE* f;
|
2004-07-15 18:54:17 +00:00
|
|
|
ZFILE(string tag_, int comp): tag(tag_), compression(comp), f(0) {}
|
2003-08-15 21:12:36 +00:00
|
|
|
~ZFILE() { close(); }
|
|
|
|
|
2004-06-21 05:03:56 +00:00
|
|
|
void open(const char* filename) {
|
2003-08-15 21:12:36 +00:00
|
|
|
close();
|
|
|
|
|
2004-06-21 05:03:56 +00:00
|
|
|
f = fopen(filename, "w");
|
2003-08-15 21:12:36 +00:00
|
|
|
if (!f) {
|
2004-09-24 20:48:07 +00:00
|
|
|
log_messages.printf(
|
|
|
|
SCHED_MSG_LOG::CRITICAL,
|
|
|
|
"Couldn't open %s for output\n", filename
|
|
|
|
);
|
2003-08-15 21:12:36 +00:00
|
|
|
}
|
2003-10-24 22:18:14 +00:00
|
|
|
fprintf(f,
|
2004-05-05 00:50:33 +00:00
|
|
|
"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n<%s>\n", tag.c_str()
|
2003-10-24 22:18:14 +00:00
|
|
|
);
|
2004-06-21 05:03:56 +00:00
|
|
|
strcpy(current_path, filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void open_num(const char* filename, int filenum) {
|
|
|
|
char buf[256];
|
|
|
|
sprintf(buf, "%s_%d", filename, filenum);
|
|
|
|
open(buf);
|
2003-08-15 21:12:36 +00:00
|
|
|
}
|
2004-06-21 05:03:56 +00:00
|
|
|
|
2003-10-24 22:18:14 +00:00
|
|
|
void close() {
|
2004-06-21 05:03:56 +00:00
|
|
|
char buf[256];
|
2003-08-15 21:12:36 +00:00
|
|
|
if (f) {
|
2003-10-24 22:18:14 +00:00
|
|
|
fprintf(f, "</%s>\n", tag.c_str());
|
2003-08-15 21:12:36 +00:00
|
|
|
fclose(f);
|
2004-06-21 05:03:56 +00:00
|
|
|
switch(compression) {
|
|
|
|
case COMPRESSION_ZIP:
|
|
|
|
sprintf(buf, "zip -q %s", current_path);
|
|
|
|
system(buf);
|
|
|
|
break;
|
|
|
|
case COMPRESSION_GZIP:
|
|
|
|
sprintf(buf, "gzip -fq %s", current_path);
|
|
|
|
system(buf);
|
|
|
|
break;
|
2003-08-15 21:12:36 +00:00
|
|
|
}
|
|
|
|
f = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-02-05 21:35:48 +00:00
|
|
|
// class that automatically opens a new file every N IDs
|
|
|
|
//
|
2003-08-15 21:12:36 +00:00
|
|
|
class NUMBERED_ZFILE : public ZFILE {
|
2004-06-21 05:03:56 +00:00
|
|
|
const char* filename_base;
|
2004-02-05 21:35:48 +00:00
|
|
|
int nids_per_file;
|
|
|
|
int last_filenum;
|
2003-08-15 21:12:36 +00:00
|
|
|
public:
|
2004-06-21 05:03:56 +00:00
|
|
|
NUMBERED_ZFILE(string tag_, int comp, const char* fb, int nids_per_file_)
|
|
|
|
: ZFILE(tag_, comp),
|
|
|
|
filename_base(fb),
|
|
|
|
nids_per_file(nids_per_file_),
|
|
|
|
last_filenum(-1)
|
|
|
|
{}
|
2003-08-15 21:12:36 +00:00
|
|
|
|
2004-02-05 21:35:48 +00:00
|
|
|
void set_id(int);
|
|
|
|
|
2003-08-15 21:12:36 +00:00
|
|
|
};
|
2003-02-26 21:54:34 +00:00
|
|
|
|
2004-02-05 21:35:48 +00:00
|
|
|
void NUMBERED_ZFILE::set_id(int id) {
|
|
|
|
int filenum = id/nids_per_file;
|
|
|
|
if (!f || (filenum != last_filenum)) {
|
2004-06-21 05:03:56 +00:00
|
|
|
open_num(filename_base, filenum);
|
2004-02-05 21:35:48 +00:00
|
|
|
last_filenum = filenum;
|
|
|
|
}
|
|
|
|
}
|
2004-06-21 23:37:06 +00:00
|
|
|
void write_host(HOST& host, FILE* f, bool detail) {
|
2004-07-15 18:54:17 +00:00
|
|
|
int retval;
|
|
|
|
|
2003-01-30 23:03:52 +00:00
|
|
|
fprintf(f,
|
|
|
|
"<host>\n"
|
2003-02-06 00:24:30 +00:00
|
|
|
" <id>%d</id>\n",
|
|
|
|
host.id
|
|
|
|
);
|
2004-06-21 23:37:06 +00:00
|
|
|
if (detail) {
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_USER user;
|
2004-07-15 18:54:17 +00:00
|
|
|
retval = user.lookup_id(host.userid);
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "user lookup: %d\n", retval);
|
|
|
|
exit(1);
|
|
|
|
}
|
2003-03-20 02:05:25 +00:00
|
|
|
if (user.show_hosts) {
|
|
|
|
fprintf(f,
|
|
|
|
" <userid>%d</userid>\n",
|
|
|
|
host.userid
|
|
|
|
);
|
|
|
|
}
|
2003-02-06 00:24:30 +00:00
|
|
|
}
|
|
|
|
fprintf(f,
|
2003-01-30 23:03:52 +00:00
|
|
|
" <total_credit>%f</total_credit>\n"
|
|
|
|
" <expavg_credit>%f</expavg_credit>\n"
|
2004-06-21 05:03:56 +00:00
|
|
|
" <expavg_time>%f</expavg_time>\n"
|
2003-01-30 23:03:52 +00:00
|
|
|
" <p_vendor>%s</p_vendor>\n"
|
|
|
|
" <p_model>%s</p_model>\n"
|
|
|
|
" <os_name>%s</os_name>\n"
|
|
|
|
" <os_version>%s</os_version>\n",
|
|
|
|
host.total_credit,
|
|
|
|
host.expavg_credit,
|
2004-06-21 05:03:56 +00:00
|
|
|
host.expavg_time,
|
2003-01-30 23:03:52 +00:00
|
|
|
host.p_vendor,
|
|
|
|
host.p_model,
|
|
|
|
host.os_name,
|
|
|
|
host.os_version
|
|
|
|
);
|
|
|
|
if (detail) {
|
|
|
|
fprintf(f,
|
|
|
|
" <create_time>%d</create_time>\n"
|
2003-11-25 15:51:19 +00:00
|
|
|
" <rpc_time>%d</rpc_time>\n"
|
2003-01-30 23:03:52 +00:00
|
|
|
" <timezone>%d</timezone>\n"
|
|
|
|
" <ncpus>%d</ncpus>\n"
|
|
|
|
" <p_fpops>%f</p_fpops>\n"
|
|
|
|
" <p_iops>%f</p_iops>\n"
|
|
|
|
" <p_membw>%f</p_membw>\n"
|
|
|
|
" <m_nbytes>%f</m_nbytes>\n"
|
|
|
|
" <m_cache>%f</m_cache>\n"
|
|
|
|
" <m_swap>%f</m_swap>\n"
|
|
|
|
" <d_total>%f</d_total>\n"
|
|
|
|
" <d_free>%f</d_free>\n"
|
|
|
|
" <n_bwup>%f</n_bwup>\n"
|
|
|
|
" <n_bwdown>%f</n_bwdown>\n",
|
|
|
|
host.create_time,
|
2003-11-25 15:51:19 +00:00
|
|
|
host.rpc_time,
|
2003-01-30 23:03:52 +00:00
|
|
|
host.timezone,
|
|
|
|
host.p_ncpus,
|
|
|
|
host.p_fpops,
|
|
|
|
host.p_iops,
|
|
|
|
host.p_membw,
|
|
|
|
host.m_nbytes,
|
|
|
|
host.m_cache,
|
|
|
|
host.m_swap,
|
|
|
|
host.d_total,
|
|
|
|
host.d_free,
|
|
|
|
host.n_bwup,
|
|
|
|
host.n_bwdown
|
|
|
|
);
|
|
|
|
}
|
2003-01-29 23:03:19 +00:00
|
|
|
fprintf(f,
|
2003-01-30 23:03:52 +00:00
|
|
|
"</host>\n"
|
2003-01-29 23:03:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2004-06-21 05:03:56 +00:00
|
|
|
void write_user(USER& user, FILE* f, bool detail) {
|
2004-04-18 18:40:13 +00:00
|
|
|
char buf[1024];
|
|
|
|
char cpid[MD5_LEN];
|
2003-06-04 17:21:26 +00:00
|
|
|
|
2003-11-25 23:34:00 +00:00
|
|
|
string name, url;
|
|
|
|
xml_escape(user.name, name);
|
|
|
|
xml_escape(user.url, url);
|
|
|
|
|
2004-04-18 18:40:13 +00:00
|
|
|
strcpy(buf, user.cross_project_id);
|
|
|
|
strcat(buf, user.email_addr);
|
|
|
|
md5_block((unsigned char*)buf, strlen(buf), cpid);
|
|
|
|
|
2003-01-30 23:03:52 +00:00
|
|
|
fprintf(f,
|
|
|
|
"<user>\n"
|
|
|
|
" <id>%d</id>\n"
|
|
|
|
" <name>%s</name>\n"
|
2003-06-18 20:52:17 +00:00
|
|
|
" <country>%s</country>\n"
|
|
|
|
" <create_time>%d</create_time>\n"
|
2003-01-30 23:03:52 +00:00
|
|
|
" <total_credit>%f</total_credit>\n"
|
2004-04-18 18:40:13 +00:00
|
|
|
" <expavg_credit>%f</expavg_credit>\n"
|
2004-06-21 05:03:56 +00:00
|
|
|
" <expavg_time>%f</expavg_time>\n"
|
2004-04-18 18:40:13 +00:00
|
|
|
" <cpid>%s</cpid>\n",
|
2003-01-30 23:03:52 +00:00
|
|
|
user.id,
|
2003-11-25 23:34:00 +00:00
|
|
|
name.c_str(),
|
2003-06-18 20:52:17 +00:00
|
|
|
user.country,
|
|
|
|
user.create_time,
|
2003-01-30 23:03:52 +00:00
|
|
|
user.total_credit,
|
2004-04-18 18:40:13 +00:00
|
|
|
user.expavg_credit,
|
2004-06-21 05:03:56 +00:00
|
|
|
user.expavg_time,
|
2004-04-18 18:40:13 +00:00
|
|
|
cpid
|
2003-01-30 23:03:52 +00:00
|
|
|
);
|
2004-06-21 05:03:56 +00:00
|
|
|
if (strlen(user.url)) {
|
|
|
|
fprintf(f,
|
|
|
|
" <url>%s</url>\n",
|
|
|
|
url.c_str()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (user.teamid) {
|
2003-02-06 00:24:30 +00:00
|
|
|
fprintf(f,
|
|
|
|
" <teamid>%d</teamid>\n",
|
|
|
|
user.teamid
|
|
|
|
);
|
|
|
|
}
|
2003-12-15 02:31:29 +00:00
|
|
|
if (user.has_profile) {
|
|
|
|
fprintf(f,
|
|
|
|
" <has_profile/>\n"
|
|
|
|
);
|
|
|
|
}
|
2004-09-24 20:48:07 +00:00
|
|
|
#if 0
|
2003-03-20 02:05:25 +00:00
|
|
|
if (detail && user.show_hosts) {
|
2004-09-27 04:26:51 +00:00
|
|
|
DB_HOST host;
|
2003-06-04 17:21:26 +00:00
|
|
|
sprintf(buf, "where userid=%d", user.id);
|
|
|
|
while (!host.enumerate(buf)) {
|
2004-02-05 21:35:48 +00:00
|
|
|
if (host.total_credit > 0) {
|
2004-06-21 23:37:06 +00:00
|
|
|
write_host(host, f, false);
|
2004-02-05 21:35:48 +00:00
|
|
|
}
|
2003-01-30 23:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-24 20:48:07 +00:00
|
|
|
#endif
|
2003-01-30 23:03:52 +00:00
|
|
|
fprintf(f,
|
|
|
|
"</user>\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_team(TEAM& team, FILE* f, bool detail) {
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_USER user;
|
2003-12-07 18:58:08 +00:00
|
|
|
char buf[256];
|
2003-11-25 23:34:00 +00:00
|
|
|
string name;
|
2004-07-15 18:54:17 +00:00
|
|
|
string url, name_html, description;
|
|
|
|
|
2003-11-25 23:34:00 +00:00
|
|
|
xml_escape(team.name, name);
|
|
|
|
|
2003-01-30 23:03:52 +00:00
|
|
|
fprintf(f,
|
|
|
|
"<team>\n"
|
|
|
|
" <id>%d</id>\n"
|
|
|
|
" <name>%s</name>\n"
|
2004-08-12 15:06:35 +00:00
|
|
|
" <userid>%d</userid>\n"
|
2003-01-30 23:03:52 +00:00
|
|
|
" <total_credit>%f</total_credit>\n"
|
|
|
|
" <expavg_credit>%f</expavg_credit>\n"
|
2004-06-21 05:03:56 +00:00
|
|
|
" <expavg_time>%f</expavg_time>\n"
|
2003-01-30 23:03:52 +00:00
|
|
|
" <nusers>%d</nusers>\n",
|
|
|
|
team.id,
|
2003-11-25 23:34:00 +00:00
|
|
|
name.c_str(),
|
2004-08-12 15:06:35 +00:00
|
|
|
team.userid,
|
2003-01-30 23:03:52 +00:00
|
|
|
team.total_credit,
|
|
|
|
team.expavg_credit,
|
2004-06-21 05:03:56 +00:00
|
|
|
team.expavg_time,
|
2003-01-30 23:03:52 +00:00
|
|
|
team.nusers
|
|
|
|
);
|
2003-11-25 23:34:00 +00:00
|
|
|
|
2004-07-15 18:54:17 +00:00
|
|
|
fprintf(f,
|
|
|
|
" <create_time>%d</create_time>\n",
|
|
|
|
team.create_time
|
|
|
|
);
|
|
|
|
if (strlen(team.url)) {
|
|
|
|
xml_escape(team.url, url);
|
2003-01-30 23:03:52 +00:00
|
|
|
fprintf(f,
|
2004-07-15 18:54:17 +00:00
|
|
|
" <url>%s</url>\n",
|
|
|
|
url.c_str()
|
2003-01-30 23:03:52 +00:00
|
|
|
);
|
2004-07-15 18:54:17 +00:00
|
|
|
}
|
|
|
|
if (strlen(team.name_html)) {
|
|
|
|
xml_escape(team.name_html, name_html);
|
2003-01-30 23:03:52 +00:00
|
|
|
fprintf(f,
|
2004-07-15 18:54:17 +00:00
|
|
|
"<name_html>%s</name_html>\n",
|
|
|
|
name_html.c_str()
|
2003-01-30 23:03:52 +00:00
|
|
|
);
|
2004-07-15 18:54:17 +00:00
|
|
|
}
|
|
|
|
if (strlen(team.description)) {
|
|
|
|
xml_escape(team.description, description);
|
|
|
|
fprintf(f,
|
|
|
|
"<description>%s</description>\n",
|
|
|
|
description.c_str()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
fprintf(f,
|
|
|
|
" <country>%s</country>\n",
|
|
|
|
team.country
|
|
|
|
);
|
|
|
|
if (detail) {
|
2003-06-04 17:21:26 +00:00
|
|
|
sprintf(buf, "where teamid=%d", team.id);
|
|
|
|
while (!user.enumerate(buf)) {
|
2004-06-21 05:03:56 +00:00
|
|
|
write_user(user, f, false);
|
2003-01-30 23:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(f,
|
|
|
|
"</team>\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2004-06-21 05:03:56 +00:00
|
|
|
void core_versions(char* dir) {
|
|
|
|
char buf[256];
|
2003-01-31 07:19:20 +00:00
|
|
|
|
2004-06-21 05:03:56 +00:00
|
|
|
sprintf(buf, "%s/core_versions.xml", dir);
|
2003-10-24 22:18:14 +00:00
|
|
|
ZFILE f("core_versions", false);
|
2004-06-21 05:03:56 +00:00
|
|
|
f.open(buf);
|
2003-08-15 21:12:36 +00:00
|
|
|
|
|
|
|
DB_PLATFORM platform;
|
|
|
|
while (!platform.enumerate("order by name")) {
|
|
|
|
DB_CORE_VERSION core_version;
|
|
|
|
char query_buf[256];
|
2003-08-15 21:20:49 +00:00
|
|
|
sprintf(query_buf, "where platformid=%d order by version_num desc", platform.id);
|
2003-08-15 21:12:36 +00:00
|
|
|
if (!core_version.enumerate(query_buf)) {
|
2003-08-15 21:20:49 +00:00
|
|
|
char url[256] = "";
|
|
|
|
parse_str(core_version.xml_doc, "<url>", url, sizeof(url));
|
|
|
|
|
2004-06-21 05:03:56 +00:00
|
|
|
fprintf(f.f,
|
2003-10-24 22:18:14 +00:00
|
|
|
" <core_version>\n"
|
|
|
|
" <id>%d</id>\n"
|
|
|
|
" <platform id=\"%d\" name=\"%s\">%s</platform>\n"
|
|
|
|
" <version>%d</version>\n"
|
|
|
|
" <create_time>%d</create_time>\n"
|
|
|
|
" <url>%s</url>\n"
|
|
|
|
" </core_version>\n",
|
|
|
|
core_version.id,
|
|
|
|
platform.id, platform.name, platform.user_friendly_name,
|
|
|
|
core_version.version_num,
|
|
|
|
core_version.create_time,
|
|
|
|
url
|
|
|
|
);
|
2003-08-15 21:12:36 +00:00
|
|
|
}
|
2003-01-31 07:19:20 +00:00
|
|
|
}
|
2003-10-24 22:18:14 +00:00
|
|
|
f.close();
|
2003-01-30 23:03:52 +00:00
|
|
|
}
|
|
|
|
|
2003-12-03 17:48:12 +00:00
|
|
|
int print_app(FILE* f, APP& app) {
|
|
|
|
|
|
|
|
fprintf(f, " <application>\n");
|
2003-12-11 19:05:52 +00:00
|
|
|
fprintf(f, " <name>%s</name>\n", app.user_friendly_name);
|
2003-12-03 17:48:12 +00:00
|
|
|
|
2004-06-30 18:53:35 +00:00
|
|
|
#if 0
|
2004-08-12 13:02:25 +00:00
|
|
|
DB_RESULT result;
|
|
|
|
char buf[256];
|
|
|
|
int n, retval;
|
2004-06-30 18:53:35 +00:00
|
|
|
// can't do this stuff because MySQL/InnoDB can't do counts efficiently
|
|
|
|
//
|
2003-12-03 17:48:12 +00:00
|
|
|
sprintf(buf, "where appid=%d and server_state=%d", app.id, RESULT_SERVER_STATE_UNSENT);
|
|
|
|
retval = result.count(n, buf);
|
2004-06-11 18:50:15 +00:00
|
|
|
if (!retval) {
|
|
|
|
fprintf(f, " <results_unsent>%d</results_unsent>\n", n);
|
|
|
|
}
|
2003-12-03 17:48:12 +00:00
|
|
|
|
|
|
|
sprintf(buf, "where appid=%d and server_state=%d", app.id, RESULT_SERVER_STATE_IN_PROGRESS);
|
|
|
|
retval = result.count(n, buf);
|
2004-06-11 18:50:15 +00:00
|
|
|
if (!retval) {
|
|
|
|
fprintf(f, " <results_in_progress>%d</results_in_progress>\n", n);
|
|
|
|
}
|
2003-12-03 17:48:12 +00:00
|
|
|
|
|
|
|
sprintf(buf, "where appid=%d and server_state=%d", app.id, RESULT_SERVER_STATE_OVER);
|
|
|
|
retval = result.count(n, buf);
|
2004-06-11 18:50:15 +00:00
|
|
|
if (!retval) {
|
|
|
|
fprintf(f, " <results_over>%d</results_over>\n", n);
|
|
|
|
}
|
2004-06-30 18:53:35 +00:00
|
|
|
#endif
|
2004-07-13 13:54:09 +00:00
|
|
|
|
2003-12-03 23:29:22 +00:00
|
|
|
fprintf(f, " </application>\n");
|
2003-12-03 17:48:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int print_apps(FILE* f) {
|
|
|
|
DB_APP app;
|
|
|
|
fprintf(f, " <applications>\n");
|
|
|
|
while (!app.enumerate()) {
|
|
|
|
print_app(f, app);
|
|
|
|
}
|
|
|
|
fprintf(f, " </applications>\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-06-21 05:03:56 +00:00
|
|
|
int tables_file(char* dir) {
|
|
|
|
char buf[256];
|
|
|
|
|
2003-10-24 22:18:14 +00:00
|
|
|
ZFILE f("tables", false);
|
2004-06-21 05:03:56 +00:00
|
|
|
sprintf(buf, "%s/tables.xml", dir);
|
|
|
|
f.open(buf);
|
2004-06-30 18:53:35 +00:00
|
|
|
fprintf(f.f,
|
|
|
|
" <update_time>%d</update_time>\n",
|
|
|
|
(int)time(0)
|
|
|
|
);
|
|
|
|
#if 0
|
2004-08-12 13:02:25 +00:00
|
|
|
DB_USER user;
|
|
|
|
DB_TEAM team;
|
|
|
|
DB_HOST host;
|
|
|
|
int nusers, nteams, nhosts;
|
|
|
|
int retval;
|
2004-06-30 18:53:35 +00:00
|
|
|
// can't do counts in MySQL/InnoDB
|
2003-06-04 17:21:26 +00:00
|
|
|
retval = user.count(nusers);
|
2003-01-30 23:03:52 +00:00
|
|
|
if (retval) return retval;
|
2003-06-04 17:21:26 +00:00
|
|
|
retval = team.count(nteams);
|
2003-01-30 23:03:52 +00:00
|
|
|
if (retval) return retval;
|
2003-06-04 17:21:26 +00:00
|
|
|
retval = host.count(nhosts);
|
2003-01-30 23:03:52 +00:00
|
|
|
if (retval) return retval;
|
2004-06-21 05:03:56 +00:00
|
|
|
fprintf(f.f,
|
2003-01-30 23:03:52 +00:00
|
|
|
" <nusers_total>%d</nusers_total>\n"
|
|
|
|
" <nteams_total>%d</nteams_total>\n"
|
2004-06-21 05:03:56 +00:00
|
|
|
" <nhosts_total>%d</nhosts_total>\n",
|
2003-01-30 23:03:52 +00:00
|
|
|
nusers,
|
|
|
|
nteams,
|
2004-06-21 05:03:56 +00:00
|
|
|
nhosts
|
2003-01-30 23:03:52 +00:00
|
|
|
);
|
2004-06-30 18:53:35 +00:00
|
|
|
#endif
|
2004-06-21 05:03:56 +00:00
|
|
|
print_apps(f.f);
|
2003-10-24 22:18:14 +00:00
|
|
|
f.close();
|
2003-01-30 23:03:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-06-21 05:03:56 +00:00
|
|
|
int ENUMERATION::make_it_happen(char* output_dir) {
|
|
|
|
unsigned int i;
|
|
|
|
int n;
|
|
|
|
DB_USER user;
|
|
|
|
DB_TEAM team;
|
|
|
|
DB_HOST host;
|
|
|
|
char clause[256];
|
|
|
|
char path[256];
|
|
|
|
|
|
|
|
sprintf(path, "%s/%s", output_dir, filename);
|
|
|
|
|
|
|
|
for (i=0; i<outputs.size(); i++) {
|
|
|
|
OUTPUT& out = outputs[i];
|
|
|
|
if (out.recs_per_file) {
|
|
|
|
out.nzfile = new NUMBERED_ZFILE(
|
|
|
|
tag_name[table], out.compression, path, out.recs_per_file
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
out.zfile = new ZFILE(tag_name[table], out.compression);
|
|
|
|
out.zfile->open(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch(sort) {
|
2004-08-24 00:15:14 +00:00
|
|
|
case SORT_NONE:
|
|
|
|
strcpy(clause, "where total_credit > 0");
|
|
|
|
break;
|
2004-06-21 05:03:56 +00:00
|
|
|
case SORT_ID:
|
2004-07-15 18:54:17 +00:00
|
|
|
strcpy(clause, "where total_credit > 0 order by id");
|
2004-06-21 05:03:56 +00:00
|
|
|
break;
|
|
|
|
case SORT_TOTAL_CREDIT:
|
2004-07-15 18:54:17 +00:00
|
|
|
strcpy(clause, "where total_credit > 0 order by total_credit desc");
|
2004-06-21 05:03:56 +00:00
|
|
|
break;
|
|
|
|
case SORT_EXPAVG_CREDIT:
|
2004-07-15 18:54:17 +00:00
|
|
|
strcpy(clause, "where total_credit > 0 order by expavg_credit desc");
|
2004-06-21 05:03:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch(table) {
|
|
|
|
case TABLE_USER:
|
|
|
|
n = 0;
|
2004-09-24 20:48:07 +00:00
|
|
|
while (!user.enumerate(clause, true)) {
|
2004-06-21 05:03:56 +00:00
|
|
|
for (i=0; i<outputs.size(); i++) {
|
|
|
|
OUTPUT& out = outputs[i];
|
|
|
|
if (sort == SORT_ID && out.recs_per_file) {
|
|
|
|
out.nzfile->set_id(n++);
|
|
|
|
}
|
|
|
|
if (out.zfile) {
|
|
|
|
write_user(user, out.zfile->f, out.detail);
|
|
|
|
} else {
|
|
|
|
write_user(user, out.nzfile->f, out.detail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TABLE_HOST:
|
2004-06-21 23:37:06 +00:00
|
|
|
n = 0;
|
|
|
|
while(!host.enumerate(clause)) {
|
|
|
|
for (i=0; i<outputs.size(); i++) {
|
|
|
|
OUTPUT& out = outputs[i];
|
|
|
|
if (sort == SORT_ID && out.recs_per_file) {
|
|
|
|
out.nzfile->set_id(n++);
|
|
|
|
}
|
|
|
|
if (out.zfile) {
|
|
|
|
write_host(host, out.zfile->f, out.detail);
|
|
|
|
} else {
|
|
|
|
write_host(host, out.nzfile->f, out.detail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-06-21 05:03:56 +00:00
|
|
|
break;
|
|
|
|
case TABLE_TEAM:
|
2004-06-21 23:37:06 +00:00
|
|
|
n = 0;
|
|
|
|
while(!team.enumerate(clause)) {
|
|
|
|
for (i=0; i<outputs.size(); i++) {
|
|
|
|
OUTPUT& out = outputs[i];
|
|
|
|
if (sort == SORT_ID && out.recs_per_file) {
|
|
|
|
out.nzfile->set_id(n++);
|
|
|
|
}
|
|
|
|
if (out.zfile) {
|
|
|
|
write_team(team, out.zfile->f, out.detail);
|
|
|
|
} else {
|
|
|
|
write_team(team, out.nzfile->f, out.detail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-06-21 05:03:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (i=0; i<outputs.size(); i++) {
|
|
|
|
OUTPUT& out = outputs[i];
|
|
|
|
if (out.zfile) out.zfile->close();
|
|
|
|
if (out.nzfile) out.nzfile->close();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-01-30 23:03:52 +00:00
|
|
|
int main(int argc, char** argv) {
|
2003-09-02 21:16:55 +00:00
|
|
|
SCHED_CONFIG config;
|
2003-01-30 23:03:52 +00:00
|
|
|
int retval, i;
|
2004-06-21 05:03:56 +00:00
|
|
|
DUMP_SPEC spec;
|
2004-09-30 17:41:02 +00:00
|
|
|
char* db_host = 0;
|
2004-06-21 05:03:56 +00:00
|
|
|
char spec_filename[256], buf[256];
|
2003-01-30 23:03:52 +00:00
|
|
|
|
2004-05-03 19:30:01 +00:00
|
|
|
check_stop_daemons();
|
2004-06-21 05:03:56 +00:00
|
|
|
setbuf(stderr, 0);
|
2003-03-08 00:09:40 +00:00
|
|
|
|
2004-07-15 18:54:17 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::NORMAL, "db_dump starting\n");
|
2004-06-21 05:03:56 +00:00
|
|
|
strcpy(spec_filename, "");
|
2003-01-30 23:03:52 +00:00
|
|
|
for (i=1; i<argc; i++) {
|
2004-06-21 05:03:56 +00:00
|
|
|
if (!strcmp(argv[i], "-dump_spec")) {
|
|
|
|
strcpy(spec_filename, argv[++i]);
|
2004-10-01 23:46:22 +00:00
|
|
|
} else if (!strcmp(argv[i], "-d")) {
|
|
|
|
log_messages.set_debug_level(atoi(argv[++i]));
|
2004-09-30 17:41:02 +00:00
|
|
|
} else if (!strcmp(argv[i], "-db_host")) {
|
|
|
|
db_host = argv[++i];
|
|
|
|
} else {
|
2004-10-01 23:46:22 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "Usage: %s\n", argv[i]);
|
2004-09-30 17:41:02 +00:00
|
|
|
exit(1);
|
2003-01-30 23:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-10 19:51:32 +00:00
|
|
|
|
2004-06-21 05:03:56 +00:00
|
|
|
if (!strlen(spec_filename)) {
|
2004-09-30 17:41:02 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "no spec file given\n");
|
2004-06-21 05:03:56 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE* f = fopen(spec_filename, "r");
|
|
|
|
if (!f) {
|
2004-09-30 17:41:02 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "spec file missing\n");
|
2004-06-21 05:03:56 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = spec.parse(f);
|
|
|
|
if (retval) {
|
2004-09-30 17:41:02 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "can't parse spec file\n");
|
2003-03-18 20:29:59 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2004-06-21 05:03:56 +00:00
|
|
|
fclose(f);
|
|
|
|
|
2003-02-10 19:51:32 +00:00
|
|
|
if (lock_file(LOCKFILE)) {
|
2004-09-30 17:41:02 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "Another copy of db_dump is already running\n");
|
2003-02-10 19:51:32 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2004-04-08 08:15:23 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::NORMAL, "Starting\n");
|
2003-02-10 19:51:32 +00:00
|
|
|
|
2003-09-02 21:16:55 +00:00
|
|
|
retval = config.parse_file("..");
|
2003-01-29 23:03:19 +00:00
|
|
|
if (retval) {
|
2004-09-30 17:41:02 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "Can't parse config file\n");
|
2003-01-29 23:03:19 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2004-09-30 17:41:02 +00:00
|
|
|
retval = boinc_db.open(
|
|
|
|
config.db_name,
|
|
|
|
db_host?db_host:config.db_host,
|
|
|
|
config.db_user,
|
|
|
|
config.db_passwd
|
|
|
|
);
|
2003-01-29 23:03:19 +00:00
|
|
|
if (retval) {
|
2004-09-30 17:41:02 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::CRITICAL, "Can't open DB\n");
|
2003-01-29 23:03:19 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2003-01-30 23:03:52 +00:00
|
|
|
|
2004-06-21 05:03:56 +00:00
|
|
|
mkdir(spec.output_dir, 0777);
|
|
|
|
|
|
|
|
unsigned int j;
|
|
|
|
for (j=0; j<spec.enumerations.size(); j++) {
|
|
|
|
ENUMERATION& e = spec.enumerations[j];
|
|
|
|
e.make_it_happen(spec.output_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
tables_file(spec.output_dir);
|
|
|
|
core_versions(spec.output_dir);
|
|
|
|
|
|
|
|
sprintf(buf, "cp %s %s/db_dump.xml", spec_filename, spec.output_dir);
|
|
|
|
system(buf);
|
|
|
|
sprintf(buf, "/bin/rm -rf %s; mv %s %s",
|
|
|
|
spec.final_output_dir, spec.output_dir, spec.final_output_dir
|
|
|
|
);
|
|
|
|
system(buf);
|
2004-07-15 18:54:17 +00:00
|
|
|
log_messages.printf(SCHED_MSG_LOG::NORMAL, "db_dump finished\n");
|
2003-01-29 23:03:19 +00:00
|
|
|
}
|