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
|
|
|
|
//
|
2003-03-18 20:29:59 +00:00
|
|
|
// usage: db_dump [-dir path] [-summary_recs num_recs_per_file]
|
|
|
|
// [-detail_recs num_recs_per_file] [-gzip] [-zip]
|
2003-01-29 23:03:19 +00:00
|
|
|
|
|
|
|
// files:
|
2003-01-30 23:03:52 +00:00
|
|
|
// NOTE: the goal is to make the full DB available (view *_id files)
|
|
|
|
// to those who want it,
|
|
|
|
// while allowing those who want to see only a particular row,
|
2003-09-26 20:00:56 +00:00
|
|
|
// or the highest-ranked rows, to get this info with a small download
|
2003-01-30 23:03:52 +00:00
|
|
|
//
|
2003-01-29 23:03:19 +00:00
|
|
|
//
|
2003-01-30 23:03:52 +00:00
|
|
|
// tables.xml
|
|
|
|
// for each table (team, user, host):
|
|
|
|
// total number of records
|
|
|
|
// number of records per file for summary files
|
|
|
|
// number of records per file for detailed files
|
|
|
|
// team_total_credit_N.xml
|
|
|
|
// list of teams by decreasing total credit (summary)
|
|
|
|
// team_expavg_credit_N.xml
|
|
|
|
// team_id_N.xml
|
|
|
|
// teams by ID (detailed, including list of user summaries)
|
|
|
|
// user_total_credit_N.xml
|
|
|
|
// list of users by total credit (summary)
|
|
|
|
// user_expavg_credit_N.xml
|
|
|
|
// user_id_N.xml
|
|
|
|
// users by ID (detailed, including list of host summaries)
|
|
|
|
// host_total_credit_N.xml
|
|
|
|
// hosts by decreasing total credit (summary)
|
|
|
|
// host_expavg_credit_N.xml
|
|
|
|
// host_id_N.xml
|
|
|
|
// hosts by ID (detailed)
|
|
|
|
|
|
|
|
// NOTE: for now we're using verbose XML tag names.
|
|
|
|
// We may change to short tag names to save bandwidth.
|
2003-01-29 23:03:19 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2003-01-31 07:19:20 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2003-01-30 23:03:52 +00:00
|
|
|
#include <unistd.h>
|
2003-01-29 23:03:19 +00:00
|
|
|
|
2003-04-07 19:06:00 +00:00
|
|
|
#include "boinc_db.h"
|
2003-01-30 23:03:52 +00:00
|
|
|
#include "util.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"
|
2003-08-15 21:20:49 +00:00
|
|
|
#include "parse.h"
|
2003-01-29 23:03:19 +00:00
|
|
|
|
2003-02-10 19:51:32 +00:00
|
|
|
#define LOCKFILE "db_dump.out"
|
|
|
|
|
2003-03-18 20:29:59 +00:00
|
|
|
#define DEFAULT_NRECS_PER_FILE_SUMMARY 1000
|
|
|
|
#define DEFAULT_NRECS_PER_FILE_DETAIL 100
|
|
|
|
|
|
|
|
int nrecs_per_file_summary;
|
|
|
|
int nrecs_per_file_detail;
|
2003-01-30 23:03:52 +00:00
|
|
|
|
2003-02-26 21:54:34 +00:00
|
|
|
bool zip_files = false;
|
2003-08-15 21:12:36 +00:00
|
|
|
string zip_cmd;
|
|
|
|
|
|
|
|
// class that automatically compresses on close
|
|
|
|
class ZFILE {
|
|
|
|
protected:
|
|
|
|
FILE* f;
|
|
|
|
string filename;
|
|
|
|
bool zip_file;
|
|
|
|
public:
|
|
|
|
ZFILE(bool zip_file_ = zip_files) : f(0), zip_file(zip_file_) {}
|
|
|
|
~ZFILE() { close(); }
|
|
|
|
|
|
|
|
operator FILE* () { return f; }
|
|
|
|
bool operator ! () { return !f; }
|
|
|
|
|
|
|
|
void open(const char* filename_format, ...)
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
va_list ap;
|
|
|
|
char filename_buf[256];
|
|
|
|
va_start(ap, filename_format);
|
|
|
|
vsprintf(filename_buf, filename_format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
filename = filename_buf;
|
|
|
|
|
|
|
|
f = fopen(filename.c_str(), "w");
|
|
|
|
if (!f) {
|
|
|
|
fprintf(stderr, "db_dump: Couldn't open %s for output\n", filename.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void close()
|
|
|
|
{
|
|
|
|
if (f) {
|
|
|
|
fclose(f);
|
|
|
|
if (zip_file) {
|
|
|
|
string cmd = zip_cmd + ' ' + filename;
|
|
|
|
system(cmd.c_str());
|
|
|
|
}
|
|
|
|
f = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// class that automatically opens a new file every N records
|
|
|
|
class NUMBERED_ZFILE : public ZFILE {
|
|
|
|
const char* filename_format;
|
|
|
|
int nrec_max;
|
|
|
|
int nfile, nrec;
|
|
|
|
public:
|
|
|
|
NUMBERED_ZFILE(const char* filename_format_, int nrec_max_)
|
|
|
|
: filename_format(filename_format_), nrec_max(nrec_max_), nfile(0), nrec(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NUMBERED_ZFILE& operator ++() {
|
|
|
|
if (!f || nrec >= nrec_max) {
|
|
|
|
open(filename_format, nfile);
|
|
|
|
++nfile;
|
|
|
|
nrec = 0;
|
|
|
|
}
|
|
|
|
++nrec;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
2003-02-26 21:54:34 +00:00
|
|
|
|
2003-02-06 00:24:30 +00:00
|
|
|
void write_host(HOST& host, FILE* f, bool detail, bool show_user) {
|
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
|
|
|
|
);
|
|
|
|
if (show_user) {
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_USER user;
|
|
|
|
user.lookup_id(host.userid);
|
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"
|
|
|
|
" <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,
|
|
|
|
host.p_vendor,
|
|
|
|
host.p_model,
|
|
|
|
host.os_name,
|
|
|
|
host.os_version
|
|
|
|
);
|
|
|
|
if (detail) {
|
|
|
|
fprintf(f,
|
|
|
|
" <create_time>%d</create_time>\n"
|
|
|
|
" <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,
|
|
|
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2003-02-06 00:24:30 +00:00
|
|
|
void write_user(USER& user, FILE* f, bool detail, bool show_team) {
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_HOST host;
|
|
|
|
char buf[256];
|
|
|
|
|
2003-01-30 23:03:52 +00:00
|
|
|
fprintf(f,
|
|
|
|
"<user>\n"
|
|
|
|
" <id>%d</id>\n"
|
|
|
|
" <name>%s</name>\n"
|
2003-03-20 02:05:25 +00:00
|
|
|
" <url>%s</url>\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"
|
2003-02-06 00:24:30 +00:00
|
|
|
" <expavg_credit>%f</expavg_credit>\n",
|
2003-01-30 23:03:52 +00:00
|
|
|
user.id,
|
|
|
|
user.name,
|
2003-03-20 02:05:25 +00:00
|
|
|
user.url,
|
2003-06-18 20:52:17 +00:00
|
|
|
user.country,
|
|
|
|
user.create_time,
|
2003-01-30 23:03:52 +00:00
|
|
|
user.total_credit,
|
2003-02-06 00:24:30 +00:00
|
|
|
user.expavg_credit
|
2003-01-30 23:03:52 +00:00
|
|
|
);
|
2003-02-06 00:24:30 +00:00
|
|
|
if (show_team) {
|
|
|
|
fprintf(f,
|
|
|
|
" <teamid>%d</teamid>\n",
|
|
|
|
user.teamid
|
|
|
|
);
|
|
|
|
}
|
2003-03-20 02:05:25 +00:00
|
|
|
if (detail && user.show_hosts) {
|
2003-06-04 17:21:26 +00:00
|
|
|
sprintf(buf, "where userid=%d", user.id);
|
|
|
|
while (!host.enumerate(buf)) {
|
2003-02-06 00:24:30 +00:00
|
|
|
write_host(host, f, false, false);
|
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-01-30 23:03:52 +00:00
|
|
|
char buf[MAX_BLOB_SIZE*2];
|
|
|
|
|
|
|
|
fprintf(f,
|
|
|
|
"<team>\n"
|
|
|
|
" <id>%d</id>\n"
|
|
|
|
" <name>%s</name>\n"
|
|
|
|
" <total_credit>%f</total_credit>\n"
|
|
|
|
" <expavg_credit>%f</expavg_credit>\n"
|
|
|
|
" <nusers>%d</nusers>\n",
|
|
|
|
team.id,
|
|
|
|
team.name,
|
|
|
|
team.total_credit,
|
|
|
|
team.expavg_credit,
|
|
|
|
team.nusers
|
|
|
|
);
|
|
|
|
if (detail) {
|
|
|
|
fprintf(f,
|
|
|
|
" <create_time>%d</create_time>\n",
|
|
|
|
team.create_time
|
|
|
|
);
|
|
|
|
if (strlen(team.url)) {
|
|
|
|
fprintf(f,
|
|
|
|
" <url>%s</url>\n",
|
|
|
|
team.url
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (strlen(team.name_html)) {
|
|
|
|
escape_url(team.name_html, buf);
|
|
|
|
fprintf(f,
|
|
|
|
"<name_html>%s</name_html>\n",
|
|
|
|
buf
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (strlen(team.description)) {
|
|
|
|
escape_url(team.description, buf);
|
|
|
|
fprintf(f,
|
|
|
|
"<description>%s</description>\n",
|
|
|
|
buf
|
|
|
|
);
|
|
|
|
}
|
|
|
|
fprintf(f,
|
|
|
|
" <country>%s</country>\n",
|
|
|
|
team.country
|
|
|
|
);
|
2003-06-04 17:21:26 +00:00
|
|
|
sprintf(buf, "where teamid=%d", team.id);
|
|
|
|
while (!user.enumerate(buf)) {
|
2003-02-06 00:24:30 +00:00
|
|
|
write_user(user, f, false, false);
|
2003-01-30 23:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(f,
|
|
|
|
"</team>\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void team_total_credit() {
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_TEAM team;
|
2003-08-15 21:12:36 +00:00
|
|
|
NUMBERED_ZFILE f("team_total_credit_%d", nrecs_per_file_summary);
|
2003-01-29 23:03:19 +00:00
|
|
|
|
2003-06-04 17:21:26 +00:00
|
|
|
while (!team.enumerate("order by total_credit desc")) {
|
2003-08-15 21:12:36 +00:00
|
|
|
write_team(team, ++f, false);
|
2003-01-31 07:19:20 +00:00
|
|
|
}
|
2003-01-29 23:03:19 +00:00
|
|
|
}
|
|
|
|
|
2003-01-30 23:03:52 +00:00
|
|
|
void team_expavg_credit() {
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_TEAM team;
|
2003-08-15 21:12:36 +00:00
|
|
|
NUMBERED_ZFILE f("team_expavg_credit_%d", nrecs_per_file_summary);
|
2003-01-30 23:03:52 +00:00
|
|
|
|
2003-06-04 17:21:26 +00:00
|
|
|
while (!team.enumerate("order by expavg_credit desc")) {
|
2003-08-15 21:12:36 +00:00
|
|
|
write_team(team, ++f, false);
|
2003-01-31 07:19:20 +00:00
|
|
|
}
|
2003-01-30 23:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void team_id() {
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_TEAM team;
|
2003-08-15 21:12:36 +00:00
|
|
|
NUMBERED_ZFILE f("team_id_%d", nrecs_per_file_detail);
|
2003-01-30 23:03:52 +00:00
|
|
|
|
2003-06-04 17:21:26 +00:00
|
|
|
while (!team.enumerate("order by id")) {
|
2003-08-15 21:12:36 +00:00
|
|
|
write_team(team, ++f, true);
|
2003-01-31 07:19:20 +00:00
|
|
|
}
|
2003-01-30 23:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void user_total_credit() {
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_USER user;
|
2003-08-15 21:12:36 +00:00
|
|
|
NUMBERED_ZFILE f("user_total_credit_%d", nrecs_per_file_summary);
|
2003-01-30 23:03:52 +00:00
|
|
|
|
2003-06-04 17:21:26 +00:00
|
|
|
while (!user.enumerate("order by total_credit desc")) {
|
2003-08-15 21:12:36 +00:00
|
|
|
write_user(user, ++f, false, true);
|
2003-01-31 07:19:20 +00:00
|
|
|
}
|
2003-01-30 23:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void user_expavg_credit() {
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_USER user;
|
2003-08-15 21:12:36 +00:00
|
|
|
NUMBERED_ZFILE f("user_expavg_credit_%d", nrecs_per_file_summary);
|
2003-01-30 23:03:52 +00:00
|
|
|
|
2003-06-04 17:21:26 +00:00
|
|
|
while (!user.enumerate("order by expavg_credit desc")) {
|
2003-08-15 21:12:36 +00:00
|
|
|
write_user(user, ++f, false, true);
|
2003-01-31 07:19:20 +00:00
|
|
|
}
|
2003-01-30 23:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void user_id() {
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_USER user;
|
2003-08-15 21:12:36 +00:00
|
|
|
NUMBERED_ZFILE f("user_id_%d", nrecs_per_file_detail);
|
2003-01-30 23:03:52 +00:00
|
|
|
|
2003-06-04 17:21:26 +00:00
|
|
|
while (!user.enumerate("order by id")) {
|
2003-08-15 21:12:36 +00:00
|
|
|
write_user(user, ++f, true, true);
|
2003-01-31 07:19:20 +00:00
|
|
|
}
|
2003-01-30 23:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void host_total_credit() {
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_HOST host;
|
2003-08-15 21:12:36 +00:00
|
|
|
NUMBERED_ZFILE f("host_total_credit_%d", nrecs_per_file_summary);
|
2003-01-30 23:03:52 +00:00
|
|
|
|
2003-06-04 17:21:26 +00:00
|
|
|
while (!host.enumerate("order by total_credit desc")) {
|
2003-08-15 21:12:36 +00:00
|
|
|
write_host(host, ++f, false, true);
|
2003-01-31 07:19:20 +00:00
|
|
|
}
|
2003-01-30 23:03:52 +00:00
|
|
|
}
|
2003-03-20 02:05:25 +00:00
|
|
|
|
2003-01-30 23:03:52 +00:00
|
|
|
void host_expavg_credit() {
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_HOST host;
|
2003-08-15 21:12:36 +00:00
|
|
|
NUMBERED_ZFILE f("host_expavg_credit_%d", nrecs_per_file_summary);
|
2003-01-30 23:03:52 +00:00
|
|
|
|
2003-06-04 17:21:26 +00:00
|
|
|
while (!host.enumerate("order by expavg_credit desc")) {
|
2003-08-15 21:12:36 +00:00
|
|
|
write_host(host, ++f, false, true);
|
2003-01-31 07:19:20 +00:00
|
|
|
}
|
2003-01-30 23:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void host_id() {
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_HOST host;
|
2003-08-15 21:12:36 +00:00
|
|
|
NUMBERED_ZFILE f("host_id_%d", nrecs_per_file_detail);
|
2003-01-30 23:03:52 +00:00
|
|
|
|
2003-06-04 17:21:26 +00:00
|
|
|
while (!host.enumerate("order by id")) {
|
2003-08-15 21:12:36 +00:00
|
|
|
write_host(host, ++f, true, true);
|
2003-01-30 23:03:52 +00:00
|
|
|
}
|
2003-08-15 21:12:36 +00:00
|
|
|
}
|
2003-01-31 07:19:20 +00:00
|
|
|
|
2003-08-15 21:12:36 +00:00
|
|
|
void core_versions() {
|
2003-08-15 21:23:56 +00:00
|
|
|
ZFILE f(false);
|
|
|
|
f.open("core_versions.xml");
|
2003-08-15 21:12:36 +00:00
|
|
|
if (!f) return;
|
|
|
|
fprintf(f, "<core_versions>\n");
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
2003-08-15 21:12:36 +00:00
|
|
|
fprintf(f,
|
|
|
|
" <core_version>\n"
|
2003-08-15 21:20:49 +00:00
|
|
|
" <id>%d</id>\n"
|
2003-08-15 21:32:50 +00:00
|
|
|
" <platform id=\"%d\" name=\"%s\">%s</platform>\n"
|
2003-08-15 21:12:36 +00:00
|
|
|
" <version>%d</version>\n"
|
2003-08-15 21:20:49 +00:00
|
|
|
" <create_time>%d</create_time>\n"
|
2003-08-15 21:12:36 +00:00
|
|
|
" <url>%s</url>\n"
|
2003-08-15 21:20:49 +00:00
|
|
|
" </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-08-15 21:20:49 +00:00
|
|
|
fprintf(f, "</core_versions>\n");
|
2003-01-30 23:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int tables_file() {
|
|
|
|
int nusers, nteams, nhosts;
|
2003-01-29 23:03:19 +00:00
|
|
|
int retval;
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_USER user;
|
|
|
|
DB_TEAM team;
|
|
|
|
DB_HOST host;
|
2003-08-15 21:23:56 +00:00
|
|
|
ZFILE f(false);
|
|
|
|
f.open("tables.xml");
|
2003-01-30 23:03:52 +00:00
|
|
|
if (!f) return -1;
|
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;
|
|
|
|
fprintf(f,
|
|
|
|
"<tables>\n"
|
2003-02-26 21:54:34 +00:00
|
|
|
" <update_time>%d</update_time>\n"
|
2003-01-30 23:03:52 +00:00
|
|
|
" <nusers_total>%d</nusers_total>\n"
|
|
|
|
" <nusers_per_file_summary>%d</nusers_per_file_summary>\n"
|
|
|
|
" <nusers_per_file_detail>%d</nusers_per_file_detail>\n"
|
|
|
|
" <nteams_total>%d</nteams_total>\n"
|
|
|
|
" <nteams_per_file_summary>%d</nteams_per_file_summary>\n"
|
|
|
|
" <nteams_per_file_detail>%d</nteams_per_file_detail>\n"
|
|
|
|
" <nhosts_total>%d</nhosts_total>\n"
|
|
|
|
" <nhosts_per_file_summary>%d</nhosts_per_file_summary>\n"
|
|
|
|
" <nhosts_per_file_detail>%d</nhosts_per_file_detail>\n"
|
|
|
|
"</tables>\n",
|
2003-02-26 21:54:34 +00:00
|
|
|
(int)time(0),
|
2003-01-30 23:03:52 +00:00
|
|
|
nusers,
|
2003-03-18 20:29:59 +00:00
|
|
|
nrecs_per_file_summary,
|
|
|
|
nrecs_per_file_detail,
|
2003-01-30 23:03:52 +00:00
|
|
|
nteams,
|
2003-03-18 20:29:59 +00:00
|
|
|
nrecs_per_file_summary,
|
|
|
|
nrecs_per_file_detail,
|
2003-01-30 23:03:52 +00:00
|
|
|
nhosts,
|
2003-03-18 20:29:59 +00:00
|
|
|
nrecs_per_file_summary,
|
|
|
|
nrecs_per_file_detail
|
2003-01-30 23:03:52 +00:00
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
char dir[256];
|
|
|
|
|
2003-03-08 00:09:40 +00:00
|
|
|
check_stop_trigger();
|
|
|
|
|
2003-03-18 20:29:59 +00:00
|
|
|
nrecs_per_file_summary = DEFAULT_NRECS_PER_FILE_SUMMARY;
|
|
|
|
nrecs_per_file_detail = DEFAULT_NRECS_PER_FILE_DETAIL;
|
2003-01-30 23:03:52 +00:00
|
|
|
strcpy(dir, "");
|
|
|
|
for (i=1; i<argc; i++) {
|
2003-03-08 00:09:40 +00:00
|
|
|
if (!strcmp(argv[i], "-dir")) {
|
2003-01-30 23:03:52 +00:00
|
|
|
strcpy(dir, argv[++i]);
|
2003-06-11 23:36:40 +00:00
|
|
|
} else if (!strcmp(argv[i], "-d")) {
|
2003-07-02 02:02:18 +00:00
|
|
|
log_messages.set_debug_level(atoi(argv[++i]));
|
2003-02-26 21:54:34 +00:00
|
|
|
} else if (!strcmp(argv[i], "-gzip")) {
|
|
|
|
zip_files = true;
|
2003-08-15 21:12:36 +00:00
|
|
|
zip_cmd = "gzip -fq";
|
2003-02-26 21:54:34 +00:00
|
|
|
} else if (!strcmp(argv[i], "-zip")) {
|
|
|
|
zip_files = true;
|
2003-08-15 21:12:36 +00:00
|
|
|
zip_cmd = "zip -q";
|
2003-03-18 20:29:59 +00:00
|
|
|
} else if (!strcmp(argv[i], "-summary_recs")) {
|
|
|
|
nrecs_per_file_summary = atoi(argv[++i]);
|
|
|
|
} else if (!strcmp(argv[i], "-detail_recs")) {
|
|
|
|
nrecs_per_file_detail = atoi(argv[++i]);
|
2003-01-30 23:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-10 19:51:32 +00:00
|
|
|
|
2003-03-18 20:29:59 +00:00
|
|
|
if (nrecs_per_file_summary <= 0 || nrecs_per_file_detail <= 0) {
|
2003-07-02 02:02:18 +00:00
|
|
|
log_messages.printf(SchedMessages::NORMAL, "Too few records per file.\n");
|
2003-03-18 20:29:59 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2003-02-10 19:51:32 +00:00
|
|
|
if (lock_file(LOCKFILE)) {
|
2003-07-02 02:02:18 +00:00
|
|
|
log_messages.printf(SchedMessages::NORMAL, "Another copy of db_dump is already running\n");
|
2003-02-10 19:51:32 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2003-07-02 02:02:18 +00:00
|
|
|
log_messages.printf(SchedMessages::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) {
|
2003-07-02 02:02:18 +00:00
|
|
|
log_messages.printf(SchedMessages::NORMAL, "Can't parse config file\n");
|
2003-01-29 23:03:19 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2003-09-05 21:26:21 +00:00
|
|
|
retval = boinc_db.open(config.db_name, config.db_passwd);
|
2003-01-29 23:03:19 +00:00
|
|
|
if (retval) {
|
2003-07-02 02:02:18 +00:00
|
|
|
log_messages.printf(SchedMessages::NORMAL, "Can't open DB\n");
|
2003-01-29 23:03:19 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2003-01-30 23:03:52 +00:00
|
|
|
|
|
|
|
if (strlen(dir)) {
|
|
|
|
retval = chdir(dir);
|
|
|
|
if (retval) {
|
2003-07-02 02:02:18 +00:00
|
|
|
log_messages.printf(SchedMessages::NORMAL, "can't chdir to %s\n", dir);
|
2003-01-30 23:03:52 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tables_file();
|
|
|
|
team_total_credit();
|
|
|
|
team_expavg_credit();
|
|
|
|
team_id();
|
|
|
|
user_total_credit();
|
|
|
|
user_expavg_credit();
|
|
|
|
user_id();
|
|
|
|
host_total_credit();
|
|
|
|
host_expavg_credit();
|
|
|
|
host_id();
|
2003-08-15 21:12:36 +00:00
|
|
|
core_versions();
|
2003-01-29 23:03:19 +00:00
|
|
|
}
|