src/dird/ua_cmds.c
int cloud_volumes_cmd(UAContext *ua, const char *cmd, const char *mode)
{
   int drive = -1;
   int nb = 0;
   uint32_t *results = NULL;
   MEDIA_DBR mr;
   POOL_DBR pr;
   BSOCK *sd = NULL;
   char storage[MAX_NAME_LENGTH];
   const char *action = mode;
   memset(&pr, 0, sizeof(pr));

   /*
    * Look for all volumes that are enabled and
    *  have more the 200 bytes.
    */
   mr.Enabled = 1;
   mr.Recycle = -1;             /* All Recycle status */
   if (strcmp("prunecache", mode) == 0) {
      mr.CacheRetention = 1;
      action = "truncate cache";
   }

   if (!scan_storage_cmd(ua, cmd, false, /* fromallpool*/
                         &drive, &mr, &pr, NULL, storage,
                         &nb, &results))
   {
      goto bail_out;
   }

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

   /*
    * Loop over the candidate Volumes and upload parts
    */
   for (int i=0; i < nb; i++) {
      bool ok=false;
      mr.clear();
      mr.MediaId = results[i];
      if (!db_get_media_record(ua->jcr, ua->db, &mr)) {
         goto bail_out;
      }

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

      sd->fsend("%s Storage=%s Volume=%s PoolName=%s MediaType=%s "
                "Slot=%d drive=%d CacheRetention=%lld\n",
                action, storage, mr.VolumeName, pr.Name, mr.MediaType,
                mr.Slot, drive, mr.CacheRetention);

      unbash_spaces(mr.VolumeName);
      unbash_spaces(mr.MediaType);
      unbash_spaces(pr.Name);
      unbash_spaces(storage);

      /* Check for valid response */
      while (bget_dirmsg(sd) >= 0) {
         if (strncmp(sd->msg, "3000 OK truncate cache", 22) == 0) {
            ua->send_msg("%s", sd->msg);
            ok = true;

         } else if (strncmp(sd->msg, "3000 OK", 7) == 0) {
            ua->send_msg(_("The volume \"%s\" has been uploaded\n"), mr.VolumeName);
            ok = true;


         } else if (strncmp(sd->msg, "39", 2) == 0) {
            ua->warning_msg("%s", sd->msg);

         } else {
            ua->send_msg("%s", sd->msg);
         }
      }
      if (!ok) {
         ua->warning_msg(_("Unable to %s for volume \"%s\"\n"), action, mr.VolumeName);
      }
   }

bail_out:
   close_db(ua);
   close_sd_bsock(ua);
   ua->jcr->wstore = NULL;
   if (results) {
      free(results);
   }

   return 1;
}
/*
 * cloud functions, like to upload cached parts to cloud.
 */
cloud functions, like to upload cached parts to cloud.
cloud functions like to upload cached parts to cloud .
int cloud_volumes_cmd(UAContext *ua, const char *cmd, const char *mode)
{
   int drive = -1;
   int nb = 0;
   uint32_t *results = NULL;
   MEDIA_DBR mr;
   POOL_DBR pr;
   BSOCK *sd = NULL;
   char storage[MAX_NAME_LENGTH];
   const char *action = mode;
   memset(&pr, 0, sizeof(pr));
   mr.Enabled = 1;
   mr.Recycle = -1;             
   if (strcmp("prunecache", mode) == 0) {
      mr.CacheRetention = 1;
      action = "truncate cache";
   }
   if (!scan_storage_cmd(ua, cmd, false, 
                         &drive, &mr, &pr, NULL, storage,
                         &nb, &results))
   {
      goto bail_out;
   }
   if ((sd=open_sd_bsock(ua)) == NULL) {
      Dmsg0(100, "Can't open connection to sd\n");
      goto bail_out;
   }
   for (int i=0; i < nb; i++) {
      bool ok=false;
      mr.clear();
      mr.MediaId = results[i];
      if (!db_get_media_record(ua->jcr, ua->db, &mr)) {
         goto bail_out;
      }
      bash_spaces(mr.VolumeName);
      bash_spaces(mr.MediaType);
      bash_spaces(pr.Name);
      bash_spaces(storage);
      sd->fsend("%s Storage=%s Volume=%s PoolName=%s MediaType=%s "
                "Slot=%d drive=%d CacheRetention=%lld\n",
                action, storage, mr.VolumeName, pr.Name, mr.MediaType,
                mr.Slot, drive, mr.CacheRetention);
      unbash_spaces(mr.VolumeName);
      unbash_spaces(mr.MediaType);
      unbash_spaces(pr.Name);
      unbash_spaces(storage);
      while (bget_dirmsg(sd) >= 0) {
         if (strncmp(sd->msg, "3000 OK truncate cache", 22) == 0) {
            ua->send_msg("%s", sd->msg);
            ok = true;
         } else if (strncmp(sd->msg, "3000 OK", 7) == 0) {
            ua->send_msg(_("The volume \"%s\" has been uploaded\n"), mr.VolumeName);
            ok = true;
         } else if (strncmp(sd->msg, "39", 2) == 0) {
            ua->warning_msg("%s", sd->msg);
         } else {
            ua->send_msg("%s", sd->msg);
         }
      }
      if (!ok) {
         ua->warning_msg(_("Unable to %s for volume \"%s\"\n"), action, mr.VolumeName);
      }
   }
bail_out:
   close_db(ua);
   close_sd_bsock(ua);
   ua->jcr->wstore = NULL;
   if (results) {
      free(results);
   }
   return 1;
}
int cloud_volumes_cmd ( UAContext * ua , const char * cmd , const char * mode ) { int drive = -1 ; int nb = 0 ; uint32_t * results = NULL ; MEDIA_DBR mr ; POOL_DBR pr ; BSOCK * sd = NULL ; char storage [ MAX_NAME_LENGTH ] ; const char * action = mode ; memset ( & pr , 0 , sizeof ( pr ) ) ; mr . Enabled = 1 ; mr . Recycle = -1 ; if ( strcmp ( " " , mode ) == 0 ) { mr . CacheRetention = 1 ; action = " " ; } if ( ! scan_storage_cmd ( ua , cmd , false , & drive , & mr , & pr , NULL , storage , & nb , & results ) ) { goto bail_out ; } if ( ( sd = open_sd_bsock ( ua ) ) == NULL ) { Dmsg0 ( 100 , " \n " ) ; goto bail_out ; } for ( int i = 0 ; i < nb ; i ++ ) { bool ok = false ; mr . clear ( ) ; mr . MediaId = results [ i ] ; if ( ! db_get_media_record ( ua -> jcr , ua -> db , & mr ) ) { goto bail_out ; } bash_spaces ( mr . VolumeName ) ; bash_spaces ( mr . MediaType ) ; bash_spaces ( pr . Name ) ; bash_spaces ( storage ) ; sd -> fsend ( " " " \n " , action , storage , mr . VolumeName , pr . Name , mr . MediaType , mr . Slot , drive , mr . CacheRetention ) ; unbash_spaces ( mr . VolumeName ) ; unbash_spaces ( mr . MediaType ) ; unbash_spaces ( pr . Name ) ; unbash_spaces ( storage ) ; while ( bget_dirmsg ( sd ) >= 0 ) { if ( strncmp ( sd -> msg , " " , 22 ) == 0 ) { ua -> send_msg ( " " , sd -> msg ) ; ok = true ; } else if ( strncmp ( sd -> msg , " " , 7 ) == 0 ) { ua -> send_msg ( _ ( " \" \" \n " ) , mr . VolumeName ) ; ok = true ; } else if ( strncmp ( sd -> msg , " " , 2 ) == 0 ) { ua -> warning_msg ( " " , sd -> msg ) ; } else { ua -> send_msg ( " " , sd -> msg ) ; } } if ( ! ok ) { ua -> warning_msg ( _ ( " \" \" \n " ) , action , mr . VolumeName ) ; } } bail_out : close_db ( ua ) ; close_sd_bsock ( ua ) ; ua -> jcr -> wstore = NULL ; if ( results ) { free ( results ) ; } return 1 ; }
cloud functions, like to upload cached parts to cloud.
cloud functions like to upload cached parts to cloud .
/*
    * Look for all volumes that are enabled and
    *  have more the 200 bytes.
    */ /* All Recycle status */ /* fromallpool*/ /*
    * Loop over the candidate Volumes and upload parts
    */ /* Protect us from spaces */ /* Check for valid response */