]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_cmds.c
Fix DATE problem and minor compile stuff
[bacula/bacula] / bacula / src / dird / ua_cmds.c
index f19e21ff062c9c88bf2dedd77e7557a2f2dfa806..e4bb83dddfb68d9a5306fc3d6127b5ce2523b9bb 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 /*
-   Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+   Copyright (C) 2000-2003 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -138,7 +138,7 @@ int do_a_command(UAContext *ua, char *cmd)
  *   into the Media DB record just before creating a media (Volume) 
  *   record.
  */
-static void set_pool_dbr_defaults_in_media_dbr(MEDIA_DBR *mr, POOL_DBR *pr)
+void set_pool_dbr_defaults_in_media_dbr(MEDIA_DBR *mr, POOL_DBR *pr)
 {
    mr->PoolId = pr->PoolId;
    strcpy(mr->VolStatus, "Append");
@@ -280,7 +280,7 @@ getVolName:
       sprintf(mr.VolumeName, name, i);
       mr.Slot = slot++;
       Dmsg1(200, "Create Volume %s\n", mr.VolumeName);
-      if (!db_create_media_record(ua->db, &mr)) {
+      if (!db_create_media_record(ua->jcr, ua->db, &mr)) {
         bsendmsg(ua, db_strerror(ua->db));
         return 1;
       }
@@ -290,7 +290,7 @@ getVolName:
    }
    pr.NumVols += num;
    Dmsg0(200, "Update pool record.\n"); 
-   if (db_update_pool_record(ua->db, &pr) != 1) {
+   if (db_update_pool_record(ua->jcr, ua->db, &pr) != 1) {
       bsendmsg(ua, db_strerror(ua->db));
       return 1;
    }
@@ -411,7 +411,7 @@ static int cancelcmd(UAContext *ua, char *cmd)
      
    switch (jcr->JobStatus) {
    case JS_Created:
-      jcr->JobStatus = JS_Cancelled;
+      set_jcr_job_status(jcr, JS_Cancelled);
       bsendmsg(ua, _("JobId %d, Job %s marked to be cancelled.\n"),
              jcr->JobId, jcr->Job);
       free_jcr(jcr);
@@ -419,7 +419,7 @@ static int cancelcmd(UAContext *ua, char *cmd)
         
    default:
 
-      jcr->JobStatus = JS_Cancelled;
+      set_jcr_job_status(jcr, JS_Cancelled);
       /* Cancel File daemon */
       ua->jcr->client = jcr->client;
       if (!connect_to_file_daemon(ua->jcr, 10, FDConnectTimeout, 1)) {
@@ -506,7 +506,7 @@ void set_pooldbr_from_poolres(POOL_DBR *pr, POOL *pool, int create)
  *          1  record created
  */
 
-int create_pool(B_DB *db, POOL *pool)
+int create_pool(JCR *jcr, B_DB *db, POOL *pool)
 {
    POOL_DBR  pr;
 
@@ -514,13 +514,13 @@ int create_pool(B_DB *db, POOL *pool)
 
    strcpy(pr.Name, pool->hdr.name);
 
-   if (db_get_pool_record(db, &pr)) {
+   if (db_get_pool_record(jcr, db, &pr)) {
       return 0;                      /* exists */
    }
 
    set_pooldbr_from_poolres(&pr, pool, 1);
 
-   if (!db_create_pool_record(db, &pr)) {
+   if (!db_create_pool_record(jcr, db, &pr)) {
       return -1;                     /* error */
    }
    return 1;
@@ -545,7 +545,7 @@ static int createcmd(UAContext *ua, char *cmd)
       return 1;
    }
 
-   switch (create_pool(ua->db, pool)) {
+   switch (create_pool(ua->jcr, ua->db, pool)) {
    case 0:
       bsendmsg(ua, _("Error: Pool %s already exists.\n\
 Use update to change it.\n"), pool->hdr.name);
@@ -632,7 +632,7 @@ static int update_volume(UAContext *ua)
    }
 
    for (int done=0; !done; ) {
-      if (!db_get_media_record(ua->db, &mr)) {
+      if (!db_get_media_record(ua->jcr, ua->db, &mr)) {
         if (mr.MediaId != 0) {
             bsendmsg(ua, _("Volume record for MediaId %d not found.\n"), mr.MediaId);
         } else {
@@ -650,6 +650,7 @@ static int update_volume(UAContext *ua)
       add_prompt(ua, _("Maximum Volume Bytes"));
       add_prompt(ua, _("Recycle Flag"));
       add_prompt(ua, _("Slot"));
+      add_prompt(ua, _("Volume Files"));
       add_prompt(ua, _("Done"));
       switch (do_prompt(ua, _("Select parameter to modify"), NULL, 0)) {
       case 0:                        /* Volume Status */
@@ -842,6 +843,37 @@ static int update_volume(UAContext *ua)
         free_pool_memory(query);
         break;
 
+      case 8:                        /* Volume Files */
+        int32_t VolFiles;
+         bsendmsg(ua, _("Warning changing Volume Files can result\n"
+                        "in loss of data on your Volume\n\n"));
+         bsendmsg(ua, _("Current Volume Files is: %u\n"), mr.VolFiles);
+         if (!get_cmd(ua, _("Enter new number of Files for Volume: "))) {
+           return 0;
+        }
+        VolFiles = atoi(ua->cmd);
+        if (VolFiles < 0) {
+            bsendmsg(ua, _("Invalid number, it must be 0 or greater\n"));
+           break;
+        } 
+        if (VolFiles != (int)(mr.VolFiles + 1)) {
+            bsendmsg(ua, _("Normally, you should only increase Volume Files by one!\n"));
+            if (!get_cmd(ua, _("Continue? (yes/no): ")) || 
+                 strcasecmp(ua->cmd, "yes") != 0) {
+              break;
+           }
+        }
+        query = get_pool_memory(PM_MESSAGE);
+         Mmsg(&query, "UPDATE Media SET VolFiles=%u WHERE MediaId=%u",
+           VolFiles, mr.MediaId);
+        if (!db_sql_query(ua->db, query, NULL, NULL)) {  
+            bsendmsg(ua, "%s", db_strerror(ua->db));
+        } else {
+            bsendmsg(ua, _("New Volume Files is: %u\n"), VolFiles);
+        }
+        free_pool_memory(query);
+        break;
+
       default:                       /* Done or error */
          bsendmsg(ua, "Selection done.\n");
         return 1;
@@ -873,7 +905,7 @@ static int update_pool(UAContext *ua)
 
    set_pooldbr_from_poolres(&pr, pool, 0); /* update */
 
-   id = db_update_pool_record(ua->db, &pr);
+   id = db_update_pool_record(ua->jcr, ua->db, &pr);
    if (id <= 0) {
       bsendmsg(ua, _("db_update_pool_record returned %d. ERR=%s\n"),
         id, db_strerror(ua->db));
@@ -1175,7 +1207,7 @@ static int delete_volume(UAContext *ua)
       return 1;
    }
    if (strcasecmp(ua->cmd, _("yes")) == 0) {
-      db_delete_media_record(ua->db, &mr);
+      db_delete_media_record(ua->jcr, ua->db, &mr);
    }
    return 1;
 }
@@ -1196,7 +1228,7 @@ static int delete_pool(UAContext *ua)
       return 1;
    }
    if (strcasecmp(ua->cmd, _("yes")) == 0) {
-      db_delete_pool_record(ua->db, &pr);
+      db_delete_pool_record(ua->jcr, ua->db, &pr);
    }
    return 1;
 }
@@ -1257,7 +1289,7 @@ gotVol:
 
    memset(&mr, 0, sizeof(mr));
    strcpy(mr.VolumeName, ua->cmd);
-   if (db_get_media_record(ua->db, &mr)) {
+   if (db_get_media_record(ua->jcr, ua->db, &mr)) {
        bsendmsg(ua, _("Media record for Volume %s already exists.\n"), 
          mr.VolumeName);
        return 1;
@@ -1305,9 +1337,10 @@ gotVol:
    unbash_spaces(mr.VolumeName);
    unbash_spaces(mr.MediaType);
    unbash_spaces(pr.Name);
+   mr.LabelDate = time(NULL);
    if (ok) {
       set_pool_dbr_defaults_in_media_dbr(&mr, &pr);
-      if (db_create_media_record(ua->db, &mr)) {
+      if (db_create_media_record(ua->jcr, ua->db, &mr)) {
          bsendmsg(ua, _("Media record for Volume=%s successfully created.\n"),
            mr.VolumeName);
         if (ua->automount) {
@@ -1450,7 +1483,7 @@ static int helpcmd(UAContext *ua, char *cmd)
 
 static int versioncmd(UAContext *ua, char *cmd)
 {
-   bsendmsg(ua, "%s Version: " VERSION " (" DATE ")\n", my_name);
+   bsendmsg(ua, "%s Version: " VERSION " (" BDATE ")\n", my_name);
    return 1;
 }
 
@@ -1469,19 +1502,19 @@ int open_db(UAContext *ua)
       ua->catalog = (CAT *)GetNextRes(R_CATALOG, NULL);
       UnlockRes();
       if (!ua->catalog) {    
-         bnet_fsend(ua->UA_sock, _("Could not find a Catalog resource\n"));
+         bsendmsg(ua, _("Could not find a Catalog resource\n"));
         return 0;
       } else {
-         bnet_fsend(ua->UA_sock, _("Using default Catalog name=%s DB=%s\n"), 
+         bsendmsg(ua, _("Using default Catalog name=%s DB=%s\n"), 
            ua->catalog->hdr.name, ua->catalog->db_name);
       }
    }
 
    Dmsg0(150, "Open database\n");
-   ua->db = db_init_database(NULL, ua->catalog->db_name, ua->catalog->db_user,
+   ua->db = db_init_database(ua->jcr, ua->catalog->db_name, ua->catalog->db_user,
                             ua->catalog->db_password);
-   if (!db_open_database(ua->db)) {
-      bnet_fsend(ua->UA_sock, _("Could not open DB %s: ERR=%s"), 
+   if (!db_open_database(ua->jcr, ua->db)) {
+      bsendmsg(ua, _("Could not open DB %s: ERR=%s"), 
         ua->catalog->db_name, db_strerror(ua->db));
       close_db(ua);
       return 0;
@@ -1494,7 +1527,7 @@ int open_db(UAContext *ua)
 void close_db(UAContext *ua)
 {
    if (ua->db) {
-      db_close_database(ua->db);
+      db_close_database(ua->jcr, ua->db);
    }
    ua->db = NULL;
    ua->jcr->db = NULL;