]> git.sur5r.net Git - bacula/bacula/commitdiff
Integration with Dan's PostgreSQL code
authorKern Sibbald <kern@sibbald.com>
Wed, 17 Dec 2003 21:38:21 +0000 (21:38 +0000)
committerKern Sibbald <kern@sibbald.com>
Wed, 17 Dec 2003 21:38:21 +0000 (21:38 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@884 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/cats/Makefile.in
bacula/src/cats/sql_create.c
bacula/src/dird/recycle.c

index c3b258375261a86937d5ee75a4b69f6b84698627..3c920ac9e9263953025af8ea8bfaeeb45fdec58d 100644 (file)
@@ -79,7 +79,6 @@ distclean: realclean
        (cd $(srcdir); $(RMF) Makefile; $(RMF) -r CVS)
 
 install:
-       $(MKDIR) $(DESTDIR)$(datadir)/bacula
        $(INSTALL_SCRIPT) create_@DB_NAME@_database $(DESTDIR)$(scriptdir)/create_@DB_NAME@_database
        $(INSTALL_SCRIPT) drop_@DB_NAME@_tables $(DESTDIR)$(scriptdir)/drop_@DB_NAME@_tables
        $(INSTALL_SCRIPT) make_@DB_NAME@_tables $(DESTDIR)$(scriptdir)/make_@DB_NAME@_tables
index 879ea797b94a8866d977aa5511bc8f36c73cb7ff..210c37dcbae70a58863ffbd0d10f43063ab42f1e 100644 (file)
@@ -54,6 +54,7 @@ extern void print_dashes(B_DB *mdb);
 extern void print_result(B_DB *mdb);
 extern int QueryDB(char *file, int line, JCR *jcr, B_DB *db, char *select_cmd);
 extern int InsertDB(char *file, int line, JCR *jcr, B_DB *db, char *select_cmd);
+extern int UpdateDB(char *file, int line, JCR *jcr, B_DB *db, char *update_cmd);
 extern void split_path_and_filename(JCR *jcr, B_DB *mdb, char *fname);
 
 
@@ -234,7 +235,6 @@ db_create_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
 {
    int stat;
    char ed1[30], ed2[30], ed3[30], ed4[30], ed5[30];
-   char dt[MAX_TIME_LENGTH];
    struct tm tm;
 
    db_lock(mdb);
@@ -259,14 +259,7 @@ db_create_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
    db_make_inchanger_unique(jcr, mdb, mr);
 
    /* Must create it */
-   if (mr->LabelDate) {
-      localtime_r(&mr->LabelDate, &tm); 
-      strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm);
-   } else {
-      bstrncpy(dt, "0000-00-00 00:00:00", sizeof(dt));
-   }
    Mmsg(&mdb->cmd, 
-#ifdef HAVE_POSTGRESQL
 "INSERT INTO Media (VolumeName,MediaType,PoolId,MaxVolBytes,VolCapacityBytes," 
 "Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
 "VolStatus,Slot,VolBytes,Drive,InChanger) "
@@ -285,26 +278,6 @@ db_create_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
                  edit_uint64(mr->VolBytes, ed5),
                  mr->Drive,
                  mr->InChanger);
-#else
-"INSERT INTO Media (VolumeName,MediaType,PoolId,MaxVolBytes,VolCapacityBytes," 
-"Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
-"VolStatus,LabelDate,Slot,VolBytes,Drive,InChanger) "
-"VALUES ('%s','%s',%u,%s,%s,%d,%s,%s,%u,%u,'%s','%s',%d,%s,%d,%d)", 
-                 mr->VolumeName,
-                 mr->MediaType, mr->PoolId, 
-                 edit_uint64(mr->MaxVolBytes,ed1),
-                 edit_uint64(mr->VolCapacityBytes, ed2),
-                 mr->Recycle,
-                 edit_uint64(mr->VolRetention, ed3),
-                 edit_uint64(mr->VolUseDuration, ed4),
-                 mr->MaxVolJobs,
-                 mr->MaxVolFiles,
-                 mr->VolStatus, dt,
-                 mr->Slot,
-                 edit_uint64(mr->VolBytes, ed5),
-                 mr->Drive,
-                 mr->InChanger);
-#endif
 
    Dmsg1(500, "Create Volume: %s\n", mdb->cmd);
    sql_table_name(mdb, _("Media"));
@@ -315,6 +288,14 @@ db_create_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
    } else {
       mr->MediaId = sql_insert_id(mdb);
       stat = 1;
+      if (mr->LabelDate) {
+        char dt[MAX_TIME_LENGTH];
+        localtime_r(&mr->LabelDate, &tm);
+         strftime(dt, sizeof(dt), "%Y-%m-%d %T", &tm);
+         Mmsg(&mdb->cmd, "UPDATE Media SET LabelDate='%s' "
+              "WHERE MediaId=%d", dt, mr->MediaId);
+        stat = UPDATE_DB(jcr, mdb, mdb->cmd);
+      }
    }
    db_unlock(mdb);
    return stat;
index 0ce19e02f0f4eaa0a026723d6962a40e3cd57c81..193df0fd376aeda2a9bfda2b63a8937cfae65533 100644 (file)
@@ -60,7 +60,7 @@ int find_recycled_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr)
    bstrncpy(mr->VolStatus, "Recycle", sizeof(mr->VolStatus));
    if (db_find_next_volume(jcr, jcr->db, 1, InChanger, mr)) {
       jcr->MediaId = mr->MediaId;
-      Dmsg1(20, "Find_next_vol MediaId=%d\n", jcr->MediaId);
+      Dmsg1(20, "Find_next_vol MediaId=%u\n", jcr->MediaId);
       pm_strcpy(&jcr->VolumeName, mr->VolumeName);
       return 1;
    }
@@ -106,7 +106,7 @@ int recycle_oldest_purged_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr)
       mr->MediaId = oldest.MediaId;
       if (db_get_media_record(jcr, jcr->db, mr)) {
         if (recycle_volume(jcr, mr)) {
-            Jmsg(jcr, M_INFO, 0, "Recycled volume '%s'\n", mr->VolumeName);
+            Jmsg(jcr, M_INFO, 0, "Recycled volume \"%s\"\n", mr->VolumeName);
             Dmsg1(100, "Exit 1  recycle_oldest_purged_volume Vol=%s\n", mr->VolumeName);
            return 1;
         }