* Version $Id$
*/
/*
- Copyright (C) 2000-2005 Kern Sibbald
+ Bacula® - The Network Backup Solution
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- version 2 as amended with additional clauses defined in the
- file LICENSE in the main source directory.
+ Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- the file LICENSE for additional details.
+ 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
+ License as published by the Free Software Foundation plus additions
+ that are listed in the file LICENSE.
- */
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ 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
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Bacula® is a registered trademark of John Walker.
+ The licensor of Bacula is the Free Software Foundation Europe
+ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+ Switzerland, email:ftf@fsfeurope.org.
+*/
/* The following is necessary so that we do not include
* the dummy external definition of DB.
#include "bacula.h"
#include "cats.h"
+static const int dbglevel = 500;
+
#if HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL
/* -----------------------------------------------------------------------
static int db_create_path_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar);
-/* Imported subroutines */
-extern void print_dashes(B_DB *mdb);
-extern void print_result(B_DB *mdb);
-extern int QueryDB(const char *file, int line, JCR *jcr, B_DB *db, char *select_cmd);
-extern int InsertDB(const char *file, int line, JCR *jcr, B_DB *db, char *select_cmd);
-extern int UpdateDB(const char *file, int line, JCR *jcr, B_DB *db, char *update_cmd);
-extern void split_path_and_file(JCR *jcr, B_DB *mdb, const char *fname);
-
-
/* Create a new record for the Job
* Returns: false on failure
* true on success
struct tm tm;
bool ok;
utime_t JobTDate;
- char ed1[30];
+ char ed1[30],ed2[30];
db_lock(mdb);
stime = jr->SchedTime;
ASSERT(stime != 0);
- localtime_r(&stime, &tm);
- strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm);
+ (void)localtime_r(&stime, &tm);
+ strftime(dt, sizeof(dt), "%Y-%m-%d %H:%M:%S", &tm);
JobTDate = (utime_t)stime;
/* Must create it */
Mmsg(mdb->cmd,
-"INSERT INTO Job (Job,Name,Type,Level,JobStatus,SchedTime,JobTDate) VALUES "
-"('%s','%s','%c','%c','%c','%s',%s)",
+"INSERT INTO Job (Job,Name,Type,Level,JobStatus,SchedTime,JobTDate,ClientId) "
+"VALUES ('%s','%s','%c','%c','%c','%s',%s,%s)",
jr->Job, jr->Name, (char)(jr->JobType), (char)(jr->JobLevel),
- (char)(jr->JobStatus), dt, edit_uint64(JobTDate, ed1));
+ (char)(jr->JobStatus), dt, edit_uint64(JobTDate, ed1),
+ edit_int64(jr->ClientId, ed2));
if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
Mmsg2(&mdb->errmsg, _("Create DB Job record %s failed. ERR=%s\n"),
return ok;
}
-/* Create a new migration, archive, copy
- * Returns: false on failure
- * true on success
- */
-bool
-db_create_mac_record(JCR *jcr, B_DB *mdb, MAC_DBR *mr)
-{
- char schedt[MAX_TIME_LENGTH], sdt[MAX_TIME_LENGTH], edt[MAX_TIME_LENGTH];
- time_t stime;
- struct tm tm;
- bool ok;
- utime_t JobTDate;
- char ed1[30], ed2[30];
-
- db_lock(mdb);
-
- stime = mr->SchedTime;
- ASSERT(stime != 0);
-
- localtime_r(&stime, &tm);
- strftime(schedt, sizeof(schedt), "%Y-%m-%d %T", &tm);
- JobTDate = (utime_t)stime;
- localtime_r(&mr->StartTime, &tm);
- strftime(sdt, sizeof(sdt), "%Y-%m-%d %T", &tm);
- localtime_r(&mr->EndTime, &tm);
- strftime(edt, sizeof(edt), "%Y-%m-%d %T", &tm);
-
- /* Must create it */
- Mmsg(mdb->cmd,
-"INSERT INTO MAC (OriginaJobId,JobType,JobLevel,SchedTime,"
-"StartTime,EndTime,JobTDate) VALUES "
-"('%s','%c','%c','%s','%s','%s',%s)",
- edit_int64(mr->OriginalJobId, ed1),
- (char)(mr->JobType), (char)(mr->JobLevel),
- schedt, sdt, edt, edit_uint64(JobTDate, ed2));
-
- if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
- Mmsg2(&mdb->errmsg, _("Create DB MAC record %s failed. ERR=%s\n"),
- mdb->cmd, sql_strerror(mdb));
- mr->JobId = 0;
- ok = false;
- } else {
- mr->JobId = sql_insert_id(mdb, NT_("Job"));
- ok = true;
- }
- db_unlock(mdb);
- return ok;
-}
-
/* Create a JobMedia record for medium used this job
* Returns: false on failure
}
count++;
+ /* Note, jm->Strip is not used and is not likely to be used
+ * in the near future, so I have removed it from the insert
+ * to save space in the DB. KES June 2006.
+ */
Mmsg(mdb->cmd,
"INSERT INTO JobMedia (JobId,MediaId,FirstIndex,LastIndex,"
- "StartFile,EndFile,StartBlock,EndBlock,VolIndex,Copy,Stripe) "
- "VALUES (%s,%s,%u,%u,%u,%u,%u,%u,%u,%u,%u)",
+ "StartFile,EndFile,StartBlock,EndBlock,VolIndex,Copy) "
+ "VALUES (%s,%s,%u,%u,%u,%u,%u,%u,%u,%u)",
edit_int64(jm->JobId, ed1),
edit_int64(jm->MediaId, ed2),
jm->FirstIndex, jm->LastIndex,
jm->StartFile, jm->EndFile, jm->StartBlock, jm->EndBlock,count,
- jm->Copy, jm->Stripe);
+ jm->Copy);
Dmsg0(300, mdb->cmd);
if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
{
int stat;
char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50], ed6[50], ed7[50], ed8[50];
+ char ed9[50], ed10[50], ed11[50], ed12[50];
struct tm tm;
db_lock(mdb);
"INSERT INTO Media (VolumeName,MediaType,MediaTypeId,PoolId,MaxVolBytes,"
"VolCapacityBytes,Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
"VolStatus,Slot,VolBytes,InChanger,VolReadTime,VolWriteTime,VolParts,"
-"EndFile,EndBlock,LabelType,StorageId,DeviceId,LocationId) "
-"VALUES ('%s','%s',0,%u,%s,%s,%d,%s,%s,%u,%u,'%s',%d,%s,%d,%s,%s,%d,0,0,%d,%s,0,0)",
+"EndFile,EndBlock,LabelType,StorageId,DeviceId,LocationId,"
+"ScratchPoolId,RecyclePoolId,Enabled)"
+"VALUES ('%s','%s',0,%u,%s,%s,%d,%s,%s,%u,%u,'%s',%d,%s,%d,%s,%s,%d,0,0,%d,%s,"
+"%s,%s,%s,%s,%d)",
mr->VolumeName,
mr->MediaType, mr->PoolId,
edit_uint64(mr->MaxVolBytes,ed1),
edit_uint64(mr->VolWriteTime, ed7),
mr->VolParts,
mr->LabelType,
- edit_int64(mr->StorageId, ed8)
+ edit_int64(mr->StorageId, ed8),
+ edit_int64(mr->DeviceId, ed9),
+ edit_int64(mr->LocationId, ed10),
+ edit_int64(mr->ScratchPoolId, ed11),
+ edit_int64(mr->RecyclePoolId, ed12),
+ mr->Enabled
);
if (mr->LabelDate == 0) {
mr->LabelDate = time(NULL);
}
- localtime_r(&mr->LabelDate, &tm);
- strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm);
+ (void)localtime_r(&mr->LabelDate, &tm);
+ strftime(dt, sizeof(dt), "%Y-%m-%d %H:%M:%S", &tm);
Mmsg(mdb->cmd, "UPDATE Media SET LabelDate='%s' "
"WHERE MediaId=%d", dt, mr->MediaId);
stat = UPDATE_DB(jcr, mdb, mdb->cmd);
if (fsr->CreateTime == 0 && fsr->cCreateTime[0] == 0) {
fsr->CreateTime = time(NULL);
}
- localtime_r(&fsr->CreateTime, &tm);
- strftime(fsr->cCreateTime, sizeof(fsr->cCreateTime), "%Y-%m-%d %T", &tm);
+ (void)localtime_r(&fsr->CreateTime, &tm);
+ strftime(fsr->cCreateTime, sizeof(fsr->cCreateTime), "%Y-%m-%d %H:%M:%S", &tm);
/* Must create it */
Mmsg(mdb->cmd, "INSERT INTO FileSet (FileSet,MD5,CreateTime) "
{
db_lock(mdb);
- Dmsg1(300, "Fname=%s\n", ar->fname);
- Dmsg0(500, "put_file_into_catalog\n");
+ Dmsg1(dbglevel, "Fname=%s\n", ar->fname);
+ Dmsg0(dbglevel, "put_file_into_catalog\n");
/*
* Make sure we have an acceptable attributes record.
*/
if (!db_create_filename_record(jcr, mdb, ar)) {
goto bail_out;
}
- Dmsg1(500, "db_create_filename_record: %s\n", mdb->esc_name);
+ Dmsg1(dbglevel, "db_create_filename_record: %s\n", mdb->esc_name);
if (!db_create_path_record(jcr, mdb, ar)) {
goto bail_out;
}
- Dmsg1(500, "db_create_path_record: %s\n", mdb->esc_name);
+ Dmsg1(dbglevel, "db_create_path_record: %s\n", mdb->esc_name);
/* Now create master File record */
if (!db_create_file_record(jcr, mdb, ar)) {
goto bail_out;
}
- Dmsg0(500, "db_create_file_record OK\n");
+ Dmsg0(dbglevel, "db_create_file_record OK\n");
- Dmsg3(300, "CreateAttributes Path=%s File=%s FilenameId=%d\n", mdb->path, mdb->fname, ar->FilenameId);
+ Dmsg3(dbglevel, "CreateAttributes Path=%s File=%s FilenameId=%d\n", mdb->path, mdb->fname, ar->FilenameId);
db_unlock(mdb);
return 1;