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.
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.
}
/* Must create it */
- Mmsg(mdb->cmd, "INSERT INTO Counters (Counter,MinValue,MaxValue,CurrentValue,"
+ Mmsg(mdb->cmd, "INSERT INTO Counters (Counter,\"MinValue\",\"MaxValue\",CurrentValue,"
"WrapCounter) VALUES ('%s','%d','%d','%d','%s')",
cr->Counter, cr->MinValue, cr->MaxValue, cr->CurrentValue,
cr->WrapCounter);
}
/*
- * Returns 1 if OK
- * 0 if failed
+ * Returns true if OK
+ * false if failed
*/
bool db_write_batch_file_records(JCR *jcr)
{
+ bool retval = false;
int JobStatus = jcr->JobStatus;
if (!jcr->batch_started) { /* no files to backup ? */
return true;
}
if (job_canceled(jcr)) {
- return false;
+ goto bail_out;
}
Dmsg1(50,"db_create_file_record changes=%u\n",jcr->db_batch->changes);
jcr->JobStatus = JS_AttrInserting;
if (!sql_batch_end(jcr, jcr->db_batch, NULL)) {
Jmsg1(jcr, M_FATAL, 0, "Batch end %s\n", jcr->db_batch->errmsg);
- return false;
+ goto bail_out;
}
if (job_canceled(jcr)) {
- return false;
+ goto bail_out;
}
-
- /* we have to lock tables */
+ /*
+ * We have to lock tables
+ */
if (!db_sql_query(jcr->db_batch, sql_batch_lock_path_query, NULL, NULL)) {
Jmsg1(jcr, M_FATAL, 0, "Lock Path table %s\n", jcr->db_batch->errmsg);
- return false;
+ goto bail_out;
}
if (!db_sql_query(jcr->db_batch, sql_batch_fill_path_query, NULL, NULL)) {
Jmsg1(jcr, M_FATAL, 0, "Fill Path table %s\n",jcr->db_batch->errmsg);
db_sql_query(jcr->db_batch, sql_batch_unlock_tables_query, NULL, NULL);
- return false;
+ goto bail_out;
}
if (!db_sql_query(jcr->db_batch, sql_batch_unlock_tables_query,NULL,NULL)) {
Jmsg1(jcr, M_FATAL, 0, "Unlock Path table %s\n", jcr->db_batch->errmsg);
- return false;
+ goto bail_out;
}
- /* we have to lock tables */
+ /*
+ * We have to lock tables
+ */
if (!db_sql_query(jcr->db_batch,sql_batch_lock_filename_query,NULL, NULL)) {
Jmsg1(jcr, M_FATAL, 0, "Lock Filename table %s\n", jcr->db_batch->errmsg);
- return false;
+ goto bail_out;
}
if (!db_sql_query(jcr->db_batch,sql_batch_fill_filename_query, NULL,NULL)) {
Jmsg1(jcr,M_FATAL,0,"Fill Filename table %s\n",jcr->db_batch->errmsg);
db_sql_query(jcr->db_batch, sql_batch_unlock_tables_query, NULL, NULL);
- return false;
+ goto bail_out;
}
if (!db_sql_query(jcr->db_batch, sql_batch_unlock_tables_query,NULL,NULL)) {
Jmsg1(jcr, M_FATAL, 0, "Unlock Filename table %s\n", jcr->db_batch->errmsg);
- return false;
+ goto bail_out;
}
if (!db_sql_query(jcr->db_batch,
- "INSERT INTO File (FileIndex, JobId, PathId, FilenameId, LStat, MD5)"
+ "INSERT INTO File (FileIndex, JobId, PathId, FilenameId, LStat, MD5) "
"SELECT batch.FileIndex, batch.JobId, Path.PathId, "
"Filename.FilenameId,batch.LStat, batch.MD5 "
"FROM batch "
NULL,NULL))
{
Jmsg1(jcr, M_FATAL, 0, "Fill File table %s\n", jcr->db_batch->errmsg);
- return false;
+ goto bail_out;
}
+ jcr->JobStatus = JobStatus; /* reset entry status */
+ retval = true;
+
+bail_out:
db_sql_query(jcr->db_batch, "DROP TABLE batch", NULL,NULL);
- jcr->JobStatus = JobStatus; /* reset entry status */
- return true;
+ return retval;
}
/**
#endif /* ! HAVE_BATCH_FILE_INSERT */
-
-/* List of SQL commands to create temp table and indicies */
-const char *create_temp_basefile[5] = {
- /* MySQL */
- "CREATE TEMPORARY TABLE basefile%lld ("
-// "CREATE TABLE basefile%lld ("
- "Path BLOB NOT NULL,"
- "Name BLOB NOT NULL)",
-
- /* Postgresql */
- "CREATE TEMPORARY TABLE basefile%lld ("
-// "CREATE TABLE basefile%lld ("
- "Path TEXT,"
- "Name TEXT)",
-
- /* SQLite */
- "CREATE TEMPORARY TABLE basefile%lld ("
- "Path TEXT,"
- "Name TEXT)",
-
- /* SQLite3 */
- "CREATE TEMPORARY TABLE basefile%lld ("
- "Path TEXT,"
- "Name TEXT)",
-
- /* Ingres */
- "DECLARE GLOBAL TEMPORARY TABLE basefile%lld ("
- "Path TEXT NOT NULL,"
- "Name TEXT NOT NULL)"
- "ON COMMIT PRESERVE ROWS WITH NORECOVERY"
-};
-
/**
* Create file attributes record, or base file attributes record
*/
goto bail_out;
}
Mmsg(buf, select_recent_version[db_type], jobids, jobids);
- Mmsg(mdb->cmd,
-"CREATE TEMPORARY TABLE new_basefile%lld AS "
-//"CREATE TABLE new_basefile%lld AS "
- "SELECT Path.Path AS Path, Filename.Name AS Name, Temp.FileIndex AS FileIndex,"
- "Temp.JobId AS JobId, Temp.LStat AS LStat, Temp.FileId AS FileId, "
- "Temp.MD5 AS MD5 "
- "FROM ( %s ) AS Temp "
- "JOIN Filename ON (Filename.FilenameId = Temp.FilenameId) "
- "JOIN Path ON (Path.PathId = Temp.PathId) "
- "WHERE Temp.FileIndex > 0",
- (uint64_t)jcr->JobId, buf.c_str());
+ Mmsg(mdb->cmd, create_temp_new_basefile[db_type], (uint64_t)jcr->JobId, buf.c_str());
ret = db_sql_query(mdb, mdb->cmd, NULL, NULL);
bail_out:
return ret;
}
-
/**
* Create Restore Object record in B_DB
*
bool db_create_restore_object_record(JCR *jcr, B_DB *mdb, ROBJECT_DBR *ro)
{
bool stat;
- POOLMEM *esc_obj = get_pool_memory(PM_MESSAGE);
+ int plug_name_len;
+ POOLMEM *esc_plug_name = get_pool_memory(PM_MESSAGE);
+
db_lock(mdb);
- Dmsg1(dbglevel, "Fname=%s\n", ro->fname);
+ Dmsg1(dbglevel, "Oname=%s\n", ro->object_name);
Dmsg0(dbglevel, "put_object_into_catalog\n");
- split_path_and_file(jcr, mdb, ro->full_fname);
-
+ mdb->fnl = strlen(ro->object_name);
mdb->esc_name = check_pool_memory_size(mdb->esc_name, mdb->fnl*2+1);
- db_escape_string(jcr, mdb, mdb->esc_name, mdb->fname, mdb->fnl);
+ db_escape_string(jcr, mdb, mdb->esc_name, ro->object_name, mdb->fnl);
- mdb->esc_path = check_pool_memory_size(mdb->esc_path, mdb->pnl*2+1);
- db_escape_string(jcr, mdb, mdb->esc_path, mdb->path, mdb->pnl);
+ db_escape_object(jcr, mdb, ro->object, ro->object_len);
- esc_obj = check_pool_memory_size(esc_obj, ro->object_len*2+1);
- db_escape_string(jcr, mdb, esc_obj, ro->object, ro->object_len);
+ plug_name_len = strlen(ro->plugin_name);
+ esc_plug_name = check_pool_memory_size(esc_plug_name, plug_name_len*2+1);
+ db_escape_string(jcr, mdb, esc_plug_name, ro->plugin_name, plug_name_len);
Mmsg(mdb->cmd,
- "INSERT INTO RestoreObject (Fname,Path,PluginName,RestoreObject,"
- "ObjectLength,ObjectIndex,ObjectType,FileIndex,JobId) VALUES"
- "('%s','%s','%s','%s',%d,%d,%d,%d,%u)",
- mdb->esc_name, mdb->esc_path, mdb->esc_path, esc_obj, ro->object_len,
- ro->ObjectIndex, FT_RESTORE_FIRST, ro->FileIndex, ro->JobId);
+ "INSERT INTO RestoreObject (ObjectName,PluginName,RestoreObject,"
+ "ObjectLength,ObjectFullLength,ObjectIndex,ObjectType,"
+ "ObjectCompression,FileIndex,JobId) "
+ "VALUES ('%s','%s','%s',%d,%d,%d,%d,%d,%d,%u)",
+ mdb->esc_name, esc_plug_name, mdb->esc_obj,
+ ro->object_len, ro->object_full_len, ro->object_index,
+ FT_RESTORE_FIRST, ro->object_compression, ro->FileIndex, ro->JobId);
ro->RestoreObjectId = sql_insert_autokey_record(mdb, mdb->cmd, NT_("RestoreObject"));
if (ro->RestoreObjectId == 0) {
stat = true;
}
db_unlock(mdb);
- free_pool_memory(esc_obj);
+ free_pool_memory(esc_plug_name);
return stat;
}