X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=bacula%2Fsrc%2Fdird%2Fua_cmds.c;h=9c37032325ca16861643014c9ea446ea31a40a32;hb=786be614c53783a10956e6ea4c9ef1f643edf07a;hp=a886f1d956309341c8474e669814943a122116b2;hpb=908d0c5a7c352c4473409fd01cab16d968c41b43;p=bacula%2Fbacula diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index a886f1d956..9c37032325 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -1,12 +1,12 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-2012 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. This program is Free Software; you can redistribute it and/or - modify it under the terms of version two of the GNU General Public + modify it under the terms of version three of the GNU Affero General Public License as published by the Free Software Foundation and included in the file LICENSE. @@ -15,7 +15,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License + You should have received a copy of the GNU Affero General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -31,12 +31,24 @@ * * Kern Sibbald, September MM * - * Version $Id$ */ #include "bacula.h" #include "dird.h" +#ifdef HAVE_PYTHON + +#undef _POSIX_C_SOURCE +#include + +#include "lib/pythonlib.h" + +/* Imported Functions */ +extern PyObject *job_getattr(PyObject *self, char *attrname); +extern int job_setattr(PyObject *self, char *attrname, PyObject *value); + +#endif /* HAVE_PYTHON */ + /* Imported subroutines */ /* Imported variables */ @@ -87,7 +99,7 @@ static int version_cmd(UAContext *ua, const char *cmd); static int wait_cmd(UAContext *ua, const char *cmd); static void do_job_delete(UAContext *ua, JobId_t JobId); -static void delete_job_id_range(UAContext *ua, char *tok); +static bool delete_job_id_range(UAContext *ua, char *tok); static int delete_volume(UAContext *ua); static int delete_pool(UAContext *ua); static void delete_job(UAContext *ua); @@ -95,67 +107,114 @@ static void delete_job(UAContext *ua); int qhelp_cmd(UAContext *ua, const char *cmd); int quit_cmd(UAContext *ua, const char *cmd); - -struct cmdstruct { const char *key; int (*func)(UAContext *ua, const char *cmd); const char *help; }; -static struct cmdstruct commands[] = { - { NT_("add"), add_cmd, _("add media to a pool")}, - { NT_("autodisplay"), autodisplay_cmd, _("autodisplay [on|off] -- console messages")}, - { NT_("automount"), automount_cmd, _("automount [on|off] -- after label")}, - { NT_("cancel"), cancel_cmd, _("cancel [ | ] -- cancel a job")}, - { NT_("create"), create_cmd, _("create DB Pool from resource")}, - { NT_("delete"), delete_cmd, _("delete [pool= | media volume=]")}, - { NT_("disable"), disable_cmd, _("disable -- disable a job")}, - { NT_("enable"), enable_cmd, _("enable -- enable a job")}, - { NT_("estimate"), estimate_cmd, _("performs FileSet estimate, listing gives full listing")}, - { NT_("exit"), quit_cmd, _("exit = quit")}, - { NT_("gui"), gui_cmd, _("gui [on|off] -- non-interactive gui mode")}, - { NT_("help"), help_cmd, _("print this command")}, - { NT_("list"), list_cmd, _("list [pools | jobs | jobtotals | media | files ]; from catalog")}, - { NT_("label"), label_cmd, _("label a tape")}, - { NT_("llist"), llist_cmd, _("full or long list like list command")}, - { NT_("messages"), messagescmd, _("messages")}, - { NT_("memory"), memory_cmd, _("print current memory usage")}, - { NT_("mount"), mount_cmd, _("mount ")}, - { NT_("prune"), prunecmd, _("prune expired records from catalog")}, - { NT_("purge"), purgecmd, _("purge records from catalog")}, - { NT_("python"), python_cmd, _("python control commands")}, - { NT_("quit"), quit_cmd, _("quit")}, - { NT_("query"), querycmd, _("query catalog")}, - { NT_("restore"), restore_cmd, _("restore files")}, - { NT_("relabel"), relabel_cmd, _("relabel a tape")}, - { NT_("release"), release_cmd, _("release ")}, - { NT_("reload"), reload_cmd, _("reload conf file")}, - { NT_("run"), run_cmd, _("run ")}, - { NT_("status"), status_cmd, _("status [storage | client]=")}, - { NT_("setdebug"), setdebug_cmd, _("sets debug level")}, - { NT_("setip"), setip_cmd, _("sets new client address -- if authorized")}, - { NT_("show"), show_cmd, _("show (resource records) [jobs | pools | ... | all]")}, - { NT_("sqlquery"), sqlquerycmd, _("use SQL to query catalog")}, - { NT_("time"), time_cmd, _("print current time")}, - { NT_("trace"), trace_cmd, _("turn on/off trace to file")}, - { NT_("unmount"), unmount_cmd, _("unmount ")}, - { NT_("umount"), unmount_cmd, _("umount for old-time Unix guys")}, - { NT_("update"), update_cmd, _("update Volume, Pool or slots")}, - { NT_("use"), use_cmd, _("use catalog xxx")}, - { NT_("var"), var_cmd, _("does variable expansion")}, - { NT_("version"), version_cmd, _("print Director version")}, - { NT_("wait"), wait_cmd, _("wait until no jobs are running [ | | ]")}, - }; -#define comsize (sizeof(commands)/sizeof(struct cmdstruct)) +/* not all in alphabetical order. New commands are added after existing commands with similar letters + to prevent breakage of existing user scripts. */ +struct cmdstruct { + const char *key; /* command */ + int (*func)(UAContext *ua, const char *cmd); /* handler */ + const char *help; /* main purpose */ + const char *usage; /* all arguments to build usage */ + const bool use_in_rs; /* Can use it in Console RunScript */ +}; +static struct cmdstruct commands[] = { /* Can use it in Console RunScript*/ + { NT_("add"), add_cmd, _("Add media to a pool"), NT_("pool= storage= jobid="), false}, + { NT_("autodisplay"), autodisplay_cmd,_("Autodisplay console messages"), NT_("on | off"), false}, + { NT_("automount"), automount_cmd, _("Automount after label"), NT_("on | off"), false}, + { NT_("cancel"), cancel_cmd, _("Cancel a job"), NT_("jobid= job= ujobid="), false}, + { NT_("create"), create_cmd, _("Create DB Pool from resource"), NT_("pool="), false}, + { NT_("delete"), delete_cmd, _("Delete volume, pool or job"), NT_("volume= pool= jobid="), true}, + { NT_("disable"), disable_cmd, _("Disable a job"), NT_("job="), true}, + { NT_("enable"), enable_cmd, _("Enable a job"), NT_("job="), true}, + { NT_("estimate"), estimate_cmd, _("Performs FileSet estimate, listing gives full listing"), + NT_("fileset= client= level= accurate= job= listing"), true}, + + { NT_("exit"), quit_cmd, _("Terminate Bconsole session"), NT_(""), false}, + { NT_("gui"), gui_cmd, _("Non-interactive gui mode"), NT_("on | off"), false}, + { NT_("help"), help_cmd, _("Print help on specific command"), + NT_("add autodisplay automount cancel create delete disable\n\tenable estimate exit gui label list llist" + "\n\tmessages memory mount prune purge python quit query\n\trestore relabel release reload run status" + "\n\tsetdebug setip show sqlquery time trace unmount\n\tumount update use var version wait"), false}, + + { NT_("label"), label_cmd, _("Label a tape"), NT_("storage= volume= pool= slot= barcodes"), false}, + { NT_("list"), list_cmd, _("List objects from catalog"), + NT_("pools | jobs | jobtotals | volume | media | files jobid= | copies jobid="), true}, + + { NT_("llist"), llist_cmd, _("Full or long list like list command"), + NT_("pools | jobs | jobtotals | media | files jobid= | copies jobid="), true}, + + { NT_("messages"), messagescmd, _("Display pending messages"), NT_(""), false}, + { NT_("memory"), memory_cmd, _("Print current memory usage"), NT_(""), true}, + { NT_("mount"), mount_cmd, _("Mount storage"), + NT_("storage= slot= drive= [ jobid= | job= ]"), false}, + + { NT_("prune"), prunecmd, _("Prune expired records from catalog"), + NT_("files | jobs | pool= | client= | volume= "), true}, + + { NT_("purge"), purgecmd, _("Purge records from catalog"), NT_("files jobs volume= [action= devicetype= pool= allpools storage= drive=]"), true}, + { NT_("python"), python_cmd, _("Python control commands"), NT_(""), false}, + { NT_("quit"), quit_cmd, _("Terminate Bconsole session"), NT_(""), false}, + { NT_("query"), querycmd, _("Query catalog"), NT_(""), false}, + { NT_("restore"), restore_cmd, _("Restore files"), + NT_("where= client= storage= bootstrap= " + "restorejob=" + "\n\tcomment= jobid= done select all"), false}, + + { NT_("relabel"), relabel_cmd, _("Relabel a tape"), + NT_("storage= oldvolume=\n\tvolume= pool="), false}, + + { NT_("release"), release_cmd, _("Release storage"), NT_("storage="), false}, + { NT_("reload"), reload_cmd, _("Reload conf file"), NT_(""), true}, + { NT_("run"), run_cmd, _("Run a job"), + NT_("job= client=\n\tfileset= level=\n\tstorage=" + "where=\n\twhen=\n\tcomment= yes"), false}, + + { NT_("status"), status_cmd, _("Report status"), + NT_("all | dir= | director | client= | storage= slots | days=nnn"), true}, + + { NT_("setdebug"), setdebug_cmd, _("Sets debug level"), + NT_("level= trace=0/1 client= | dir | storage= | all"), true}, + + { NT_("setip"), setip_cmd, _("Sets new client address -- if authorized"), NT_(""), false}, + { NT_("show"), show_cmd, _("Show resource records"), + NT_("job= | pool= | fileset= schedule= | client= | disabled | all"), true}, + + { NT_("sqlquery"), sqlquerycmd, _("Use SQL to query catalog"), NT_(""), false}, + { NT_("time"), time_cmd, _("Print current time"), NT_(""), true}, + { NT_("trace"), trace_cmd, _("Turn on/off trace to file"), NT_("on | off"), true}, + { NT_("unmount"), unmount_cmd, _("Unmount storage"), + NT_("storage= [ drive= ] | jobid= | job="), false}, + + { NT_("umount"), unmount_cmd, _("Umount - for old-time Unix guys, see unmount"), + NT_("storage= [ drive= ] | jobid= | job="), false}, + + { NT_("update"), update_cmd, _("Update volume, pool or stats"), + NT_("stats\n\tpool=\n\tslots storage= scan" + "\n\tvolume= volstatus= volretention=" + "\n\t pool= recycle= slot=\n\t inchanger=" + "\n\t maxvolbytes= maxvolfiles= maxvoljobs=" + "\n\t enable= recyclepool= actiononpurge="),true}, + { NT_("use"), use_cmd, _("Use catalog xxx"), NT_("catalog="), false}, + { NT_("var"), var_cmd, _("Does variable expansion"), NT_(""), false}, + { NT_("version"), version_cmd, _("Print Director version"), NT_(""), true}, + { NT_("wait"), wait_cmd, _("Wait until no jobs are running"), + NT_("jobname= | jobid= | ujobid="), false} +}; + +#define comsize ((int)(sizeof(commands)/sizeof(struct cmdstruct))) /* * Execute a command from the UA */ bool do_a_command(UAContext *ua) { - unsigned int i; + int i; int len; bool ok = false; bool found = false; BSOCK *user = ua->UA_sock; - Dmsg1(900, "Command: %s\n", ua->UA_sock->msg); + Dmsg1(900, "Command: %s\n", ua->argk[0]); if (ua->argc == 0) { return false; } @@ -172,8 +231,14 @@ bool do_a_command(UAContext *ua) !acl_access_ok(ua, Command_ACL, ua->argk[0], len)) { break; } + /* Check if this command is authorized in RunScript */ + if (ua->runscript && !commands[i].use_in_rs) { + ua->error_msg(_("Can't use %s command in a runscript"), ua->argk[0]); + break; + } if (ua->api) user->signal(BNET_CMD_BEGIN); ok = (*commands[i].func)(ua, ua->cmd); /* go execute command */ + if (ua->api) user->signal(ok?BNET_CMD_OK:BNET_CMD_FAILED); found = true; break; } @@ -182,7 +247,6 @@ bool do_a_command(UAContext *ua) ua->error_msg(_("%s: is an invalid command.\n"), ua->argk[0]); ok = false; } - if (ua->api) user->signal(ok?BNET_CMD_OK:BNET_CMD_FAILED); return ok; } @@ -198,6 +262,7 @@ void set_pool_dbr_defaults_in_media_dbr(MEDIA_DBR *mr, POOL_DBR *pr) mr->Recycle = pr->Recycle; mr->VolRetention = pr->VolRetention; mr->VolUseDuration = pr->VolUseDuration; + mr->ActionOnPurge = pr->ActionOnPurge; mr->RecyclePoolId = pr->RecyclePoolId; mr->MaxVolJobs = pr->MaxVolJobs; mr->MaxVolFiles = pr->MaxVolFiles; @@ -215,7 +280,6 @@ static int add_cmd(UAContext *ua, const char *cmd) POOL_DBR pr; MEDIA_DBR mr; int num, i, max, startnum; - int first_id = 0; char name[MAX_NAME_LENGTH]; STORE *store; int Slot = 0, InChanger = 0; @@ -230,7 +294,6 @@ static int add_cmd(UAContext *ua, const char *cmd) } memset(&pr, 0, sizeof(pr)); - memset(&mr, 0, sizeof(mr)); if (!get_pool_dbr(ua, &pr)) { return 1; @@ -334,16 +397,13 @@ static int add_cmd(UAContext *ua, const char *cmd) bsnprintf(mr.VolumeName, sizeof(mr.VolumeName), name, i); mr.Slot = Slot++; mr.InChanger = InChanger; - mr.StorageId = store->StorageId; mr.Enabled = 1; + set_storageid_in_mr(store, &mr); Dmsg1(200, "Create Volume %s\n", mr.VolumeName); if (!db_create_media_record(ua->jcr, ua->db, &mr)) { ua->error_msg("%s", db_strerror(ua->db)); return 1; } - if (i == startnum) { - first_id = mr.PoolId; - } } pr.NumVols += num; Dmsg0(200, "Update pool record.\n"); @@ -393,10 +453,10 @@ static int cancel_cmd(UAContext *ua, const char *cmd) for (i=1; iargc; i++) { if (strcasecmp(ua->argk[i], NT_("jobid")) == 0) { uint32_t JobId; - if (!ua->argv[i]) { + JobId = str_to_int64(ua->argv[i]); + if (!JobId) { break; } - JobId = str_to_int64(ua->argv[i]); if (!(jcr=get_jcr_by_id(JobId))) { ua->error_msg(_("JobId %s is not running. Use Job name to cancel inactive jobs.\n"), ua->argv[i]); return 1; @@ -538,6 +598,7 @@ void set_pooldbr_from_poolres(POOL_DBR *pr, POOL *pool, e_pool_op op) pr->MaxVolFiles = pool->MaxVolFiles; pr->MaxVolBytes = pool->MaxVolBytes; pr->AutoPrune = pool->AutoPrune; + pr->ActionOnPurge = pool->action_on_purge; pr->Recycle = pool->Recycle; if (pool->label_format) { bstrncpy(pr->LabelFormat, pool->label_format, sizeof(pr->LabelFormat)); @@ -546,12 +607,12 @@ void set_pooldbr_from_poolres(POOL_DBR *pr, POOL *pool, e_pool_op op) } } -/* set/update Pool.RecyclePoolId in Catalog */ -int update_pool_recyclepool(JCR *jcr, B_DB *db, POOL *pool) +/* set/update Pool.RecyclePoolId and Pool.ScratchPoolId in Catalog */ +int update_pool_references(JCR *jcr, B_DB *db, POOL *pool) { POOL_DBR pr; - if (!pool->RecyclePool) { + if (!pool->RecyclePool && !pool->ScratchPool) { return 1; } @@ -564,7 +625,7 @@ int update_pool_recyclepool(JCR *jcr, B_DB *db, POOL *pool) set_pooldbr_from_poolres(&pr, pool, POOL_OP_UPDATE); - if (!set_pooldbr_recyclepoolid(jcr, db, &pr, pool)) { + if (!set_pooldbr_references(jcr, db, &pr, pool)) { return -1; /* error */ } @@ -574,10 +635,10 @@ int update_pool_recyclepool(JCR *jcr, B_DB *db, POOL *pool) return 1; } -/* set POOL_DBR.RecyclePoolId from Pool resource +/* set POOL_DBR.RecyclePoolId and POOL_DBR.ScratchPoolId from Pool resource * works with set_pooldbr_from_poolres */ -bool set_pooldbr_recyclepoolid(JCR *jcr, B_DB *db, POOL_DBR *pr, POOL *pool) +bool set_pooldbr_references(JCR *jcr, B_DB *db, POOL_DBR *pr, POOL *pool) { POOL_DBR rpool; bool ret = true; @@ -599,6 +660,24 @@ bool set_pooldbr_recyclepoolid(JCR *jcr, B_DB *db, POOL_DBR *pr, POOL *pool) } else { /* no RecyclePool used, set it to 0 */ pr->RecyclePoolId = 0; } + + if (pool->ScratchPool) { + memset(&rpool, 0, sizeof(POOL_DBR)); + + bstrncpy(rpool.Name, pool->ScratchPool->name(), sizeof(rpool.Name)); + if (db_get_pool_record(jcr, db, &rpool)) { + pr->ScratchPoolId = rpool.PoolId; + } else { + Jmsg(jcr, M_WARNING, 0, + _("Can't set %s ScratchPool to %s, %s is not in database.\n" \ + "Try to update it with 'update pool=%s'\n"), + pool->name(), rpool.Name, rpool.Name,pool->name()); + ret = false; + } + } else { /* no ScratchPool used, set it to 0 */ + pr->ScratchPoolId = 0; + } + return ret; } @@ -623,12 +702,14 @@ int create_pool(JCR *jcr, B_DB *db, POOL *pool, e_pool_op op) /* Pool Exists */ if (op == POOL_OP_UPDATE) { /* update request */ set_pooldbr_from_poolres(&pr, pool, op); + set_pooldbr_references(jcr, db, &pr, pool); db_update_pool_record(jcr, db, &pr); } return 0; /* exists */ } set_pooldbr_from_poolres(&pr, pool, op); + set_pooldbr_references(jcr, db, &pr, pool); if (!db_create_pool_record(jcr, db, &pr)) { return -1; /* error */ @@ -674,6 +755,7 @@ static int create_cmd(UAContext *ua, const char *cmd) extern DIRRES *director; +extern char *configfile; /* * Python control command @@ -681,18 +763,32 @@ extern DIRRES *director; */ static int python_cmd(UAContext *ua, const char *cmd) { +#ifdef HAVE_PYTHON + init_python_interpreter_args python_args; + if (ua->argc >= 2 && strcasecmp(ua->argk[1], NT_("restart")) == 0) { term_python_interpreter(); - init_python_interpreter(director->name(), - director->scripts_directory, "DirStartUp"); + + python_args.progname = director->name(); + python_args.scriptdir = director->scripts_directory; + python_args.modulename = "DirStartUp"; + python_args.configfile = configfile; + python_args.workingdir = director->working_directory; + python_args.job_getattr = job_getattr; + python_args.job_setattr = job_setattr; + + init_python_interpreter(&python_args); + ua->send_msg(_("Python interpreter restarted.\n")); } else { +#endif /* HAVE_PYTHON */ ua->warning_msg(_("Nothing done.\n")); +#ifdef HAVE_PYTHON } +#endif /* HAVE_PYTHON */ return 1; } - /* * Set a new address in a Client resource. We do this only * if the Console name is the same as the Client name @@ -734,7 +830,7 @@ static void do_en_disable_cmd(UAContext *ua, bool setting) i = find_arg_with_value(ua, NT_("job")); if (i < 0) { - job = select_job_resource(ua); + job = select_enable_disable_job_resource(ua, setting); if (!job) { return; } @@ -769,7 +865,6 @@ static int disable_cmd(UAContext *ua, const char *cmd) return 1; } - static void do_storage_setdebug(UAContext *ua, STORE *store, int level, int trace_flag) { BSOCK *sd; @@ -788,17 +883,26 @@ static void do_storage_setdebug(UAContext *ua, STORE *store, int level, int trac } Dmsg0(120, _("Connected to storage daemon\n")); sd = jcr->store_bsock; - bnet_fsend(sd, "setdebug=%d trace=%d\n", level, trace_flag); - if (bnet_recv(sd) >= 0) { + sd->fsend("setdebug=%d trace=%d\n", level, trace_flag); + if (sd->recv() >= 0) { ua->send_msg("%s", sd->msg); } - bnet_sig(sd, BNET_TERMINATE); - bnet_close(sd); + sd->signal(BNET_TERMINATE); + sd->close(); jcr->store_bsock = NULL; return; } -static void do_client_setdebug(UAContext *ua, CLIENT *client, int level, int trace_flag) +/* + * For the client, we have the following values that can be set + * level = debug level + * trace = send debug output to a file + * hangup = how many records to send to SD before hanging up + * obviously this is most useful for testing restarting + * failed jobs. + */ +static void do_client_setdebug(UAContext *ua, CLIENT *client, + int level, int trace, int hangup) { BSOCK *fd; @@ -814,18 +918,18 @@ static void do_client_setdebug(UAContext *ua, CLIENT *client, int level, int tra } Dmsg0(120, "Connected to file daemon\n"); fd = ua->jcr->file_bsock; - bnet_fsend(fd, "setdebug=%d trace=%d\n", level, trace_flag); - if (bnet_recv(fd) >= 0) { + fd->fsend("setdebug=%d trace=%d hangup=%d\n", level, trace, hangup); + if (fd->recv() >= 0) { ua->send_msg("%s", fd->msg); } - bnet_sig(fd, BNET_TERMINATE); - bnet_close(fd); + fd->signal(BNET_TERMINATE); + fd->close(); ua->jcr->file_bsock = NULL; return; } -static void do_all_setdebug(UAContext *ua, int level, int trace_flag) +static void do_all_setdebug(UAContext *ua, int level, int trace_flag, int hangup) { STORE *store, **unique_store; CLIENT *client, **unique_client; @@ -898,7 +1002,7 @@ static void do_all_setdebug(UAContext *ua, int level, int trace_flag) /* Call each unique File daemon */ for (j=0; j not change */ + i = find_arg_with_value(ua, "hangup"); + if (i >= 0) { + hangup = atoi(ua->argv[i]); + } + + /* General debug? */ for (i=1; iargc; i++) { if (strcasecmp(ua->argk[i], "all") == 0) { - do_all_setdebug(ua, level, trace_flag); + do_all_setdebug(ua, level, trace_flag, hangup); return 1; } if (strcasecmp(ua->argk[i], "dir") == 0 || @@ -958,13 +1067,13 @@ static int setdebug_cmd(UAContext *ua, const char *cmd) if (ua->argv[i]) { client = GetClientResWithName(ua->argv[i]); if (client) { - do_client_setdebug(ua, client, level, trace_flag); + do_client_setdebug(ua, client, level, trace_flag, hangup); return 1; } } client = select_client_resource(ua); if (client) { - do_client_setdebug(ua, client, level, trace_flag); + do_client_setdebug(ua, client, level, trace_flag, hangup); return 1; } } @@ -1010,11 +1119,11 @@ static int setdebug_cmd(UAContext *ua, const char *cmd) case 2: client = select_client_resource(ua); if (client) { - do_client_setdebug(ua, client, level, trace_flag); + do_client_setdebug(ua, client, level, trace_flag, hangup); } break; case 3: - do_all_setdebug(ua, level, trace_flag); + do_all_setdebug(ua, level, trace_flag, hangup); break; default: break; @@ -1072,8 +1181,9 @@ static int estimate_cmd(UAContext *ua, const char *cmd) int listing = 0; char since[MAXSTRING]; JCR *jcr = ua->jcr; + int accurate=-1; - jcr->JobLevel = L_FULL; + jcr->setJobLevel(L_FULL); for (int i=1; iargc; i++) { if (strcasecmp(ua->argk[i], NT_("client")) == 0 || strcasecmp(ua->argk[i], NT_("fd")) == 0) { @@ -1083,7 +1193,14 @@ static int estimate_cmd(UAContext *ua, const char *cmd) ua->error_msg(_("Client \"%s\" not found.\n"), ua->argv[i]); return 1; } + if (!acl_access_ok(ua, Client_ACL, client->name())) { + ua->error_msg(_("No authorization for Client \"%s\"\n"), client->name()); + return 1; + } continue; + } else { + ua->error_msg(_("Client name missing.\n")); + return 1; } } if (strcasecmp(ua->argk[i], NT_("job")) == 0) { @@ -1098,7 +1215,11 @@ static int estimate_cmd(UAContext *ua, const char *cmd) return 1; } continue; + } else { + ua->error_msg(_("Job name missing.\n")); + return 1; } + } if (strcasecmp(ua->argk[i], NT_("fileset")) == 0) { if (ua->argv[i]) { @@ -1112,6 +1233,9 @@ static int estimate_cmd(UAContext *ua, const char *cmd) return 1; } continue; + } else { + ua->error_msg(_("Fileset name missing.\n")); + return 1; } } if (strcasecmp(ua->argk[i], NT_("listing")) == 0) { @@ -1119,10 +1243,21 @@ static int estimate_cmd(UAContext *ua, const char *cmd) continue; } if (strcasecmp(ua->argk[i], NT_("level")) == 0) { - if (!get_level_from_name(ua->jcr, ua->argv[i])) { - ua->error_msg(_("Level %s not valid.\n"), ua->argv[i]); + if (ua->argv[i]) { + if (!get_level_from_name(ua->jcr, ua->argv[i])) { + ua->error_msg(_("Level \"%s\" not valid.\n"), ua->argv[i]); + } + continue; + } else { + ua->error_msg(_("Level value missing.\n")); + return 1; + } + } + if (strcasecmp(ua->argk[i], NT_("accurate")) == 0) { + if (!is_yesno(ua->argv[i], &accurate)) { + ua->error_msg(_("Invalid value for accurate. " + "It must be yes or no.\n")); } - continue; } } if (!job && !(client && fileset)) { @@ -1161,7 +1296,8 @@ static int estimate_cmd(UAContext *ua, const char *cmd) } jcr->job = job; - jcr->JobType = JT_BACKUP; + jcr->setJobType(JT_BACKUP); + jcr->start_time = time(NULL); init_jcr_job_record(jcr); if (!get_or_create_client_record(jcr)) { @@ -1180,6 +1316,17 @@ static int estimate_cmd(UAContext *ua, const char *cmd) return 1; } + /* The level string change if accurate mode is enabled */ + if (accurate >= 0) { + jcr->accurate = accurate; + } else { + jcr->accurate = job->accurate; + } + + if (!send_level_command(jcr)) { + goto bail_out; + } + if (!send_include_list(jcr)) { ua->error_msg(_("Error sending include list.\n")); goto bail_out; @@ -1190,19 +1337,24 @@ static int estimate_cmd(UAContext *ua, const char *cmd) goto bail_out; } - if (!send_level_command(jcr)) { + /* + * If the job is in accurate mode, we send the list of + * all files to FD. + */ + Dmsg1(40, "estimate accurate=%d\n", jcr->accurate); + if (!send_accurate_current_files(jcr)) { goto bail_out; } - bnet_fsend(jcr->file_bsock, "estimate listing=%d\n", listing); - while (bnet_recv(jcr->file_bsock) >= 0) { + jcr->file_bsock->fsend("estimate listing=%d\n", listing); + while (jcr->file_bsock->recv() >= 0) { ua->send_msg("%s", jcr->file_bsock->msg); } bail_out: if (jcr->file_bsock) { - bnet_sig(jcr->file_bsock, BNET_TERMINATE); - bnet_close(jcr->file_bsock); + jcr->file_bsock->signal(BNET_TERMINATE); + jcr->file_bsock->close(); jcr->file_bsock = NULL; } return 1; @@ -1321,9 +1473,7 @@ static void delete_job(UAContext *ua) sep = strchr(tok, ','); while (sep != NULL) { *sep = '\0'; - if (strchr(tok, '-')) { - delete_job_id_range(ua, tok); - } else { + if (!delete_job_id_range(ua, tok)) { JobId = str_to_int64(tok); do_job_delete(ua, JobId); } @@ -1331,9 +1481,7 @@ static void delete_job(UAContext *ua) sep = strchr(tok, ','); } /* pick up the last token */ - if (strchr(tok, '-')) { - delete_job_id_range(ua, tok); - } else { + if (!delete_job_id_range(ua, tok)) { JobId = str_to_int64(tok); do_job_delete(ua, JobId); } @@ -1354,12 +1502,15 @@ static void delete_job(UAContext *ua) /* * we call delete_job_id_range to parse range tokens and iterate over ranges */ -static void delete_job_id_range(UAContext *ua, char *tok) +static bool delete_job_id_range(UAContext *ua, char *tok) { char *tok2; JobId_t j,j1,j2; tok2 = strchr(tok, '-'); + if (!tok2) { + return false; + } *tok2 = '\0'; tok2++; j1 = str_to_int64(tok); @@ -1367,6 +1518,7 @@ static void delete_job_id_range(UAContext *ua, char *tok) for (j=j1; j<=j2; j++) { do_job_delete(ua, j); } + return true; } /* @@ -1388,6 +1540,7 @@ static int delete_volume(UAContext *ua) { MEDIA_DBR mr; char buf[1000]; + db_list_ctx lst; if (!select_media_dbr(ua, &mr)) { return 1; @@ -1396,14 +1549,31 @@ static int delete_volume(UAContext *ua) "and all Jobs saved on that volume from the Catalog\n"), mr.VolumeName); - bsnprintf(buf, sizeof(buf), _("Are you sure you want to delete Volume \"%s\"? (yes/no): "), - mr.VolumeName); - if (!get_yesno(ua, buf)) { + if (find_arg(ua, "yes") >= 0) { + ua->pint32_val = 1; /* Have "yes" on command line already" */ + } else { + bsnprintf(buf, sizeof(buf), _("Are you sure you want to delete Volume \"%s\"? (yes/no): "), + mr.VolumeName); + if (!get_yesno(ua, buf)) { + return 1; + } + } + if (!ua->pint32_val) { return 1; } - if (ua->pint32_val) { - db_delete_media_record(ua->jcr, ua->db, &mr); + + /* If not purged, do it */ + if (strcmp(mr.VolStatus, "Purged") != 0) { + if (!db_get_volume_jobids(ua->jcr, ua->db, &mr, &lst)) { + ua->error_msg(_("Can't list jobs on this volume\n")); + return 1; + } + if (lst.count) { + purge_jobs_from_catalog(ua, lst.list); + } } + + db_delete_media_record(ua->jcr, ua->db, &mr); return 1; } @@ -1433,6 +1603,7 @@ static int delete_pool(UAContext *ua) int memory_cmd(UAContext *ua, const char *cmd) { + garbage_collect_memory(); list_dir_status_header(ua); sm_dump(false, true); return 1; @@ -1474,15 +1645,15 @@ static void do_mount_cmd(UAContext *ua, const char *command) bstrncpy(dev_name, store.store->dev_name(), sizeof(dev_name)); bash_spaces(dev_name); if (slot > 0) { - bnet_fsend(sd, "%s %s drive=%d slot=%d", command, dev_name, drive, slot); + sd->fsend("%s %s drive=%d slot=%d", command, dev_name, drive, slot); } else { - bnet_fsend(sd, "%s %s drive=%d", command, dev_name, drive); + sd->fsend("%s %s drive=%d", command, dev_name, drive); } - while (bnet_recv(sd) >= 0) { + while (sd->recv() >= 0) { ua->send_msg("%s", sd->msg); } - bnet_sig(sd, BNET_TERMINATE); - bnet_close(sd); + sd->signal(BNET_TERMINATE); + sd->close(); jcr->store_bsock = NULL; } @@ -1566,6 +1737,8 @@ static int status_handler(void *ctx, int num_fields, char **row) int wait_cmd(UAContext *ua, const char *cmd) { JCR *jcr; + int i; + time_t stop_time = 0; /* * no args @@ -1590,6 +1763,11 @@ int wait_cmd(UAContext *ua, const char *cmd) return 1; } + i = find_arg_with_value(ua, NT_("timeout")); + if (i > 0 && ua->argv[i]) { + stop_time = time(NULL) + str_to_int64(ua->argv[i]); + } + /* we have jobid, jobname or ujobid argument */ uint32_t jobid = 0 ; @@ -1627,6 +1805,27 @@ int wait_cmd(UAContext *ua, const char *cmd) free_jcr(jcr); } break; + /* Wait for a mount request */ + } else if (strcasecmp(ua->argk[i], "mount") == 0) { + for (bool waiting=false; !waiting; ) { + foreach_jcr(jcr) { + if (jcr->JobId != 0 && + (jcr->JobStatus == JS_WaitMedia || jcr->JobStatus == JS_WaitMount)) { + waiting = true; + break; + } + } + endeach_jcr(jcr); + if (waiting) { + break; + } + if (stop_time && (time(NULL) >= stop_time)) { + ua->warning_msg(_("Wait on mount timed out\n")); + return 1; + } + bmicrosleep(1, 0); + } + return 1; } } @@ -1681,6 +1880,7 @@ int wait_cmd(UAContext *ua, const char *cmd) status = 2 ; /* Critical */ break; + case JS_Warnings: case JS_Terminated: status = 0 ; /* Ok */ break; @@ -1705,11 +1905,21 @@ int wait_cmd(UAContext *ua, const char *cmd) static int help_cmd(UAContext *ua, const char *cmd) { - unsigned int i; - - ua->send_msg(_(" Command Description\n ======= ===========\n")); + int i; + ua->send_msg(_(" Command Description\n ======= ===========\n")); for (i=0; isend_msg(_(" %-10s %s\n"), _(commands[i].key), _(commands[i].help)); + if (ua->argc == 2) { + if (!strcasecmp(ua->argk[1], commands[i].key)) { + ua->send_msg(_(" %-13s %s\n\nArguments:\n\t%s\n"), commands[i].key, + commands[i].help, commands[i].usage); + break; + } + } else { + ua->send_msg(_(" %-13s %s\n"), commands[i].key, commands[i].help); + } + } + if (i == comsize && ua->argc == 2) { + ua->send_msg(_("\nCan't find %s command.\n\n"), ua->argk[1]); } ua->send_msg(_("\nWhen at a prompt, entering a period cancels the command.\n\n")); return 1; @@ -1717,10 +1927,29 @@ static int help_cmd(UAContext *ua, const char *cmd) int qhelp_cmd(UAContext *ua, const char *cmd) { - unsigned int i; - + int i,j; + /* Want to display only commands */ + j = find_arg(ua, NT_("all")); + if (j >= 0) { + for (i=0; isend_msg("%s\n", commands[i].key); + } + return 1; + } + /* Want to display a specific help section */ + j = find_arg_with_value(ua, NT_("item")); + if (j >= 0 && ua->argk[j]) { + for (i=0; iargv[j])) { + ua->send_msg("%s\n", commands[i].usage); + break; + } + } + return 1; + } + /* Want to display everything */ for (i=0; isend_msg("%s %s\n", commands[i].key, _(commands[i].help)); + ua->send_msg("%s %s -- %s\n", commands[i].key, commands[i].help, commands[i].usage); } return 1; } @@ -1728,8 +1957,8 @@ int qhelp_cmd(UAContext *ua, const char *cmd) #if 1 static int version_cmd(UAContext *ua, const char *cmd) { - ua->send_msg(_("%s Version: %s (%s) %s %s %s\n"), my_name, VERSION, BDATE, - HOST_OS, DISTNAME, DISTVER); + ua->send_msg(_("%s Version: %s (%s) %s %s %s %s\n"), my_name, VERSION, BDATE, + HOST_OS, DISTNAME, DISTVER, NPRTB(director->verid)); return 1; } #else @@ -1752,6 +1981,22 @@ static int version_cmd(UAContext *ua, const char *cmd) } #endif +/* + * This call uses open_client_db() and force a + * new dedicated connection to the catalog + */ +bool open_new_client_db(UAContext *ua) +{ + bool ret; + + /* Force a new dedicated connection */ + close_db(ua); + ua->force_mult_db_connections = true; + ret = open_client_db(ua); + ua->force_mult_db_connections = false; + return ret; +} + /* * This call explicitly checks for a catalog=xxx and * if given, opens that catalog. It also checks for @@ -1837,6 +2082,8 @@ bool open_client_db(UAContext *ua) */ bool open_db(UAContext *ua) { + bool mult_db_conn; + if (ua->db) { return true; } @@ -1848,14 +2095,20 @@ bool open_db(UAContext *ua) } } + /* Some modules like bvfs need their own catalog connection */ + mult_db_conn = ua->catalog->mult_db_connections; + if (ua->force_mult_db_connections) { + mult_db_conn = true; + } + ua->jcr->catalog = ua->catalog; Dmsg0(100, "UA Open database\n"); - ua->db = db_init(ua->jcr, ua->catalog->db_driver, ua->catalog->db_name, + ua->db = db_init_database(ua->jcr, ua->catalog->db_driver, ua->catalog->db_name, ua->catalog->db_user, ua->catalog->db_password, ua->catalog->db_address, ua->catalog->db_port, ua->catalog->db_socket, - ua->catalog->mult_db_connections); + mult_db_conn, ua->catalog->disable_batch_insert); if (!ua->db || !db_open_database(ua->jcr, ua->db)) { ua->error_msg(_("Could not open catalog database \"%s\".\n"), ua->catalog->db_name);