]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_dotcmds.c
Merge branch 'master' of ssh://bacula.git.sourceforge.net/gitroot/bacula/bacula
[bacula/bacula] / bacula / src / dird / ua_dotcmds.c
index 7f5f4cb59162c5b06154ca0d18ce99b0a9eb6911..b6c52c069cc5c9321805aff7d7c0328c70ddbaf2 100644 (file)
@@ -35,7 +35,6 @@
  *
  *     Kern Sibbald, April MMII
  *
- *   Version $Id$
  */
 
 #include "bacula.h"
@@ -65,10 +64,15 @@ static bool typescmd(UAContext *ua, const char *cmd);
 static bool backupscmd(UAContext *ua, const char *cmd);
 static bool levelscmd(UAContext *ua, const char *cmd);
 static bool getmsgscmd(UAContext *ua, const char *cmd);
+static bool volstatuscmd(UAContext *ua, const char *cmd);
+static bool mediatypescmd(UAContext *ua, const char *cmd);
+static bool locationscmd(UAContext *ua, const char *cmd);
+static bool mediacmd(UAContext *ua, const char *cmd);
+static bool aopcmd(UAContext *ua, const char *cmd);
 
-static bool dot_lsdirs(UAContext *ua, const char *cmd);
-static bool dot_lsfiles(UAContext *ua, const char *cmd);
-static bool dot_update(UAContext *ua, const char *cmd);
+static bool dot_bvfs_lsdirs(UAContext *ua, const char *cmd);
+static bool dot_bvfs_lsfiles(UAContext *ua, const char *cmd);
+static bool dot_bvfs_update(UAContext *ua, const char *cmd);
 
 static bool api_cmd(UAContext *ua, const char *cmd);
 static bool sql_cmd(UAContext *ua, const char *cmd);
@@ -94,9 +98,14 @@ static struct cmdstruct commands[] = { /* help */  /* can be used in runscript *
  { NT_(".sql"),        sql_cmd,          NULL,       false},
  { NT_(".status"),     dot_status_cmd,   NULL,       false},
  { NT_(".storage"),    storagecmd,       NULL,       true},
- { NT_(".lsdirs"),     dot_lsdirs,       NULL,       true},
- { NT_(".lsfiles"),    dot_lsfiles,      NULL,       true},
- { NT_(".update"),     dot_update,       NULL,       true},
+ { NT_(".volstatus"),  volstatuscmd,     NULL,       true},
+ { NT_(".media"),      mediacmd,         NULL,       true},
+ { NT_(".mediatypes"), mediatypescmd,    NULL,       true},
+ { NT_(".locations"),  locationscmd,     NULL,       true},
+ { NT_(".actiononpurge"),aopcmd,         NULL,       true},
+ { NT_(".bvfs_lsdirs"), dot_bvfs_lsdirs, NULL,       true},
+ { NT_(".bvfs_lsfiles"),dot_bvfs_lsfiles,NULL,       true},
+ { NT_(".bvfs_update"), dot_bvfs_update, NULL,       true},
  { NT_(".types"),      typescmd,         NULL,       false} 
              };
 #define comsize ((int)(sizeof(commands)/sizeof(struct cmdstruct)))
@@ -154,17 +163,18 @@ bool do_a_dot_command(UAContext *ua)
    return ok;
 }
 
-static bool dot_update(UAContext *ua, const char *cmd)
+static bool dot_bvfs_update(UAContext *ua, const char *cmd)
 {
+
    if (!open_client_db(ua)) {
       return 1;
    }
 
    int pos = find_arg_with_value(ua, "jobid");
-   if (pos != -1) {             /* find jobid arg */
-      if (is_a_number_list(ua->argv[pos])) {
-         bvfs_update_path_hierarchy_cache(ua->jcr, ua->db, ua->argv[pos]);
-      }
+   if (pos != -1 && is_a_number_list(ua->argv[pos])) {
+      POOL_MEM jobids;
+      pm_strcpy(jobids, ua->argv[pos]);
+      bvfs_update_path_hierarchy_cache(ua->jcr, ua->db, jobids.c_str());
    } else {
       /* update cache for all jobids */
       bvfs_update_cache(ua->jcr, ua->db);
@@ -177,17 +187,26 @@ static int bvfs_result_handler(void *ctx, int fields, char **row)
    UAContext *ua = (UAContext *)ctx;
    struct stat statp;
    int32_t LinkFI;
+   const char *fileid;
+   char *lstat;
    char empty[] = "A A A A A A A A A A A A A A";
 
+   lstat = (row[BVFS_LStat] && row[BVFS_LStat][0])?row[BVFS_LStat]:empty;
+   fileid = (row[BVFS_FileId] && row[BVFS_FileId][0])?row[BVFS_FileId]:"0";
+
    memset(&statp, 0, sizeof(struct stat));
-   decode_stat((row[BVFS_LStat] && row[BVFS_LStat][0])?row[BVFS_LStat]:empty,
-               &statp, &LinkFI);
+   decode_stat(lstat, &statp, &LinkFI);
 
-   if (fields == BVFS_DIR_RECORD) {
+   Dmsg1(100, "type=%s\n", row[0]);
+   if (bvfs_is_dir(row)) {
       char *path = bvfs_basename_dir(row[BVFS_Name]);
-      ua->send_msg("%s\t%s\t\%s\n", row[BVFS_Id], row[BVFS_JobId], path);
-   } else if (fields == BVFS_FILE_RECORD) {
-      ua->send_msg("%s\t%s\t\%s\n", row[BVFS_Id], row[BVFS_JobId], row[BVFS_Name]);
+      ua->send_msg("%s\t0\t%s\t%s\t%s\t%s\n", row[BVFS_PathId], fileid,
+                   row[BVFS_JobId], row[BVFS_LStat], path);
+
+   } else if (bvfs_is_file(row)) {
+      ua->send_msg("%s\t%s\t%s\t%s\t%s\t%s\n", row[BVFS_PathId],
+                   row[BVFS_FilenameId], fileid, row[BVFS_JobId],
+                   row[BVFS_LStat], row[BVFS_Name]);
    }
 
    return 0;
@@ -232,18 +251,22 @@ static bool bvfs_parse_arg(UAContext *ua,
       }
    }
 
-   if (!((pathid || path) && jobid)) {
+   if (!((*pathid || *path) && *jobid)) {
       return false;
    }
 
    if (!open_client_db(ua)) {
-      return 1;
+      return false;
    }
 
    return true;
 }
 
-static bool dot_lsfiles(UAContext *ua, const char *cmd)
+/* 
+ * .bvfs_lsfiles jobid=1,2,3,4 pathid=10
+ * .bvfs_lsfiles jobid=1,2,3,4 path=/
+ */
+static bool dot_bvfs_lsfiles(UAContext *ua, const char *cmd)
 {
    DBId_t pathid=0;
    int limit=2000, offset=0;
@@ -258,9 +281,8 @@ static bool dot_lsfiles(UAContext *ua, const char *cmd)
 
    Bvfs fs(ua->jcr, ua->db);
    fs.set_jobids(jobid);   
-   fs.set_limit(limit);
-   fs.set_offset(offset);
    fs.set_handler(bvfs_result_handler, ua);
+   fs.set_limit(limit);
 
    if (pathid) {
       fs.ch_dir(pathid);
@@ -268,12 +290,19 @@ static bool dot_lsfiles(UAContext *ua, const char *cmd)
       fs.ch_dir(path);
    }
 
+   fs.set_offset(offset);
+
    fs.ls_files();
 
    return true;
 }
 
-static bool dot_lsdirs(UAContext *ua, const char *cmd)
+/* 
+ * .bvfs_lsdirs jobid=1,2,3,4 pathid=10
+ * .bvfs_lsdirs jobid=1,2,3,4 path=/
+ * .bvfs_lsdirs jobid=1,2,3,4 path=
+ */
+static bool dot_bvfs_lsdirs(UAContext *ua, const char *cmd)
 {
    DBId_t pathid=0;
    int limit=2000, offset=0;
@@ -289,7 +318,6 @@ static bool dot_lsdirs(UAContext *ua, const char *cmd)
    Bvfs fs(ua->jcr, ua->db);
    fs.set_jobids(jobid);   
    fs.set_limit(limit);
-   fs.set_offset(offset);
    fs.set_handler(bvfs_result_handler, ua);
 
    if (pathid) {
@@ -298,6 +326,9 @@ static bool dot_lsdirs(UAContext *ua, const char *cmd)
       fs.ch_dir(path);
    }
 
+   fs.set_offset(offset);
+
+   fs.ls_special_dirs();
    fs.ls_dirs();
 
    return true;
@@ -479,13 +510,24 @@ static bool diecmd(UAContext *ua, const char *cmd)
 
 #endif
 
+/* 
+ * Can use an argument to filter on JobType
+ * .jobs [type=B]
+ */
 static bool jobscmd(UAContext *ua, const char *cmd)
 {
    JOB *job;
+   uint32_t type = 0;
+   int pos;
+   if ((pos = find_arg_with_value(ua, "type")) >= 0) {
+      type = ua->argv[pos][0];
+   }
    LockRes();
    foreach_res(job, R_JOB) {
-      if (acl_access_ok(ua, Job_ACL, job->name())) {
-         ua->send_msg("%s\n", job->name());
+      if (!type || type == job->JobType) {
+         if (acl_access_ok(ua, Job_ACL, job->name())) {
+            ua->send_msg("%s\n", job->name());
+         }
       }
    }
    UnlockRes();
@@ -555,6 +597,12 @@ static bool storagecmd(UAContext *ua, const char *cmd)
    return true;
 }
 
+static bool aopcmd(UAContext *ua, const char *cmd)
+{
+   ua->send_msg("None\n");
+   ua->send_msg("Truncate\n");
+   return true;
+}
 
 static bool typescmd(UAContext *ua, const char *cmd)
 {
@@ -566,7 +614,6 @@ static bool typescmd(UAContext *ua, const char *cmd)
    return true;
 }
 
-
 /*
  * If this command is called, it tells the director that we
  *  are a program that wants a sort of API, and hence,
@@ -665,7 +712,54 @@ static bool sql_cmd(UAContext *ua, const char *cmd)
    return true;
 }
       
+static int one_handler(void *ctx, int num_field, char **row)
+{
+   UAContext *ua = (UAContext *)ctx;
+   ua->send_msg("%s\n", row[0]);
+   return 0;
+}
+
+static bool mediatypescmd(UAContext *ua, const char *cmd)
+{
+   if (!open_client_db(ua)) {
+      return true;
+   }
+   if (!db_sql_query(ua->db, 
+                  "SELECT DISTINCT MediaType FROM MediaType ORDER BY MediaType",
+                  one_handler, (void *)ua)) 
+   {
+      ua->error_msg(_("List MediaType failed: ERR=%s\n"), db_strerror(ua->db));
+   }
+   return true;
+}
 
+static bool mediacmd(UAContext *ua, const char *cmd)
+{
+   if (!open_client_db(ua)) {
+      return true;
+   }
+   if (!db_sql_query(ua->db, 
+                  "SELECT DISTINCT Media.VolumeName FROM Media ORDER BY VolumeName",
+                  one_handler, (void *)ua)) 
+   {
+      ua->error_msg(_("List Media failed: ERR=%s\n"), db_strerror(ua->db));
+   }
+   return true;
+}
+
+static bool locationscmd(UAContext *ua, const char *cmd)
+{
+   if (!open_client_db(ua)) {
+      return true;
+   }
+   if (!db_sql_query(ua->db, 
+                  "SELECT DISTINCT Location FROM Location ORDER BY Location",
+                  one_handler, (void *)ua)) 
+   {
+      ua->error_msg(_("List Location failed: ERR=%s\n"), db_strerror(ua->db));
+   }
+   return true;
+}
 
 static bool levelscmd(UAContext *ua, const char *cmd)
 {
@@ -679,6 +773,18 @@ static bool levelscmd(UAContext *ua, const char *cmd)
    return true;
 }
 
+static bool volstatuscmd(UAContext *ua, const char *cmd)
+{
+   ua->send_msg("Append\n");
+   ua->send_msg("Full\n");
+   ua->send_msg("Used\n");
+   ua->send_msg("Recycle\n");
+   ua->send_msg("Purged\n");
+   ua->send_msg("Cleaning\n");
+   ua->send_msg("Error\n");
+   return true;
+}
+
 /*
  * Return default values for a job
  */
@@ -776,6 +882,8 @@ static bool defaultscmd(UAContext *ua, const char *cmd)
          ua->send_msg("max_vol_bytes=%s", edit_uint64(pool->MaxVolBytes, ed1));
          ua->send_msg("auto_prune=%d", pool->AutoPrune);
          ua->send_msg("recycle=%d", pool->Recycle);
+         ua->send_msg("file_retention=%s", edit_uint64(pool->FileRetention, ed1));
+         ua->send_msg("job_retention=%s", edit_uint64(pool->JobRetention, ed1));
       }
    }
    return true;