src/stored/vbackup.c
static bool record_cb(DCR *dcr, DEV_RECORD *rec)
{
   JCR *jcr = dcr->jcr;
   DEVICE *dev = jcr->dcr->dev;
   char buf1[100], buf2[100];
   bool     restoredatap = false;
   POOLMEM *orgdata = NULL;
   uint32_t orgdata_len = 0;
   bool ret = false;

   /* If label and not for us, discard it */
   if (rec->FileIndex < 0 && rec->match_stat <= 0) {
      ret = true;
      goto bail_out;
   }
   /* We want to write SOS_LABEL and EOS_LABEL discard all others */
   switch (rec->FileIndex) {
   case PRE_LABEL:
   case VOL_LABEL:
   case EOT_LABEL:
   case EOM_LABEL:
      ret = true;                    /* don't write vol labels */
      goto bail_out;
   }

   /*
    * For normal migration jobs, FileIndex values are sequential because
    *  we are dealing with one job.  However, for Vbackup (consolidation),
    *  we will be getting records from multiple jobs and writing them back
    *  out, so we need to ensure that the output FileIndex is sequential.
    *  We do so by detecting a FileIndex change and incrementing the
    *  JobFiles, which we then use as the output FileIndex.
    */
   if (rec->FileIndex >= 0) {
      /* If something changed, increment FileIndex */
      if (rec->VolSessionId != rec->last_VolSessionId ||
          rec->VolSessionTime != rec->last_VolSessionTime ||
          rec->FileIndex != rec->last_FileIndex) {
         jcr->JobFiles++;
         rec->last_VolSessionId = rec->VolSessionId;
         rec->last_VolSessionTime = rec->VolSessionTime;
         rec->last_FileIndex = rec->FileIndex;
      }
      rec->FileIndex = jcr->JobFiles;     /* set sequential output FileIndex */
   }

   /* TODO: If user really wants to do rehydrate the data, we should propose
    * this option.
    */

   /*
    * Modify record SessionId and SessionTime to correspond to
    * output.
    */
   rec->VolSessionId = jcr->VolSessionId;
   rec->VolSessionTime = jcr->VolSessionTime;
   Dmsg5(200, "before write JobId=%d FI=%s SessId=%d Strm=%s len=%d\n",
      jcr->JobId,
      FI_to_ascii(buf1, rec->FileIndex), rec->VolSessionId,
      stream_to_ascii(buf2, rec->Stream, rec->FileIndex), rec->data_len);

   if (!jcr->dcr->write_record(rec)) {
      Jmsg2(jcr, M_FATAL, 0, _("Fatal append error on device %s: ERR=%s\n"),
            dev->print_name(), dev->bstrerror());
      goto bail_out;
   }
   /* Restore packet */
   rec->VolSessionId = rec->last_VolSessionId;
   rec->VolSessionTime = rec->last_VolSessionTime;
   if (rec->FileIndex < 0) {
      ret = true;                    /* don't send LABELs to Dir */
      goto bail_out;
   }
   jcr->JobBytes += rec->data_len;   /* increment bytes this job */
   Dmsg5(500, "wrote_record JobId=%d FI=%s SessId=%d Strm=%s len=%d\n",
      jcr->JobId,
      FI_to_ascii(buf1, rec->FileIndex), rec->VolSessionId,
      stream_to_ascii(buf2, rec->Stream, rec->FileIndex), rec->data_len);

   send_attrs_to_dir(jcr, rec);
   ret = true;

bail_out:
   if (restoredatap) {
      rec->data = orgdata;
      rec->data_len = orgdata_len;
   }
   return ret;
}
/*
 * Called here for each record from read_records()
 *  Returns: true if OK
 *           false if error
 */
Called here for each record from read_records()
Returns: true if OK
false if error
Called here for each record from read_records () Returns : true if OK false if error
static bool record_cb(DCR *dcr, DEV_RECORD *rec)
{
   JCR *jcr = dcr->jcr;
   DEVICE *dev = jcr->dcr->dev;
   char buf1[100], buf2[100];
   bool     restoredatap = false;
   POOLMEM *orgdata = NULL;
   uint32_t orgdata_len = 0;
   bool ret = false;
   if (rec->FileIndex < 0 && rec->match_stat <= 0) {
      ret = true;
      goto bail_out;
   }
   switch (rec->FileIndex) {
   case PRE_LABEL:
   case VOL_LABEL:
   case EOT_LABEL:
   case EOM_LABEL:
      ret = true;                    
      goto bail_out;
   }
   if (rec->FileIndex >= 0) {
      if (rec->VolSessionId != rec->last_VolSessionId ||
          rec->VolSessionTime != rec->last_VolSessionTime ||
          rec->FileIndex != rec->last_FileIndex) {
         jcr->JobFiles++;
         rec->last_VolSessionId = rec->VolSessionId;
         rec->last_VolSessionTime = rec->VolSessionTime;
         rec->last_FileIndex = rec->FileIndex;
      }
      rec->FileIndex = jcr->JobFiles;     
   }
   rec->VolSessionId = jcr->VolSessionId;
   rec->VolSessionTime = jcr->VolSessionTime;
   Dmsg5(200, "before write JobId=%d FI=%s SessId=%d Strm=%s len=%d\n",
      jcr->JobId,
      FI_to_ascii(buf1, rec->FileIndex), rec->VolSessionId,
      stream_to_ascii(buf2, rec->Stream, rec->FileIndex), rec->data_len);
   if (!jcr->dcr->write_record(rec)) {
      Jmsg2(jcr, M_FATAL, 0, _("Fatal append error on device %s: ERR=%s\n"),
            dev->print_name(), dev->bstrerror());
      goto bail_out;
   }
   rec->VolSessionId = rec->last_VolSessionId;
   rec->VolSessionTime = rec->last_VolSessionTime;
   if (rec->FileIndex < 0) {
      ret = true;                    
      goto bail_out;
   }
   jcr->JobBytes += rec->data_len;   
   Dmsg5(500, "wrote_record JobId=%d FI=%s SessId=%d Strm=%s len=%d\n",
      jcr->JobId,
      FI_to_ascii(buf1, rec->FileIndex), rec->VolSessionId,
      stream_to_ascii(buf2, rec->Stream, rec->FileIndex), rec->data_len);
   send_attrs_to_dir(jcr, rec);
   ret = true;
bail_out:
   if (restoredatap) {
      rec->data = orgdata;
      rec->data_len = orgdata_len;
   }
   return ret;
}
static bool record_cb ( DCR * dcr , DEV_RECORD * rec ) { JCR * jcr = dcr -> jcr ; DEVICE * dev = jcr -> dcr -> dev ; char buf1 [ 100 ] , buf2 [ 100 ] ; bool restoredatap = false ; POOLMEM * orgdata = NULL ; uint32_t orgdata_len = 0 ; bool ret = false ; if ( rec -> FileIndex < 0 && rec -> match_stat <= 0 ) { ret = true ; goto bail_out ; } switch ( rec -> FileIndex ) { case PRE_LABEL : case VOL_LABEL : case EOT_LABEL : case EOM_LABEL : ret = true ; goto bail_out ; } if ( rec -> FileIndex >= 0 ) { if ( rec -> VolSessionId != rec -> last_VolSessionId || rec -> VolSessionTime != rec -> last_VolSessionTime || rec -> FileIndex != rec -> last_FileIndex ) { jcr -> JobFiles ++ ; rec -> last_VolSessionId = rec -> VolSessionId ; rec -> last_VolSessionTime = rec -> VolSessionTime ; rec -> last_FileIndex = rec -> FileIndex ; } rec -> FileIndex = jcr -> JobFiles ; } rec -> VolSessionId = jcr -> VolSessionId ; rec -> VolSessionTime = jcr -> VolSessionTime ; Dmsg5 ( 200 , " \n " , jcr -> JobId , FI_to_ascii ( buf1 , rec -> FileIndex ) , rec -> VolSessionId , stream_to_ascii ( buf2 , rec -> Stream , rec -> FileIndex ) , rec -> data_len ) ; if ( ! jcr -> dcr -> write_record ( rec ) ) { Jmsg2 ( jcr , M_FATAL , 0 , _ ( " \n " ) , dev -> print_name ( ) , dev -> bstrerror ( ) ) ; goto bail_out ; } rec -> VolSessionId = rec -> last_VolSessionId ; rec -> VolSessionTime = rec -> last_VolSessionTime ; if ( rec -> FileIndex < 0 ) { ret = true ; goto bail_out ; } jcr -> JobBytes += rec -> data_len ; Dmsg5 ( 500 , " \n " , jcr -> JobId , FI_to_ascii ( buf1 , rec -> FileIndex ) , rec -> VolSessionId , stream_to_ascii ( buf2 , rec -> Stream , rec -> FileIndex ) , rec -> data_len ) ; send_attrs_to_dir ( jcr , rec ) ; ret = true ; bail_out : if ( restoredatap ) { rec -> data = orgdata ; rec -> data_len = orgdata_len ; } return ret ; }
Called here for each record from read_records()
  Returns: true if OK
           false if error
Called here for each record from read_records () Returns : true if OK false if error
/* If label and not for us, discard it */ /* We want to write SOS_LABEL and EOS_LABEL discard all others */ /* don't write vol labels */ /*
    * For normal migration jobs, FileIndex values are sequential because
    *  we are dealing with one job.  However, for Vbackup (consolidation),
    *  we will be getting records from multiple jobs and writing them back
    *  out, so we need to ensure that the output FileIndex is sequential.
    *  We do so by detecting a FileIndex change and incrementing the
    *  JobFiles, which we then use as the output FileIndex.
    */ /* If something changed, increment FileIndex */ /* set sequential output FileIndex */ /* TODO: If user really wants to do rehydrate the data, we should propose
    * this option.
    */ /*
    * Modify record SessionId and SessionTime to correspond to
    * output.
    */ /* Restore packet */ /* don't send LABELs to Dir */ /* increment bytes this job */