From bc48c2aaeeac68248369dd44d5cf869dc31c7e9c Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 17 Dec 2003 21:38:21 +0000 Subject: [PATCH] Integration with Dan's PostgreSQL code git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@884 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/cats/Makefile.in | 1 - bacula/src/cats/sql_create.c | 37 +++++++++--------------------------- bacula/src/dird/recycle.c | 4 ++-- 3 files changed, 11 insertions(+), 31 deletions(-) diff --git a/bacula/src/cats/Makefile.in b/bacula/src/cats/Makefile.in index c3b2583752..3c920ac9e9 100644 --- a/bacula/src/cats/Makefile.in +++ b/bacula/src/cats/Makefile.in @@ -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 diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index 879ea797b9..210c37dcba 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -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; diff --git a/bacula/src/dird/recycle.c b/bacula/src/dird/recycle.c index 0ce19e02f0..193df0fd37 100644 --- a/bacula/src/dird/recycle.c +++ b/bacula/src/dird/recycle.c @@ -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; } -- 2.39.5