// The contents of this file are subject to the BOINC Public License // 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 // http://boinc.berkeley.edu/license_1.0.txt // // 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 // under the License. // // The Original Code is the Berkeley Open Infrastructure for Network Computing. // // The Initial Developer of the Original Code is the SETI@home project. // Portions created by the SETI@home project are Copyright (C) 2002 // University of California at Berkeley. All Rights Reserved. // // Contributor(s): // // db_dump: dump database views in XML format // // usage: db_dump [-dir path] [-summary_recs num_recs_per_file] // [-detail_recs num_recs_per_file] [-gzip] [-zip] // files: // 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, // or the highest-ranked rows, to get this info with limited transfer // // // 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. #include #include #include #include #include "boinc_db.h" #include "util.h" #include "config.h" #include "sched_util.h" #define LOCKFILE "db_dump.out" #define DEFAULT_NRECS_PER_FILE_SUMMARY 1000 #define DEFAULT_NRECS_PER_FILE_DETAIL 100 int nrecs_per_file_summary; int nrecs_per_file_detail; bool zip_files = false; char zip_cmd[256]; void write_host(HOST& host, FILE* f, bool detail, bool show_user) { fprintf(f, "\n" " %d\n", host.id ); if (show_user) { DB_USER user; user.lookup_id(host.userid); if (user.show_hosts) { fprintf(f, " %d\n", host.userid ); } } fprintf(f, " %f\n" " %f\n" " %s\n" " %s\n" " %s\n" " %s\n", host.total_credit, host.expavg_credit, host.p_vendor, host.p_model, host.os_name, host.os_version ); if (detail) { fprintf(f, " %d\n" " %d\n" " %d\n" " %f\n" " %f\n" " %f\n" " %f\n" " %f\n" " %f\n" " %f\n" " %f\n" " %f\n" " %f\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 ); } fprintf(f, "\n" ); } void write_user(USER& user, FILE* f, bool detail, bool show_team) { DB_HOST host; char buf[256]; fprintf(f, "\n" " %d\n" " %s\n" " %s\n" " %s\n" " %d\n" " %f\n" " %f\n", user.id, user.name, user.url, user.country, user.create_time, user.total_credit, user.expavg_credit ); if (show_team) { fprintf(f, " %d\n", user.teamid ); } if (detail && user.show_hosts) { sprintf(buf, "where userid=%d", user.id); while (!host.enumerate(buf)) { write_host(host, f, false, false); } } fprintf(f, "\n" ); } void write_team(TEAM& team, FILE* f, bool detail) { DB_USER user; char buf[MAX_BLOB_SIZE*2]; fprintf(f, "\n" " %d\n" " %s\n" " %f\n" " %f\n" " %d\n", team.id, team.name, team.total_credit, team.expavg_credit, team.nusers ); if (detail) { fprintf(f, " %d\n", team.create_time ); if (strlen(team.url)) { fprintf(f, " %s\n", team.url ); } if (strlen(team.name_html)) { escape_url(team.name_html, buf); fprintf(f, "%s\n", buf ); } if (strlen(team.description)) { escape_url(team.description, buf); fprintf(f, "%s\n", buf ); } fprintf(f, " %s\n", team.country ); sprintf(buf, "where teamid=%d", team.id); while (!user.enumerate(buf)) { write_user(user, f, false, false); } } fprintf(f, "\n" ); } void team_total_credit() { DB_TEAM team; FILE* f = NULL; int nfile=0, nrec=0; char buf[256], cmd_line[256]; while (!team.enumerate("order by total_credit desc")) { if (!f) { sprintf(buf, "team_total_credit_%d", nfile); sprintf(cmd_line, "%s %s", zip_cmd, buf); f = fopen(buf, "w"); nfile++; nrec = 0; } write_team(team, f, false); nrec++; if (nrec == nrecs_per_file_summary) { fclose(f); if (zip_files) system(cmd_line); f = 0; } } if (f) { fclose(f); if (zip_files) system(cmd_line); } } void team_expavg_credit() { DB_TEAM team; FILE* f = NULL; int nfile=0, nrec=0; char buf[256], cmd_line[256]; while (!team.enumerate("order by expavg_credit desc")) { if (!f) { sprintf(buf, "team_expavg_credit_%d", nfile); sprintf(cmd_line, "%s %s", zip_cmd, buf); f = fopen(buf, "w"); nfile++; nrec = 0; } write_team(team, f, false); nrec++; if (nrec == nrecs_per_file_summary) { fclose(f); if (zip_files) system(cmd_line); f = 0; } } if (f) { fclose(f); if (zip_files) system(cmd_line); } } void team_id() { DB_TEAM team; FILE* f = NULL; int nfile=0, nrec=0; char buf[256], cmd_line[256]; while (!team.enumerate("order by id")) { if (!f) { sprintf(buf, "team_id_%d", nfile); sprintf(cmd_line, "%s %s", zip_cmd, buf); f = fopen(buf, "w"); nfile++; nrec = 0; } write_team(team, f, true); nrec++; if (nrec == nrecs_per_file_detail) { fclose(f); if (zip_files) system(cmd_line); f = 0; } } if (f) { fclose(f); if (zip_files) system(cmd_line); } } void user_total_credit() { DB_USER user; FILE* f = NULL; int nfile=0, nrec=0; char buf[256], cmd_line[256]; while (!user.enumerate("order by total_credit desc")) { if (!f) { sprintf(buf, "user_total_credit_%d", nfile); sprintf(cmd_line, "%s %s", zip_cmd, buf); f = fopen(buf, "w"); nfile++; nrec = 0; } write_user(user, f, false, true); nrec++; if (nrec == nrecs_per_file_summary) { fclose(f); if (zip_files) system(cmd_line); f = 0; } } if (f) { fclose(f); if (zip_files) system(cmd_line); } } void user_expavg_credit() { DB_USER user; FILE* f = NULL; int nfile=0, nrec=0; char buf[256], cmd_line[256]; while (!user.enumerate("order by expavg_credit desc")) { if (!f) { sprintf(buf, "user_expavg_credit_%d", nfile); sprintf(cmd_line, "%s %s", zip_cmd, buf); f = fopen(buf, "w"); nfile++; nrec = 0; } write_user(user, f, false, true); nrec++; if (nrec == nrecs_per_file_summary) { fclose(f); if (zip_files) system(cmd_line); f = 0; } } if (f) { fclose(f); if (zip_files) system(cmd_line); } } void user_id() { DB_USER user; FILE* f = NULL; int nfile=0, nrec=0; char buf[256], cmd_line[256]; while (!user.enumerate("order by id")) { if (!f) { sprintf(buf, "user_id_%d", nfile); sprintf(cmd_line, "%s %s", zip_cmd, buf); f = fopen(buf, "w"); nfile++; nrec = 0; } write_user(user, f, true, true); nrec++; if (nrec == nrecs_per_file_detail) { fclose(f); if (zip_files) system(cmd_line); f = 0; } } if (f) { fclose(f); if (zip_files) system(cmd_line); } } void host_total_credit() { DB_HOST host; FILE* f = NULL; int nfile=0, nrec=0; char buf[256], cmd_line[256]; while (!host.enumerate("order by total_credit desc")) { if (!f) { sprintf(buf, "host_total_credit_%d", nfile); sprintf(cmd_line, "%s %s", zip_cmd, buf); f = fopen(buf, "w"); nfile++; nrec = 0; } write_host(host, f, false, true); nrec++; if (nrec == nrecs_per_file_summary) { fclose(f); if (zip_files) system(cmd_line); f = 0; } } if (f) { fclose(f); if (zip_files) system(cmd_line); } } void host_expavg_credit() { DB_HOST host; FILE* f = NULL; int nfile=0, nrec=0; char buf[256], cmd_line[256]; while (!host.enumerate("order by expavg_credit desc")) { if (!f) { sprintf(buf, "host_expavg_credit_%d", nfile); sprintf(cmd_line, "%s %s", zip_cmd, buf); f = fopen(buf, "w"); nfile++; nrec = 0; } write_host(host, f, false, true); nrec++; if (nrec == nrecs_per_file_summary) { fclose(f); if (zip_files) system(cmd_line); f = 0; } } if (f) { fclose(f); if (zip_files) system(cmd_line); } } void host_id() { DB_HOST host; FILE* f = NULL; int nfile=0, nrec=0; char buf[256], cmd_line[256]; while (!host.enumerate("order by id")) { if (!f) { sprintf(buf, "host_id_%d", nfile); sprintf(cmd_line, "%s %s", zip_cmd, buf); f = fopen(buf, "w"); nfile++; nrec = 0; } write_host(host, f, true, true); nrec++; if (nrec == nrecs_per_file_detail) { fclose(f); if (zip_files) system(cmd_line); f = 0; } } if (f) { fclose(f); if (zip_files) system(cmd_line); } } int tables_file() { int nusers, nteams, nhosts; int retval; DB_USER user; DB_TEAM team; DB_HOST host; FILE* f = NULL; f = fopen("tables.xml", "w"); if (!f) return -1; retval = user.count(nusers); if (retval) return retval; retval = team.count(nteams); if (retval) return retval; retval = host.count(nhosts); if (retval) return retval; fprintf(f, "\n" " %d\n" " %d\n" " %d\n" " %d\n" " %d\n" " %d\n" " %d\n" " %d\n" " %d\n" " %d\n" "\n", (int)time(0), nusers, nrecs_per_file_summary, nrecs_per_file_detail, nteams, nrecs_per_file_summary, nrecs_per_file_detail, nhosts, nrecs_per_file_summary, nrecs_per_file_detail ); fclose(f); return 0; } int main(int argc, char** argv) { CONFIG config; int retval, i; char dir[256]; check_stop_trigger(); nrecs_per_file_summary = DEFAULT_NRECS_PER_FILE_SUMMARY; nrecs_per_file_detail = DEFAULT_NRECS_PER_FILE_DETAIL; strcpy(dir, ""); strcpy(zip_cmd, ""); for (i=1; i