src/dird/ua_cmds.c
static int cloud_list_cmd(UAContext *ua, const char *cmd)
{
   int drive = -1;
   int64_t size, mtime;
   STORE *store = NULL;
   MEDIA_DBR mr;
   POOL_DBR pr;
   BSOCK *sd = NULL;
   char storage[MAX_NAME_LENGTH];
   char ed1[50], ed2[50];
   bool first=true;
   uint32_t maxpart=0, part;
   uint64_t maxpart_size=0;
   memset(&pr, 0, sizeof(pr));
   memset(&mr, 0, sizeof(mr));

   /* Look at arguments */
   for (int i=1; i<ua->argc; i++) {
      if (strcasecmp(ua->argk[i], NT_("volume")) == 0
          && is_name_valid(ua->argv[i], NULL)) {
         bstrncpy(mr.VolumeName, ua->argv[i], sizeof(mr.VolumeName));

      } else if (strcasecmp(ua->argk[i], NT_("drive")) == 0 && ua->argv[i]) {
         drive = atoi(ua->argv[i]);
      }
   }

   if (!open_client_db(ua)) {
      goto bail_out;
   }

   /* Choose storage */
   ua->jcr->wstore = store = get_storage_resource(ua, false);
   if (!store) {
      goto bail_out;
   }
   bstrncpy(storage, store->dev_name(), sizeof(storage));
   bstrncpy(mr.MediaType, store->media_type, sizeof(mr.MediaType));

   if ((sd=open_sd_bsock(ua)) == NULL) {
      Dmsg0(100, "Can't open connection to SD\n");
      goto bail_out;
   }

   /* Protect us from spaces */
   bash_spaces(mr.MediaType);
   bash_spaces(storage);
   bash_spaces(mr.VolumeName);

   sd->fsend("cloudlist Storage=%s Volume=%s MediaType=%s Slot=%d drive=%d\n",
             storage, mr.VolumeName,  mr.MediaType, mr.Slot, drive);

   if (mr.VolumeName[0]) {      /* Want to list parts */
      const char *output_hformat="| %8d | %12sB | %20s |\n";
      uint64_t volsize=0;
      /* Check for valid response */
      while (sd->recv() >= 0) {
         if (sscanf(sd->msg, "part=%d size=%lld mtime=%lld", &part, &size, &mtime) != 3) {
            if (sd->msg[0] == '3') {
               ua->send_msg("%s", sd->msg);
            }
            continue;
         }
         /* Print information */
         if (first) {
            ua->send_msg(_("+----------+---------------+----------------------+\n"));
            ua->send_msg(_("|   Part   |     Size      |   MTime              |\n"));
            ua->send_msg(_("+----------+---------------+----------------------+\n"));
            first=false;
         }
         if (part > maxpart) {
            maxpart = part;
            maxpart_size = size;
         }
         volsize += size;
         ua->send_msg(output_hformat, part, edit_uint64_with_suffix(size, ed1), bstrftimes(ed2, sizeof(ed2), mtime));
      }
      if (!first) {
         ua->send_msg(_("+----------+---------------+----------------------+\n"));
      }
      /* TODO: See if we fix the catalog record directly */
      if (db_get_media_record(ua->jcr, ua->db, &mr)) {
         POOL_MEM errmsg, tmpmsg;
         if (mr.LastPartBytes != maxpart_size) {
            Mmsg(tmpmsg, "Error on volume \"%s\". Catalog LastPartBytes mismatch %lld != %lld\n",
                 mr.VolumeName, mr.LastPartBytes, maxpart_size);
            pm_strcpy(errmsg, tmpmsg.c_str());
         }
         if (mr.VolCloudParts != maxpart) {
            Mmsg(tmpmsg, "Error on volume \"%s\". Catalog VolCloudParts mismatch %ld != %ld\n",
                 mr.VolumeName, mr.VolCloudParts, maxpart);
            pm_strcpy(errmsg, tmpmsg.c_str());
         }
         if (strlen(errmsg.c_str()) > 0) {
            ua->error_msg("\n%s", errmsg.c_str());
         }
      }
   } else {                     /* TODO: Get the last part if possible? */
      const char *output_hformat="| %18s | %9s | %20s | %20s | %12sB |\n";

      /* Check for valid response */
      while (sd->recv() >= 0) {
         if (sscanf(sd->msg, "volume=%127s", mr.VolumeName) != 1) {
            if (sd->msg[0] == '3') {
               ua->send_msg("%s", sd->msg);
            }
            continue;
         }
         unbash_spaces(mr.VolumeName);

         mr.MediaId = 0;

         if (mr.VolumeName[0] && db_get_media_record(ua->jcr, ua->db, &mr)) {
            memset(&pr, 0, sizeof(POOL_DBR));
            pr.PoolId = mr.PoolId;
            if (!db_get_pool_record(ua->jcr, ua->db, &pr)) {
               strcpy(pr.Name, "?");
            }

            if (first) {
               ua->send_msg(_("+--------------------+-----------+----------------------+----------------------+---------------+\n"));
               ua->send_msg(_("|    Volume Name     |   Status  |     Media Type       |       Pool           |    VolBytes   |\n"));
               ua->send_msg(_("+--------------------+-----------+----------------------+----------------------+---------------+\n"));
               first=false;
            }
            /* Print information */
            ua->send_msg(output_hformat, mr.VolumeName, mr.VolStatus, mr.MediaType, pr.Name,
                         edit_uint64_with_suffix(mr.VolBytes, ed1));
         }
      }
      if (!first) {
         ua->send_msg(_("+--------------------+-----------+----------------------+----------------------+---------------+\n"));
      }
   }

bail_out:
   close_db(ua);
   close_sd_bsock(ua);
   ua->jcr->wstore = NULL;
   return 1;
}
/* List volumes in the cloud */
/* TODO: Update the code for .api 2 and llist */
List volumes in the cloud
TODO: Update the code for .api 2 and llist
List volumes in the cloud TODO : Update the code for . api 2 and llist
static int cloud_list_cmd(UAContext *ua, const char *cmd)
{
   int drive = -1;
   int64_t size, mtime;
   STORE *store = NULL;
   MEDIA_DBR mr;
   POOL_DBR pr;
   BSOCK *sd = NULL;
   char storage[MAX_NAME_LENGTH];
   char ed1[50], ed2[50];
   bool first=true;
   uint32_t maxpart=0, part;
   uint64_t maxpart_size=0;
   memset(&pr, 0, sizeof(pr));
   memset(&mr, 0, sizeof(mr));
   for (int i=1; i<ua->argc; i++) {
      if (strcasecmp(ua->argk[i], NT_("volume")) == 0
          && is_name_valid(ua->argv[i], NULL)) {
         bstrncpy(mr.VolumeName, ua->argv[i], sizeof(mr.VolumeName));
      } else if (strcasecmp(ua->argk[i], NT_("drive")) == 0 && ua->argv[i]) {
         drive = atoi(ua->argv[i]);
      }
   }
   if (!open_client_db(ua)) {
      goto bail_out;
   }
   ua->jcr->wstore = store = get_storage_resource(ua, false);
   if (!store) {
      goto bail_out;
   }
   bstrncpy(storage, store->dev_name(), sizeof(storage));
   bstrncpy(mr.MediaType, store->media_type, sizeof(mr.MediaType));
   if ((sd=open_sd_bsock(ua)) == NULL) {
      Dmsg0(100, "Can't open connection to SD\n");
      goto bail_out;
   }
   bash_spaces(mr.MediaType);
   bash_spaces(storage);
   bash_spaces(mr.VolumeName);
   sd->fsend("cloudlist Storage=%s Volume=%s MediaType=%s Slot=%d drive=%d\n",
             storage, mr.VolumeName,  mr.MediaType, mr.Slot, drive);
   if (mr.VolumeName[0]) {      
      const char *output_hformat="| %8d | %12sB | %20s |\n";
      uint64_t volsize=0;
      while (sd->recv() >= 0) {
         if (sscanf(sd->msg, "part=%d size=%lld mtime=%lld", &part, &size, &mtime) != 3) {
            if (sd->msg[0] == '3') {
               ua->send_msg("%s", sd->msg);
            }
            continue;
         }
         if (first) {
            ua->send_msg(_("+----------+---------------+----------------------+\n"));
            ua->send_msg(_("|   Part   |     Size      |   MTime              |\n"));
            ua->send_msg(_("+----------+---------------+----------------------+\n"));
            first=false;
         }
         if (part > maxpart) {
            maxpart = part;
            maxpart_size = size;
         }
         volsize += size;
         ua->send_msg(output_hformat, part, edit_uint64_with_suffix(size, ed1), bstrftimes(ed2, sizeof(ed2), mtime));
      }
      if (!first) {
         ua->send_msg(_("+----------+---------------+----------------------+\n"));
      }
      if (db_get_media_record(ua->jcr, ua->db, &mr)) {
         POOL_MEM errmsg, tmpmsg;
         if (mr.LastPartBytes != maxpart_size) {
            Mmsg(tmpmsg, "Error on volume \"%s\". Catalog LastPartBytes mismatch %lld != %lld\n",
                 mr.VolumeName, mr.LastPartBytes, maxpart_size);
            pm_strcpy(errmsg, tmpmsg.c_str());
         }
         if (mr.VolCloudParts != maxpart) {
            Mmsg(tmpmsg, "Error on volume \"%s\". Catalog VolCloudParts mismatch %ld != %ld\n",
                 mr.VolumeName, mr.VolCloudParts, maxpart);
            pm_strcpy(errmsg, tmpmsg.c_str());
         }
         if (strlen(errmsg.c_str()) > 0) {
            ua->error_msg("\n%s", errmsg.c_str());
         }
      }
   } else {                     
      const char *output_hformat="| %18s | %9s | %20s | %20s | %12sB |\n";
      while (sd->recv() >= 0) {
         if (sscanf(sd->msg, "volume=%127s", mr.VolumeName) != 1) {
            if (sd->msg[0] == '3') {
               ua->send_msg("%s", sd->msg);
            }
            continue;
         }
         unbash_spaces(mr.VolumeName);
         mr.MediaId = 0;
         if (mr.VolumeName[0] && db_get_media_record(ua->jcr, ua->db, &mr)) {
            memset(&pr, 0, sizeof(POOL_DBR));
            pr.PoolId = mr.PoolId;
            if (!db_get_pool_record(ua->jcr, ua->db, &pr)) {
               strcpy(pr.Name, "?");
            }
            if (first) {
               ua->send_msg(_("+--------------------+-----------+----------------------+----------------------+---------------+\n"));
               ua->send_msg(_("|    Volume Name     |   Status  |     Media Type       |       Pool           |    VolBytes   |\n"));
               ua->send_msg(_("+--------------------+-----------+----------------------+----------------------+---------------+\n"));
               first=false;
            }
            ua->send_msg(output_hformat, mr.VolumeName, mr.VolStatus, mr.MediaType, pr.Name,
                         edit_uint64_with_suffix(mr.VolBytes, ed1));
         }
      }
      if (!first) {
         ua->send_msg(_("+--------------------+-----------+----------------------+----------------------+---------------+\n"));
      }
   }
bail_out:
   close_db(ua);
   close_sd_bsock(ua);
   ua->jcr->wstore = NULL;
   return 1;
}
static int cloud_list_cmd ( UAContext * ua , const char * cmd ) { int drive = -1 ; int64_t size , mtime ; STORE * store = NULL ; MEDIA_DBR mr ; POOL_DBR pr ; BSOCK * sd = NULL ; char storage [ MAX_NAME_LENGTH ] ; char ed1 [ 50 ] , ed2 [ 50 ] ; bool first = true ; uint32_t maxpart = 0 , part ; uint64_t maxpart_size = 0 ; memset ( & pr , 0 , sizeof ( pr ) ) ; memset ( & mr , 0 , sizeof ( mr ) ) ; for ( int i = 1 ; i < ua -> argc ; i ++ ) { if ( strcasecmp ( ua -> argk [ i ] , NT_ ( " " ) ) == 0 && is_name_valid ( ua -> argv [ i ] , NULL ) ) { bstrncpy ( mr . VolumeName , ua -> argv [ i ] , sizeof ( mr . VolumeName ) ) ; } else if ( strcasecmp ( ua -> argk [ i ] , NT_ ( " " ) ) == 0 && ua -> argv [ i ] ) { drive = atoi ( ua -> argv [ i ] ) ; } } if ( ! open_client_db ( ua ) ) { goto bail_out ; } ua -> jcr -> wstore = store = get_storage_resource ( ua , false ) ; if ( ! store ) { goto bail_out ; } bstrncpy ( storage , store -> dev_name ( ) , sizeof ( storage ) ) ; bstrncpy ( mr . MediaType , store -> media_type , sizeof ( mr . MediaType ) ) ; if ( ( sd = open_sd_bsock ( ua ) ) == NULL ) { Dmsg0 ( 100 , " \n " ) ; goto bail_out ; } bash_spaces ( mr . MediaType ) ; bash_spaces ( storage ) ; bash_spaces ( mr . VolumeName ) ; sd -> fsend ( " \n " , storage , mr . VolumeName , mr . MediaType , mr . Slot , drive ) ; if ( mr . VolumeName [ 0 ] ) { const char * output_hformat = " \n " ; uint64_t volsize = 0 ; while ( sd -> recv ( ) >= 0 ) { if ( sscanf ( sd -> msg , " " , & part , & size , & mtime ) != 3 ) { if ( sd -> msg [ 0 ] == ' ' ) { ua -> send_msg ( " " , sd -> msg ) ; } continue ; } if ( first ) { ua -> send_msg ( _ ( " \n " ) ) ; ua -> send_msg ( _ ( " \n " ) ) ; ua -> send_msg ( _ ( " \n " ) ) ; first = false ; } if ( part > maxpart ) { maxpart = part ; maxpart_size = size ; } volsize += size ; ua -> send_msg ( output_hformat , part , edit_uint64_with_suffix ( size , ed1 ) , bstrftimes ( ed2 , sizeof ( ed2 ) , mtime ) ) ; } if ( ! first ) { ua -> send_msg ( _ ( " \n " ) ) ; } if ( db_get_media_record ( ua -> jcr , ua -> db , & mr ) ) { POOL_MEM errmsg , tmpmsg ; if ( mr . LastPartBytes != maxpart_size ) { Mmsg ( tmpmsg , " \" \" \n " , mr . VolumeName , mr . LastPartBytes , maxpart_size ) ; pm_strcpy ( errmsg , tmpmsg . c_str ( ) ) ; } if ( mr . VolCloudParts != maxpart ) { Mmsg ( tmpmsg , " \" \" \n " , mr . VolumeName , mr . VolCloudParts , maxpart ) ; pm_strcpy ( errmsg , tmpmsg . c_str ( ) ) ; } if ( strlen ( errmsg . c_str ( ) ) > 0 ) { ua -> error_msg ( " \n " , errmsg . c_str ( ) ) ; } } } else { const char * output_hformat = " \n " ; while ( sd -> recv ( ) >= 0 ) { if ( sscanf ( sd -> msg , " " , mr . VolumeName ) != 1 ) { if ( sd -> msg [ 0 ] == ' ' ) { ua -> send_msg ( " " , sd -> msg ) ; } continue ; } unbash_spaces ( mr . VolumeName ) ; mr . MediaId = 0 ; if ( mr . VolumeName [ 0 ] && db_get_media_record ( ua -> jcr , ua -> db , & mr ) ) { memset ( & pr , 0 , sizeof ( POOL_DBR ) ) ; pr . PoolId = mr . PoolId ; if ( ! db_get_pool_record ( ua -> jcr , ua -> db , & pr ) ) { strcpy ( pr . Name , " " ) ; } if ( first ) { ua -> send_msg ( _ ( " \n " ) ) ; ua -> send_msg ( _ ( " \n " ) ) ; ua -> send_msg ( _ ( " \n " ) ) ; first = false ; } ua -> send_msg ( output_hformat , mr . VolumeName , mr . VolStatus , mr . MediaType , pr . Name , edit_uint64_with_suffix ( mr . VolBytes , ed1 ) ) ; } } if ( ! first ) { ua -> send_msg ( _ ( " \n " ) ) ; } } bail_out : close_db ( ua ) ; close_sd_bsock ( ua ) ; ua -> jcr -> wstore = NULL ; return 1 ; }
List volumes in the cloud
TODO: Update the code for .api 2 and llist
List volumes in the cloud TODO : Update the code for . api 2 and llist
/* Look at arguments */ /* Choose storage */ /* Protect us from spaces */ /* Want to list parts */ /* Check for valid response */ /* Print information */ /* TODO: See if we fix the catalog record directly */ /* TODO: Get the last part if possible? */ /* Check for valid response */ /* Print information */