src/filed/backup.c
bool blast_data_to_storage_daemon(JCR *jcr, char *addr)
{
   BSOCK *sd;
   bool ok = true;
   // TODO landonf: Allow user to specify encryption algorithm

   sd = jcr->store_bsock;

   jcr->setJobStatus(JS_Running);

   Dmsg1(300, "bfiled: opened data connection %d to stored\n", sd->m_fd);

   LockRes();
   CLIENT *client = (CLIENT *)GetNextRes(R_CLIENT, NULL);
   UnlockRes();
   uint32_t buf_size;
   if (client) {
      buf_size = client->max_network_buffer_size;
   } else {
      buf_size = 0;                   /* use default */
   }
   if (!sd->set_buffer_size(buf_size, BNET_SETBUF_WRITE)) {
      jcr->setJobStatus(JS_ErrorTerminated);
      Jmsg(jcr, M_FATAL, 0, _("Cannot set buffer size FD->SD.\n"));
      return false;
   }

   jcr->buf_size = sd->msglen;
   /**
    * Adjust for compression so that output buffer is
    *  12 bytes + 0.1% larger than input buffer plus 18 bytes.
    *  This gives a bit extra plus room for the sparse addr if any.
    *  Note, we adjust the read size to be smaller so that the
    *  same output buffer can be used without growing it.
    *
    *  For LZO1X compression the recommended value is :
    *                  output_block_size = input_block_size + (input_block_size / 16) + 64 + 3 + sizeof(comp_stream_header)
    *
    * The zlib compression workset is initialized here to minimize
    *  the "per file" load. The jcr member is only set, if the init
    *  was successful.
    *
    *  For the same reason, lzo compression is initialized here.
    */
   if (have_lzo) {
      jcr->compress_buf_size = MAX(jcr->buf_size + (jcr->buf_size / 16) + 67 + (int)sizeof(comp_stream_header), jcr->buf_size + ((jcr->buf_size+999) / 1000) + 30);
      jcr->compress_buf = get_memory(jcr->compress_buf_size);
   } else {
      jcr->compress_buf_size = jcr->buf_size + ((jcr->buf_size+999) / 1000) + 30;
      jcr->compress_buf = get_memory(jcr->compress_buf_size);
   }

#ifdef HAVE_LIBZ
   z_stream *pZlibStream = (z_stream*)malloc(sizeof(z_stream));
   if (pZlibStream) {
      pZlibStream->zalloc = Z_NULL;
      pZlibStream->zfree = Z_NULL;
      pZlibStream->opaque = Z_NULL;
      pZlibStream->state = Z_NULL;

      if (deflateInit(pZlibStream, Z_DEFAULT_COMPRESSION) == Z_OK) {
         jcr->pZLIB_compress_workset = pZlibStream;
      } else {
         free (pZlibStream);
      }
   }
#endif

#ifdef HAVE_LZO
   lzo_voidp pLzoMem = (lzo_voidp) malloc(LZO1X_1_MEM_COMPRESS);
   if (pLzoMem) {
      if (lzo_init() == LZO_E_OK) {
         jcr->LZO_compress_workset = pLzoMem;
      } else {
         free (pLzoMem);
      }
   }
#endif

   if (!crypto_session_start(jcr)) {
      return false;
   }

   set_find_options(jcr->ff, jcr->incremental, jcr->mtime);
   set_find_snapshot_function(jcr->ff, snapshot_convert_path);

   /** in accurate mode, we overload the find_one check function */
   if (jcr->accurate) {
      set_find_changed_function((FF_PKT *)jcr->ff, accurate_check_file);
   }
   start_heartbeat_monitor(jcr);

#ifdef HAVE_ACL
   jcr->bacl = (BACL*)new_bacl();
#endif
#ifdef HAVE_XATTR
   jcr->bxattr = (BXATTR*)new_bxattr();
#endif

   /* Subroutine save_file() is called for each file */
   if (!find_files(jcr, (FF_PKT *)jcr->ff, save_file, plugin_save)) {
      ok = false;                     /* error */
      jcr->setJobStatus(JS_ErrorTerminated);
   }
#ifdef HAVE_ACL
   if (jcr->bacl && jcr->bacl->get_acl_nr_errors() > 0) {
      Jmsg(jcr, M_WARNING, 0, _("Had %ld acl errors while doing backup\n"),
         jcr->bacl->get_acl_nr_errors());
   }
#endif
#ifdef HAVE_XATTR
   if (jcr->bxattr && jcr->bxattr->get_xattr_nr_errors() > 0) {
      Jmsg(jcr, M_WARNING, 0, _("Had %ld xattr errors while doing backup\n"),
         jcr->bxattr->get_xattr_nr_errors());
   }
#endif

   /* Delete or keep snapshots */
   close_snapshot_backup_session(jcr);
   close_vss_backup_session(jcr);

   accurate_finish(jcr);              /* send deleted or base file list to SD */

   stop_heartbeat_monitor(jcr);

   sd->signal(BNET_EOD);            /* end of sending data */

#ifdef HAVE_ACL
   if (jcr->bacl) {
      delete(jcr->bacl);
      jcr->bacl = NULL;
   }
#endif
#ifdef HAVE_XATTR
   if (jcr->bxattr) {
      delete(jcr->bxattr);
      jcr->bxattr = NULL;
   }
#endif
   if (jcr->big_buf) {
      bfree_and_null(jcr->big_buf);
   }
   if (jcr->compress_buf) {
      free_and_null_pool_memory(jcr->compress_buf);
   }
   if (jcr->pZLIB_compress_workset) {
      /* Free the zlib stream */
#ifdef HAVE_LIBZ
      deflateEnd((z_stream *)jcr->pZLIB_compress_workset);
#endif
      bfree_and_null(jcr->pZLIB_compress_workset);
   }
   if (jcr->LZO_compress_workset) {
      bfree_and_null(jcr->LZO_compress_workset);
   }

   crypto_session_end(jcr);


   Dmsg1(100, "end blast_data ok=%d\n", ok);
   return ok;
}
/**
 * Find all the requested files and send them
 * to the Storage daemon.
 *
 * Note, we normally carry on a one-way
 * conversation from this point on with the SD, simply blasting
 * data to him.  To properly know what is going on, we
 * also run a "heartbeat" monitor which reads the socket and
 * reacts accordingly (at the moment it has nothing to do
 * except echo the heartbeat to the Director).
 *
 */
Find all the requested files and send them
to the Storage daemon.

Note, we normally carry on a one-way
conversation from this point on with the SD, simply blasting
data to him.  To properly know what is going on, we
also run a "heartbeat" monitor which reads the socket and
reacts accordingly (at the moment it has nothing to do
except echo the heartbeat to the Director).
Find all the requested files and send them to the Storage daemon . Note we normally carry on a one - way conversation from this point on with the SD simply blasting data to him . To properly know what is going on we also run a " heartbeat " monitor which reads the socket and reacts accordingly ( at the moment it has nothing to do except echo the heartbeat to the Director ) .
bool blast_data_to_storage_daemon(JCR *jcr, char *addr)
{
   BSOCK *sd;
   bool ok = true;
   sd = jcr->store_bsock;
   jcr->setJobStatus(JS_Running);
   Dmsg1(300, "bfiled: opened data connection %d to stored\n", sd->m_fd);
   LockRes();
   CLIENT *client = (CLIENT *)GetNextRes(R_CLIENT, NULL);
   UnlockRes();
   uint32_t buf_size;
   if (client) {
      buf_size = client->max_network_buffer_size;
   } else {
      buf_size = 0;                   
   }
   if (!sd->set_buffer_size(buf_size, BNET_SETBUF_WRITE)) {
      jcr->setJobStatus(JS_ErrorTerminated);
      Jmsg(jcr, M_FATAL, 0, _("Cannot set buffer size FD->SD.\n"));
      return false;
   }
   jcr->buf_size = sd->msglen;
   if (have_lzo) {
      jcr->compress_buf_size = MAX(jcr->buf_size + (jcr->buf_size / 16) + 67 + (int)sizeof(comp_stream_header), jcr->buf_size + ((jcr->buf_size+999) / 1000) + 30);
      jcr->compress_buf = get_memory(jcr->compress_buf_size);
   } else {
      jcr->compress_buf_size = jcr->buf_size + ((jcr->buf_size+999) / 1000) + 30;
      jcr->compress_buf = get_memory(jcr->compress_buf_size);
   }
#ifdef HAVE_LIBZ
   z_stream *pZlibStream = (z_stream*)malloc(sizeof(z_stream));
   if (pZlibStream) {
      pZlibStream->zalloc = Z_NULL;
      pZlibStream->zfree = Z_NULL;
      pZlibStream->opaque = Z_NULL;
      pZlibStream->state = Z_NULL;
      if (deflateInit(pZlibStream, Z_DEFAULT_COMPRESSION) == Z_OK) {
         jcr->pZLIB_compress_workset = pZlibStream;
      } else {
         free (pZlibStream);
      }
   }
#endif
#ifdef HAVE_LZO
   lzo_voidp pLzoMem = (lzo_voidp) malloc(LZO1X_1_MEM_COMPRESS);
   if (pLzoMem) {
      if (lzo_init() == LZO_E_OK) {
         jcr->LZO_compress_workset = pLzoMem;
      } else {
         free (pLzoMem);
      }
   }
#endif
   if (!crypto_session_start(jcr)) {
      return false;
   }
   set_find_options(jcr->ff, jcr->incremental, jcr->mtime);
   set_find_snapshot_function(jcr->ff, snapshot_convert_path);
   if (jcr->accurate) {
      set_find_changed_function((FF_PKT *)jcr->ff, accurate_check_file);
   }
   start_heartbeat_monitor(jcr);
#ifdef HAVE_ACL
   jcr->bacl = (BACL*)new_bacl();
#endif
#ifdef HAVE_XATTR
   jcr->bxattr = (BXATTR*)new_bxattr();
#endif
   if (!find_files(jcr, (FF_PKT *)jcr->ff, save_file, plugin_save)) {
      ok = false;                     
      jcr->setJobStatus(JS_ErrorTerminated);
   }
#ifdef HAVE_ACL
   if (jcr->bacl && jcr->bacl->get_acl_nr_errors() > 0) {
      Jmsg(jcr, M_WARNING, 0, _("Had %ld acl errors while doing backup\n"),
         jcr->bacl->get_acl_nr_errors());
   }
#endif
#ifdef HAVE_XATTR
   if (jcr->bxattr && jcr->bxattr->get_xattr_nr_errors() > 0) {
      Jmsg(jcr, M_WARNING, 0, _("Had %ld xattr errors while doing backup\n"),
         jcr->bxattr->get_xattr_nr_errors());
   }
#endif
   close_snapshot_backup_session(jcr);
   close_vss_backup_session(jcr);
   accurate_finish(jcr);              
   stop_heartbeat_monitor(jcr);
   sd->signal(BNET_EOD);            
#ifdef HAVE_ACL
   if (jcr->bacl) {
      delete(jcr->bacl);
      jcr->bacl = NULL;
   }
#endif
#ifdef HAVE_XATTR
   if (jcr->bxattr) {
      delete(jcr->bxattr);
      jcr->bxattr = NULL;
   }
#endif
   if (jcr->big_buf) {
      bfree_and_null(jcr->big_buf);
   }
   if (jcr->compress_buf) {
      free_and_null_pool_memory(jcr->compress_buf);
   }
   if (jcr->pZLIB_compress_workset) {
#ifdef HAVE_LIBZ
      deflateEnd((z_stream *)jcr->pZLIB_compress_workset);
#endif
      bfree_and_null(jcr->pZLIB_compress_workset);
   }
   if (jcr->LZO_compress_workset) {
      bfree_and_null(jcr->LZO_compress_workset);
   }
   crypto_session_end(jcr);
   Dmsg1(100, "end blast_data ok=%d\n", ok);
   return ok;
}
bool blast_data_to_storage_daemon ( JCR * jcr , char * addr ) { BSOCK * sd ; bool ok = true ; sd = jcr -> store_bsock ; jcr -> setJobStatus ( JS_Running ) ; Dmsg1 ( 300 , " \n " , sd -> m_fd ) ; LockRes ( ) ; CLIENT * client = ( CLIENT * ) GetNextRes ( R_CLIENT , NULL ) ; UnlockRes ( ) ; uint32_t buf_size ; if ( client ) { buf_size = client -> max_network_buffer_size ; } else { buf_size = 0 ; } if ( ! sd -> set_buffer_size ( buf_size , BNET_SETBUF_WRITE ) ) { jcr -> setJobStatus ( JS_ErrorTerminated ) ; Jmsg ( jcr , M_FATAL , 0 , _ ( " \n " ) ) ; return false ; } jcr -> buf_size = sd -> msglen ; if ( have_lzo ) { jcr -> compress_buf_size = MAX ( jcr -> buf_size + ( jcr -> buf_size / 16 ) + 67 + ( int ) sizeof ( comp_stream_header ) , jcr -> buf_size + ( ( jcr -> buf_size + 999 ) / 1000 ) + 30 ) ; jcr -> compress_buf = get_memory ( jcr -> compress_buf_size ) ; } else { jcr -> compress_buf_size = jcr -> buf_size + ( ( jcr -> buf_size + 999 ) / 1000 ) + 30 ; jcr -> compress_buf = get_memory ( jcr -> compress_buf_size ) ; } #ifdef HAVE_LIBZ z_stream * pZlibStream = ( z_stream * ) malloc ( sizeof ( z_stream ) ) ; if ( pZlibStream ) { pZlibStream -> zalloc = Z_NULL ; pZlibStream -> zfree = Z_NULL ; pZlibStream -> opaque = Z_NULL ; pZlibStream -> state = Z_NULL ; if ( deflateInit ( pZlibStream , Z_DEFAULT_COMPRESSION ) == Z_OK ) { jcr -> pZLIB_compress_workset = pZlibStream ; } else { free ( pZlibStream ) ; } } #endif #ifdef HAVE_LZO lzo_voidp pLzoMem = ( lzo_voidp ) malloc ( LZO1X_1_MEM_COMPRESS ) ; if ( pLzoMem ) { if ( lzo_init ( ) == LZO_E_OK ) { jcr -> LZO_compress_workset = pLzoMem ; } else { free ( pLzoMem ) ; } } #endif if ( ! crypto_session_start ( jcr ) ) { return false ; } set_find_options ( jcr -> ff , jcr -> incremental , jcr -> mtime ) ; set_find_snapshot_function ( jcr -> ff , snapshot_convert_path ) ; if ( jcr -> accurate ) { set_find_changed_function ( ( FF_PKT * ) jcr -> ff , accurate_check_file ) ; } start_heartbeat_monitor ( jcr ) ; #ifdef HAVE_ACL jcr -> bacl = ( BACL * ) new_bacl ( ) ; #endif #ifdef HAVE_XATTR jcr -> bxattr = ( BXATTR * ) new_bxattr ( ) ; #endif if ( ! find_files ( jcr , ( FF_PKT * ) jcr -> ff , save_file , plugin_save ) ) { ok = false ; jcr -> setJobStatus ( JS_ErrorTerminated ) ; } #ifdef HAVE_ACL if ( jcr -> bacl && jcr -> bacl -> get_acl_nr_errors ( ) > 0 ) { Jmsg ( jcr , M_WARNING , 0 , _ ( " \n " ) , jcr -> bacl -> get_acl_nr_errors ( ) ) ; } #endif #ifdef HAVE_XATTR if ( jcr -> bxattr && jcr -> bxattr -> get_xattr_nr_errors ( ) > 0 ) { Jmsg ( jcr , M_WARNING , 0 , _ ( " \n " ) , jcr -> bxattr -> get_xattr_nr_errors ( ) ) ; } #endif close_snapshot_backup_session ( jcr ) ; close_vss_backup_session ( jcr ) ; accurate_finish ( jcr ) ; stop_heartbeat_monitor ( jcr ) ; sd -> signal ( BNET_EOD ) ; #ifdef HAVE_ACL if ( jcr -> bacl ) { delete ( jcr -> bacl ) ; jcr -> bacl = NULL ; } #endif #ifdef HAVE_XATTR if ( jcr -> bxattr ) { delete ( jcr -> bxattr ) ; jcr -> bxattr = NULL ; } #endif if ( jcr -> big_buf ) { bfree_and_null ( jcr -> big_buf ) ; } if ( jcr -> compress_buf ) { free_and_null_pool_memory ( jcr -> compress_buf ) ; } if ( jcr -> pZLIB_compress_workset ) { #ifdef HAVE_LIBZ deflateEnd ( ( z_stream * ) jcr -> pZLIB_compress_workset ) ; #endif bfree_and_null ( jcr -> pZLIB_compress_workset ) ; } if ( jcr -> LZO_compress_workset ) { bfree_and_null ( jcr -> LZO_compress_workset ) ; } crypto_session_end ( jcr ) ; Dmsg1 ( 100 , " \n " , ok ) ; return ok ; }
Find all the requested files and send them
 to the Storage daemon.
Find all the requested files and send them to the Storage daemon .
// TODO landonf: Allow user to specify encryption algorithm /* use default */ /**
    * Adjust for compression so that output buffer is
    *  12 bytes + 0.1% larger than input buffer plus 18 bytes.
    *  This gives a bit extra plus room for the sparse addr if any.
    *  Note, we adjust the read size to be smaller so that the
    *  same output buffer can be used without growing it.
    *
    *  For LZO1X compression the recommended value is :
    *                  output_block_size = input_block_size + (input_block_size / 16) + 64 + 3 + sizeof(comp_stream_header)
    *
    * The zlib compression workset is initialized here to minimize
    *  the "per file" load. The jcr member is only set, if the init
    *  was successful.
    *
    *  For the same reason, lzo compression is initialized here.
    */ /** in accurate mode, we overload the find_one check function */ /* Subroutine save_file() is called for each file */ /* error */ /* Delete or keep snapshots */ /* send deleted or base file list to SD */ /* end of sending data */ /* Free the zlib stream */