/* * List Volumes -- this should be moved to status.c */ void list_volumes(void sendit(const char *msg, int len, void *sarg), void *arg) { VOLRES *vol; POOL_MEM msg(PM_MESSAGE); int len; lock_volumes(); foreach_dlist(vol, vol_list) { DEVICE *dev = vol->dev; if (dev) { len = Mmsg(msg, "%s on device %s\n", vol->vol_name, dev->print_name()); sendit(msg.c_str(), len, arg); len = Mmsg(msg, " Reader=%d writers=%d devres=%d volinuse=%d\n", dev->can_read()?1:0, dev->num_writers, dev->num_reserved(), vol->is_in_use()); sendit(msg.c_str(), len, arg); } else { len = Mmsg(msg, "%s no device. volinuse= %d\n", vol->vol_name, vol->is_in_use()); sendit(msg.c_str(), len, arg); } }
static void mark_row(int row, bool mark) { char *file; int len; char new_mark[10]; gtk_clist_get_text(restore->list, row, FILE_COLUMN, &file); if (mark) { bstrncpy(new_mark, "x", sizeof(new_mark)); len = Mmsg(&restore->buf, "mark %s", file); } else { bstrncpy(new_mark, " ", sizeof(new_mark)); len = Mmsg(&restore->buf, "unmark %s", file); } gtk_clist_set_text(restore->list, row, CHECK_COLUMN, new_mark); /* strip trailing slash from directory name */ while (len > 1 && restore->buf[len-1] == '/') { restore->buf[len-1] = 0; } write_director(restore->buf); discard_to_prompt(); }
void db_list_base_files_for_job(JCR *jcr, B_DB *mdb, JobId_t jobid, OUTPUT_FORMATTER *sendit) { char ed1[50]; LIST_CTX lctx(jcr, mdb, sendit, NF_LIST); db_lock(mdb); /* * Stupid MySQL is NON-STANDARD ! */ if (db_get_type_index(mdb) == SQL_TYPE_MYSQL) { Mmsg(mdb->cmd, "SELECT CONCAT(Path.Path,Filename.Name) AS Filename " "FROM BaseFiles, File, Filename, Path " "WHERE BaseFiles.JobId=%s AND BaseFiles.BaseJobId = File.JobId " "AND BaseFiles.FileId = File.FileId " "AND Filename.FilenameId=File.FilenameId " "AND Path.PathId=File.PathId", edit_int64(jobid, ed1)); } else { Mmsg(mdb->cmd, "SELECT Path.Path||Filename.Name AS Filename " "FROM BaseFiles, File, Filename, Path " "WHERE BaseFiles.JobId=%s AND BaseFiles.BaseJobId = File.JobId " "AND BaseFiles.FileId = File.FileId " "AND Filename.FilenameId=File.FilenameId " "AND Path.PathId=File.PathId", edit_int64(jobid, ed1)); } sendit->array_start("files"); if (!db_big_sql_query(mdb, mdb->cmd, list_result, &lctx)) { goto bail_out; } sendit->array_end("files"); sql_free_result(mdb); bail_out: db_unlock(mdb); }
/* * Update the Job record at end of Job * * Returns: 0 on failure * 1 on success */ int db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr) { char dt[MAX_TIME_LENGTH]; char rdt[MAX_TIME_LENGTH]; time_t ttime; struct tm tm; int stat; char ed1[30], ed2[30], ed3[50], ed4[50]; btime_t JobTDate; char PriorJobId[50]; if (jr->PriorJobId) { bstrncpy(PriorJobId, edit_int64(jr->PriorJobId, ed1), sizeof(PriorJobId)); } else { bstrncpy(PriorJobId, "0", sizeof(PriorJobId)); } ttime = jr->EndTime; (void)localtime_r(&ttime, &tm); strftime(dt, sizeof(dt), "%Y-%m-%d %H:%M:%S", &tm); if (jr->RealEndTime == 0) { jr->RealEndTime = jr->EndTime; } ttime = jr->RealEndTime; (void)localtime_r(&ttime, &tm); strftime(rdt, sizeof(rdt), "%Y-%m-%d %H:%M:%S", &tm); JobTDate = ttime; db_lock(mdb); Mmsg(mdb->cmd, "UPDATE Job SET JobStatus='%c',EndTime='%s'," "ClientId=%u,JobBytes=%s,ReadBytes=%s,JobFiles=%u,JobErrors=%u,VolSessionId=%u," "VolSessionTime=%u,PoolId=%u,FileSetId=%u,JobTDate=%s," "RealEndTime='%s',PriorJobId=%s,HasBase=%u,PurgedFiles=%u WHERE JobId=%s", (char)(jr->JobStatus), dt, jr->ClientId, edit_uint64(jr->JobBytes, ed1), edit_uint64(jr->ReadBytes, ed4), jr->JobFiles, jr->JobErrors, jr->VolSessionId, jr->VolSessionTime, jr->PoolId, jr->FileSetId, edit_uint64(JobTDate, ed2), rdt, PriorJobId, jr->HasBase, jr->PurgedFiles, edit_int64(jr->JobId, ed3)); stat = UPDATE_DB(jcr, mdb, mdb->cmd); db_unlock(mdb); return stat; }
/* * (Un)mount the device (for tape devices) */ static bool do_mount(DCR *dcr, int mount, int dotimeout) { DEVRES *device = dcr->dev->device; POOL_MEM ocmd(PM_FNAME); POOLMEM *results; char *icmd; int status, tries; berrno be; Dsm_check(200); if (mount) { icmd = device->mount_command; } else { icmd = device->unmount_command; } dcr->dev->edit_mount_codes(ocmd, icmd); Dmsg2(100, "do_mount: cmd=%s mounted=%d\n", ocmd.c_str(), dcr->dev->is_mounted()); if (dotimeout) { /* Try at most 10 times to (un)mount the device. This should perhaps be configurable. */ tries = 10; } else { tries = 1; } results = get_memory(4000); /* If busy retry each second */ Dmsg1(100, "do_mount run_prog=%s\n", ocmd.c_str()); while ((status = run_program_full_output(ocmd.c_str(), dcr->dev->max_open_wait / 2, results)) != 0) { if (tries-- > 0) { continue; } Dmsg5(100, "Device %s cannot be %smounted. stat=%d result=%s ERR=%s\n", dcr->dev->print_name(), (mount ? "" : "un"), status, results, be.bstrerror(status)); Mmsg(dcr->dev->errmsg, _("Device %s cannot be %smounted. ERR=%s\n"), dcr->dev->print_name(), (mount ? "" : "un"), be.bstrerror(status)); free_pool_memory(results); Dmsg0(200, "============ mount=0\n"); Dsm_check(200); return false; } free_pool_memory(results); Dmsg1(200, "============ mount=%d\n", mount); return true; }
bool db_update_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr) { bool retval; char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50], ed6[50]; char esc[MAX_ESCAPE_NAME_LENGTH]; db_lock(mdb); mdb->db_escape_string(jcr, esc, pr->LabelFormat, strlen(pr->LabelFormat)); Mmsg(mdb->cmd, "SELECT count(*) from Media WHERE PoolId=%s", edit_int64(pr->PoolId, ed4)); pr->NumVols = get_sql_record_max(jcr, mdb); Dmsg1(400, "NumVols=%d\n", pr->NumVols); Mmsg(mdb->cmd, "UPDATE Pool SET NumVols=%u,MaxVols=%u,UseOnce=%d,UseCatalog=%d," "AcceptAnyVolume=%d,VolRetention='%s',VolUseDuration='%s'," "MaxVolJobs=%u,MaxVolFiles=%u,MaxVolBytes=%s,Recycle=%d," "AutoPrune=%d,LabelType=%d,LabelFormat='%s',RecyclePoolId=%s," "ScratchPoolId=%s,ActionOnPurge=%d,MinBlockSize=%d,MaxBlockSize=%d WHERE PoolId=%s", pr->NumVols, pr->MaxVols, pr->UseOnce, pr->UseCatalog, pr->AcceptAnyVolume, edit_uint64(pr->VolRetention, ed1), edit_uint64(pr->VolUseDuration, ed2), pr->MaxVolJobs, pr->MaxVolFiles, edit_uint64(pr->MaxVolBytes, ed3), pr->Recycle, pr->AutoPrune, pr->LabelType, esc, edit_int64(pr->RecyclePoolId,ed5), edit_int64(pr->ScratchPoolId,ed6), pr->ActionOnPurge, pr->MinBlocksize, pr->MaxBlocksize, ed4); retval = UPDATE_DB(jcr, mdb, mdb->cmd); db_unlock(mdb); return retval; }
void db_list_joblog_records(JCR *jcr, B_DB *mdb, uint32_t JobId, OUTPUT_FORMATTER *sendit, e_list_type type) { char ed1[50]; if (JobId <= 0) { return; } db_lock(mdb); if (type == VERT_LIST) { Mmsg(mdb->cmd, "SELECT Time, LogText FROM Log " "WHERE Log.JobId=%s ORDER BY Log.LogId", edit_int64(JobId, ed1)); } else { Mmsg(mdb->cmd, "SELECT Time, LogText FROM Log " "WHERE Log.JobId=%s ORDER BY Log.LogId", edit_int64(JobId, ed1)); /* * When something else then a vertical list is requested set the list type * to RAW_LIST e.g. non formated raw data as that makes the only sense for * the logtext output. The logtext already has things like \n etc in it * so we should just dump the raw content out for the best visible output. */ type = RAW_LIST; } if (!QUERY_DB(jcr, mdb, mdb->cmd)) { goto bail_out; } sendit->array_start("joblog"); list_result(jcr, mdb, sendit, type); sendit->array_end("joblog"); sql_free_result(mdb); bail_out: db_unlock(mdb); }
/* Dump the item table format to a text file (used by plugin) */ int ConfigFile::serialize(POOLMEM **buf) { int len; POOLMEM *tmp; if (!items) { **buf = 0; return 0; } len = Mmsg(buf, "# Plugin configuration file\n# Version %d\n", version); tmp = get_pool_memory(PM_MESSAGE); for (int i = 0; items[i].name; i++) { if (items[i].comment) { Mmsg(tmp, "OptPrompt=%s\n", items[i].comment); pm_strcat(buf, tmp); } if (items[i].default_value) { Mmsg(tmp, "OptDefault=%s\n", items[i].default_value); pm_strcat(buf, tmp); } if (items[i].required) { Mmsg(tmp, "OptRequired=yes\n"); pm_strcat(buf, tmp); } /* variable = @INT64@ */ Mmsg(tmp, "%s=%s\n\n", items[i].name, ini_get_store_code(items[i].handler)); len = pm_strcat(buf, tmp); } free_pool_memory(tmp); return len ; }
/* * Update Counters record * Returns: 0 on failure * 1 on success */ int db_update_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr) { char esc[MAX_ESCAPE_NAME_LENGTH]; db_lock(mdb); mdb->db_escape_string(jcr, esc, cr->Counter, strlen(cr->Counter)); Mmsg(mdb->cmd, "UPDATE Counters SET Counters.MinValue=%d,Counters.MaxValue=%d,CurrentValue=%d," "WrapCounter='%s' WHERE Counter='%s'", cr->MinValue, cr->MaxValue, cr->CurrentValue, cr->WrapCounter, esc); int stat = UPDATE_DB(jcr, mdb, mdb->cmd); db_unlock(mdb); return stat; }
/* * Find the last job start time for the specified JobLevel * * StartTime is returned in stime * * Returns: false on failure * true on success, jr is unchanged, but stime is set */ bool db_find_last_job_start_time(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM **stime, int JobLevel) { SQL_ROW row; char ed1[50], ed2[50]; db_lock(mdb); pm_strcpy(stime, "0000-00-00 00:00:00"); /* default */ Mmsg(mdb->cmd, "SELECT StartTime FROM Job WHERE JobStatus IN ('T','W') AND Type='%c' AND " "Level='%c' AND Name='%s' AND ClientId=%s AND FileSetId=%s " "ORDER BY StartTime DESC LIMIT 1", jr->JobType, JobLevel, jr->Name, edit_int64(jr->ClientId, ed1), edit_int64(jr->FileSetId, ed2)); if (!QUERY_DB(jcr, mdb, mdb->cmd)) { Mmsg2(&mdb->errmsg, _("Query error for start time request: ERR=%s\nCMD=%s\n"), sql_strerror(mdb), mdb->cmd); goto bail_out; } if ((row = sql_fetch_row(mdb)) == NULL) { sql_free_result(mdb); Mmsg(mdb->errmsg, _("No prior Full backup Job record found.\n")); goto bail_out; } Dmsg1(100, "Got start time: %s\n", row[0]); pm_strcpy(stime, row[0]); sql_free_result(mdb); db_unlock(mdb); return true; bail_out: db_unlock(mdb); return false; }
/* * Dump the item table format to a text file (used by plugin) */ int ConfigFile::serialize(POOL_MEM *buf) { int len; POOL_MEM tmp(PM_MESSAGE); if (!items) { char *p; p = buf->c_str(); p[0] = '\0'; return 0; } len = Mmsg(buf, "# Plugin configuration file\n# Version %d\n", version); for (int i = 0; items[i].name; i++) { if (items[i].comment) { Mmsg(tmp, "OptPrompt=%s\n", items[i].comment); pm_strcat(buf, tmp.c_str()); } if (items[i].default_value) { Mmsg(tmp, "OptDefault=%s\n", items[i].default_value); pm_strcat(buf, tmp.c_str()); } if (items[i].required) { Mmsg(tmp, "OptRequired=yes\n"); pm_strcat(buf, tmp.c_str()); } /* variable = @INT64@ */ Mmsg(tmp, "%s=%s\n\n", items[i].name, ini_get_store_code(items[i].type)); len = pm_strcat(buf, tmp.c_str()); } return len ; }
/* * Open and read the state file for the daemon */ void read_state_file(char *dir, const char *progname, int port) { int sfd; ssize_t status; bool ok = false; POOLMEM *fname = get_pool_memory(PM_FNAME); struct s_state_hdr hdr; int hdr_size = sizeof(hdr); Mmsg(&fname, "%s/%s.%d.state", dir, progname, port); /* If file exists, see what we have */ // Dmsg1(10, "O_BINARY=%d\n", O_BINARY); if ((sfd = open(fname, O_RDONLY|O_BINARY)) < 0) { berrno be; Dmsg3(010, "Could not open state file. sfd=%d size=%d: ERR=%s\n", sfd, sizeof(hdr), be.bstrerror()); goto bail_out; } if ((status = read(sfd, &hdr, hdr_size)) != hdr_size) { berrno be; Dmsg4(010, "Could not read state file. sfd=%d status=%d size=%d: ERR=%s\n", sfd, (int)status, hdr_size, be.bstrerror()); goto bail_out; } if (hdr.version != state_hdr.version) { Dmsg2(010, "Bad hdr version. Wanted %d got %d\n", state_hdr.version, hdr.version); goto bail_out; } hdr.id[13] = 0; if (!bstrcmp(hdr.id, state_hdr.id)) { Dmsg0(000, "State file header id invalid.\n"); goto bail_out; } // Dmsg1(010, "Read header of %d bytes.\n", sizeof(hdr)); if (!read_last_jobs_list(sfd, hdr.last_jobs_addr)) { goto bail_out; } ok = true; bail_out: if (sfd >= 0) { close(sfd); } if (!ok) { unlink(fname); } free_pool_memory(fname); }
/* * See in the tree with selected files what files were selected to be restored. */ static inline int set_files_to_restore(JCR *jcr, struct ndm_job_param *job, int32_t FileIndex, const char *restore_prefix, const char *ndmp_filesystem) { int len; int cnt = 0; TREE_NODE *node, *parent; POOL_MEM restore_pathname, tmp; node = first_tree_node(jcr->restore_tree_root); while (node) { /* * See if this is the wanted FileIndex and the user asked to extract it. */ if (node->FileIndex == FileIndex && node->extract) { pm_strcpy(restore_pathname, node->fname); /* * Walk up the parent until we hit the head of the list. */ for (parent = node->parent; parent; parent = parent->parent) { pm_strcpy(tmp, restore_pathname.c_str()); Mmsg(restore_pathname, "%s/%s", parent->fname, tmp.c_str()); } /* * We only want to restore the non pseudo NDMP names e.g. not the full backup stream name. */ if (!bstrncmp(restore_pathname.c_str(), "/@NDMP/", 7)) { /* * See if we need to strip the prefix from the filename. */ len = strlen(ndmp_filesystem); if (bstrncmp(restore_pathname.c_str(), ndmp_filesystem, len)) { add_to_namelist(job, restore_pathname.c_str() + len, restore_prefix, (char *)"", (char *)"", NDMP_INVALID_U_QUAD); } else { add_to_namelist(job, restore_pathname.c_str(), restore_prefix, (char *)"", (char *)"", NDMP_INVALID_U_QUAD); } cnt++; } } node = next_tree_node(node); } return cnt; }
/* * Update Counters record * Returns: false on failure * true on success */ bool db_update_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr) { bool retval; char esc[MAX_ESCAPE_NAME_LENGTH]; db_lock(mdb); mdb->db_escape_string(jcr, esc, cr->Counter, strlen(cr->Counter)); Mmsg(mdb->cmd, update_counter_values[mdb->db_get_type_index()], cr->MinValue, cr->MaxValue, cr->CurrentValue, cr->WrapCounter, esc); retval = UPDATE_DB(jcr, mdb, mdb->cmd); db_unlock(mdb); return retval; }
/* * Update Long term statistics with all jobs that were run before * age seconds */ int db_update_stats(JCR *jcr, B_DB *mdb, utime_t age) { char ed1[30]; int rows; utime_t now = (utime_t)time(NULL); edit_uint64(now - age, ed1); db_lock(mdb); Mmsg(mdb->cmd, fill_jobhisto, ed1); QUERY_DB(jcr, mdb, mdb->cmd); /* TODO: get a message ? */ rows = sql_affected_rows(mdb); db_unlock(mdb); return rows; }
/* Prune Job stat records from the database. * */ int prune_stats(UAContext *ua, utime_t retention) { char ed1[50]; POOL_MEM query(PM_MESSAGE); utime_t now = (utime_t)time(NULL); db_lock(ua->db); Mmsg(query, "DELETE FROM JobHisto WHERE JobTDate < %s", edit_int64(now - retention, ed1)); db_sql_query(ua->db, query.c_str()); db_unlock(ua->db); ua->info_msg(_("Pruned Jobs from JobHisto catalog.\n")); return true; }
/* * Fill the rx->BaseJobIds and display the list */ static void get_and_display_basejobs(UAContext *ua, RESTORE_CTX *rx) { db_list_ctx jobids; if (!db_get_used_base_jobids(ua->jcr, ua->db, rx->JobIds, &jobids)) { ua->warning_msg("%s", db_strerror(ua->db)); } if (jobids.count) { POOL_MEM q; Mmsg(q, uar_print_jobs, jobids.list); ua->send_msg(_("The restore will use the following job(s) as Base\n")); db_list_sql_query(ua->jcr, ua->db, q.c_str(), prtit, ua, 1, HORZ_LIST); } pm_strcpy(rx->BaseJobIds, jobids.list); }
/* * Delete the pid file if we created it */ int delete_pid_file(char *dir, const char *progname, int port) { #if !defined(HAVE_WIN32) POOLMEM *fname = get_pool_memory(PM_FNAME); if (!del_pid_file_ok) { free_pool_memory(fname); return 0; } del_pid_file_ok = FALSE; Mmsg(&fname, "%s/%s.%d.pid", dir, progname, port); unlink(fname); free_pool_memory(fname); #endif return 1; }
/* * Reset Quota Gracetime * * Returns: false on failure * true on success */ bool db_reset_quota_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr) { bool retval; char ed1[50]; db_lock(mdb); Mmsg(mdb->cmd, "UPDATE Quota SET GraceTime='0', QuotaLimit='0' WHERE ClientId='%s'", edit_uint64(cr->ClientId, ed1)); retval = UPDATE_DB(jcr, mdb, mdb->cmd); db_unlock(mdb); return retval; }
void write_state_file(char *dir, const char *progname, int port) { int sfd; bool ok = false; POOLMEM *fname = get_pool_memory(PM_FNAME); P(state_mutex); /* Only one job at a time can call here */ Mmsg(&fname, "%s/%s.%d.state", dir, progname, port); /* Create new state file */ unlink(fname); if ((sfd = open(fname, O_CREAT|O_WRONLY|O_BINARY, 0640)) < 0) { berrno be; Dmsg2(000, "Could not create state file. %s ERR=%s\n", fname, be.bstrerror()); Emsg2(M_ERROR, 0, _("Could not create state file. %s ERR=%s\n"), fname, be.bstrerror()); goto bail_out; } if (write(sfd, &state_hdr, sizeof(state_hdr)) != sizeof(state_hdr)) { berrno be; Dmsg1(000, "Write hdr error: ERR=%s\n", be.bstrerror()); goto bail_out; } // Dmsg1(010, "Wrote header of %d bytes\n", sizeof(state_hdr)); state_hdr.last_jobs_addr = sizeof(state_hdr); state_hdr.reserved[0] = write_last_jobs_list(sfd, state_hdr.last_jobs_addr); // Dmsg1(010, "write last job end = %d\n", (int)state_hdr.reserved[0]); if (lseek(sfd, 0, SEEK_SET) < 0) { berrno be; Dmsg1(000, "lseek error: ERR=%s\n", be.bstrerror()); goto bail_out; } if (write(sfd, &state_hdr, sizeof(state_hdr)) != sizeof(state_hdr)) { berrno be; Pmsg1(000, _("Write final hdr error: ERR=%s\n"), be.bstrerror()); goto bail_out; } ok = true; // Dmsg1(010, "rewrote header = %d\n", sizeof(state_hdr)); bail_out: if (sfd >= 0) { close(sfd); } if (!ok) { unlink(fname); } V(state_mutex); free_pool_memory(fname); }
/* * Update Quota Softlimit * * Returns: false on failure * true on success */ bool db_update_quota_softlimit(JCR *jcr, B_DB *mdb, JOB_DBR *jr) { bool retval; char ed1[50], ed2[50]; db_lock(mdb); Mmsg(mdb->cmd, "UPDATE Quota SET QuotaLimit=%s WHERE ClientId='%s'", edit_uint64((jr->JobSumTotalBytes + jr->JobBytes), ed1), edit_uint64(jr->ClientId, ed2)); retval = UPDATE_DB(jcr, mdb, mdb->cmd); db_unlock(mdb); return retval; }
/* ---------------------------------------------------------------- * Handle data type. Import/Export * ---------------------------------------------------------------- */ bool ini_store_str(LEX *lc, ConfigFile *inifile, ini_items *item) { if (!lc) { Mmsg(inifile->edit, "%s", item->val.strval); return true; } if (lex_get_token(lc, T_STRING) == T_ERROR) { return false; } /* If already allocated, free first */ if (item->found && item->val.strval) { free(item->val.strval); } item->val.strval = bstrdup(lc->str); scan_to_eol(lc); return true; }
/* Update the attributes record by adding the file digest */ bool db_add_digest_to_file_record(JCR *jcr, B_DB *mdb, FileId_t FileId, char *digest, int type) { bool retval; char ed1[50]; int len = strlen(digest); db_lock(mdb); mdb->esc_name = check_pool_memory_size(mdb->esc_name, len*2+1); mdb->db_escape_string(jcr, mdb->esc_name, digest, len); Mmsg(mdb->cmd, "UPDATE File SET MD5='%s' WHERE FileId=%s", mdb->esc_name, edit_int64(FileId, ed1)); retval = UPDATE_DB(jcr, mdb, mdb->cmd); db_unlock(mdb); return retval; }
/* * Get freespace using OS calls * TODO: See if it's working with mount commands */ bool DEVICE::get_os_device_freespace() { int64_t freespace, totalspace; if (!is_file()) { return true; } if (fs_get_free_space(dev_name, &freespace, &totalspace) == 0) { set_freespace(freespace, totalspace, 0, true); Mmsg(errmsg, ""); return true; } else { set_freespace(0, 0, 0, false); /* No valid freespace */ } return false; }
/* Check that the tables correspond to the version we want */ bool check_tables_version(JCR *jcr, B_DB *mdb) { uint32_t bareos_db_version = 0; const char *query = "SELECT VersionId FROM Version"; if (!db_sql_query(mdb, query, db_int_handler, (void *)&bareos_db_version)) { Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg); return false; } if (bareos_db_version != BDB_VERSION) { Mmsg(mdb->errmsg, "Version error for database \"%s\". Wanted %d, got %d\n", mdb->get_db_name(), BDB_VERSION, bareos_db_version); Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg); return false; } return true; }
static void update_volretention(UAContext *ua, char *val, MEDIA_DBR *mr) { char ed1[150], ed2[50]; POOL_MEM query(PM_MESSAGE); if (!duration_to_utime(val, &mr->VolRetention)) { ua->error_msg(_("Invalid retention period specified: %s\n"), val); return; } Mmsg(query, "UPDATE Media SET VolRetention=%s WHERE MediaId=%s", edit_uint64(mr->VolRetention, ed1), edit_int64(mr->MediaId,ed2)); if (!db_sql_query(ua->db, query.c_str(), NULL, NULL)) { ua->error_msg("%s", db_strerror(ua->db)); } else { ua->info_msg(_("New retention period is: %s\n"), edit_utime(mr->VolRetention, ed1, sizeof(ed1))); } }
/* * Get the JobId and FileIndexes of all files in the specified table */ static bool insert_table_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *table) { strip_trailing_junk(table); Mmsg(rx->query, uar_jobid_fileindex_from_table, table); rx->found = false; /* Find and insert jobid and File Index */ if (!db_sql_query(ua->db, rx->query, jobid_fileindex_handler, (void *)rx)) { ua->error_msg(_("Query failed: %s. ERR=%s\n"), rx->query, db_strerror(ua->db)); } if (!rx->found) { ua->error_msg(_("No table found: %s\n"), table); return true; } return true; }
static void update_volmaxbytes(UAContext *ua, char *val, MEDIA_DBR *mr) { uint64_t maxbytes; char ed1[50], ed2[50]; POOL_MEM query(PM_MESSAGE); if (!size_to_uint64(val, strlen(val), &maxbytes)) { ua->error_msg(_("Invalid max. bytes specification: %s\n"), val); return; } Mmsg(query, "UPDATE Media SET MaxVolBytes=%s WHERE MediaId=%s", edit_uint64(maxbytes, ed1), edit_int64(mr->MediaId, ed2)); if (!db_sql_query(ua->db, query.c_str(), NULL, NULL)) { ua->error_msg("%s", db_strerror(ua->db)); } else { ua->info_msg(_("New Max bytes is: %s\n"), edit_uint64(maxbytes, ed1)); } }
/* * Update Quota record * * Returns: false on failure * true on success */ bool db_update_quota_gracetime(JCR *jcr, B_DB *mdb, JOB_DBR *jr) { bool retval; char ed1[50], ed2[50]; time_t now = time(NULL); db_lock(mdb); Mmsg(mdb->cmd, "UPDATE Quota SET GraceTime=%s WHERE ClientId='%s'", edit_uint64(now, ed1), edit_uint64(jr->ClientId, ed2)); retval = UPDATE_DB(jcr, mdb, mdb->cmd); db_unlock(mdb); return retval; }
static void update_volinchanger(UAContext *ua, char *val, MEDIA_DBR *mr) { int InChanger; char ed1[50]; POOL_MEM query(PM_MESSAGE); if (!is_yesno(val, &InChanger)) { ua->error_msg(_("Invalid value. It must be yes or no.\n")); return; } Mmsg(query, "UPDATE Media SET InChanger=%d WHERE MediaId=%s", InChanger, edit_int64(mr->MediaId, ed1)); if (!db_sql_query(ua->db, query.c_str(), NULL, NULL)) { ua->error_msg("%s", db_strerror(ua->db)); } else { ua->info_msg(_("New InChanger flag is: %s\n"), InChanger==1?_("yes"):_("no")); } }