]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/sql_create.c
Implement restore files
[bacula/bacula] / bacula / src / cats / sql_create.c
index 670570c0098bb70fa96c3a0b769131794c0f6588..1406ca4dfbae2874222fafa0ca7dfa836d3804df 100644 (file)
@@ -117,6 +117,7 @@ db_create_jobmedia_record(JCR *jcr, B_DB *mdb, JOBMEDIA_DBR *jm)
    int count;
 
    db_lock(mdb);
+#ifdef not_used_in_new_code
    Mmsg(&mdb->cmd, "SELECT JobId, MediaId FROM JobMedia WHERE \
 JobId=%d AND MediaId=%d", jm->JobId, jm->MediaId);
 
@@ -132,6 +133,7 @@ JobId=%d AND MediaId=%d", jm->JobId, jm->MediaId);
       }
       sql_free_result(mdb);
    }
+#endif
 
    /* Now get count for VolIndex */
    Mmsg(&mdb->cmd, "SELECT count(*) from JobMedia");
@@ -359,6 +361,44 @@ FileRetention, JobRetention) VALUES \
 }
 
 
+/* 
+ * Create a Unique record for the counter -- no duplicates 
+ * Returns: 0 on failure
+ *         1 on success with counter filled in
+ */
+int db_create_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr)
+{
+   COUNTER_DBR mcr;
+   int stat;
+
+   db_lock(mdb);
+   memset(&mcr, 0, sizeof(mcr));
+   bstrncpy(mcr.Counter, cr->Counter, sizeof(mcr.Counter));
+   if (db_get_counter_record(jcr, mdb, &mcr)) {
+      memcpy(cr, &mcr, sizeof(COUNTER_DBR));
+      db_unlock(mdb);
+      return 1;
+   }
+
+   /* Must create it */
+   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);
+
+   if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
+      Mmsg2(&mdb->errmsg, _("Create DB Counters record %s failed. ERR=%s\n"),
+           mdb->cmd, sql_strerror(mdb));
+      Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
+      stat = 0;
+   } else {
+      stat = 1;
+   }
+   db_unlock(mdb);
+   return stat;
+}
+
+
 /* 
  * Create a FileSet record. This record is unique in the
  *  name and the MD5 signature of the include/exclude sets.
@@ -471,7 +511,8 @@ int db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
    /*
     * Make sure we have an acceptable attributes record.
     */
-   if (!(ar->Stream == STREAM_UNIX_ATTRIBUTES || ar->Stream == STREAM_WIN32_ATTRIBUTES)) {
+   if (!(ar->Stream == STREAM_UNIX_ATTRIBUTES || 
+        ar->Stream == STREAM_UNIX_ATTRIBUTES_EX)) {
       Mmsg0(&mdb->errmsg, _("Attempt to put non-attributes into catalog\n"));
       Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
       return 0;
@@ -520,8 +561,8 @@ static int db_create_file_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
 
    /* Must create it */
    Mmsg(&mdb->cmd,
-"INSERT INTO File (FileIndex, JobId, PathId, FilenameId, \
-LStat, MD5) VALUES (%u, %u, %u, %u, '%s', '0')", 
+"INSERT INTO File (FileIndex,JobId,PathId,FilenameId,"
+"LStat,MD5) VALUES (%u,%u,%u,%u,'%s','0')", 
       ar->FileIndex, ar->JobId, ar->PathId, ar->FilenameId, 
       ar->attr);
 
@@ -588,7 +629,7 @@ static int db_create_path_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar)
       sql_free_result(mdb);
    }
 
-   Mmsg(&mdb->cmd, "INSERT INTO Path (Path)  VALUES ('%s')", mdb->esc_name);
+   Mmsg(&mdb->cmd, "INSERT INTO Path (Path) VALUES ('%s')", mdb->esc_name);
 
    if (!INSERT_DB(jcr, mdb, mdb->cmd)) {
       Mmsg2(&mdb->errmsg, _("Create db Path record %s failed. ERR=%s\n"),