src/dird/snapshot.c
int snapshot_catreq(JCR *jcr, BSOCK *bs)
{
   SNAPSHOT_DBR snapdbr;
   char Job[MAX_NAME_LENGTH], ed1[50];
   POOLMEM *vol = get_memory(bs->msglen);
   POOLMEM *dev = get_memory(bs->msglen);
   POOLMEM *err = get_pool_memory(PM_MESSAGE);
   int n, ret = 1, expired;
   *vol = *dev = 0;

   Dmsg1(DT_SNAPSHOT|10, "Get snapshot catalog request %s\n", bs->msg);

   /* We need to create a snapshot record in the catalog */
   n = sscanf(bs->msg, CreateSnap, Job, snapdbr.Name, vol, dev, 
              &snapdbr.CreateTDate, snapdbr.Type, ed1);
   if (n == 7) {
      snapdbr.Volume = vol;
      snapdbr.Device = dev;
      snapdbr.JobId = jcr->JobId;
      unbash_spaces(snapdbr.Name);
      unbash_spaces(snapdbr.Volume);
      unbash_spaces(snapdbr.Device);
      snapdbr.Retention = str_to_uint64(ed1);
      bstrftimes(snapdbr.CreateDate, sizeof(snapdbr.CreateDate), snapdbr.CreateTDate);
      unbash_spaces(snapdbr.Type);
      bstrncpy(snapdbr.Client, jcr->client->hdr.name, sizeof(snapdbr.Client));
      bstrncpy(snapdbr.FileSet, (jcr->fileset)?jcr->fileset->hdr.name:"", sizeof(snapdbr.FileSet));

      Dmsg1(DT_SNAPSHOT|10, "Creating snapshot %s\n", snapdbr.Name);
      snapdbr.debug(20);

      /* We lock the db before to keep the error message */
      db_lock(jcr->db);
      ret = db_create_snapshot_record(jcr, jcr->db, &snapdbr);
      pm_strcpy(err, jcr->db->errmsg);
      db_unlock(jcr->db);

      if (ret) {
         bs->fsend("1000 Snapshot created\n");

      } else {
         bs->fsend("1999 Snapshot not created ERR=%s\n", err);
      }
      goto bail_out;
   }

   n = sscanf(bs->msg, ListSnap, Job, snapdbr.Name, vol, dev, &snapdbr.CreateTDate, snapdbr.Type,
              snapdbr.created_before, snapdbr.created_after, &expired);
   if (n == 8) {
      snapdbr.Volume = vol;
      snapdbr.Device = dev;
      unbash_spaces(snapdbr.Name);
      unbash_spaces(snapdbr.Volume);
      unbash_spaces(snapdbr.Device);
      bstrftimes(snapdbr.CreateDate, sizeof(snapdbr.CreateDate), snapdbr.CreateTDate);
      unbash_spaces(snapdbr.Type);
      unbash_spaces(snapdbr.created_before);
      unbash_spaces(snapdbr.created_after);
      bstrncpy(snapdbr.Client, jcr->client->hdr.name, sizeof(snapdbr.Client));
      snapdbr.expired = (expired != 0);
      Dmsg0(DT_SNAPSHOT|10, "List snapshots\n");
      snapdbr.debug(20);
      db_list_snapshot_records(jcr, jcr->db, &snapdbr, send_list, bs, ARG_LIST);
      bs->signal(BNET_EOD);
      goto bail_out;
   }

   n = sscanf(bs->msg, DelSnap, Job, snapdbr.Name, dev);
   if (n == 3) {
      snapdbr.Device = dev;
      unbash_spaces(snapdbr.Name);
      unbash_spaces(snapdbr.Device);
      bstrncpy(snapdbr.Client, jcr->client->hdr.name, sizeof(snapdbr.Client));
      Dmsg2(DT_SNAPSHOT|10, "Delete snapshot %s from %s\n", snapdbr.Name, snapdbr.Client);
      snapdbr.debug(20);      

      /* We lock the db before to keep the error message */
      db_lock(jcr->db);
      ret = db_delete_snapshot_record(jcr, jcr->db, &snapdbr);
      pm_strcpy(err, jcr->db->errmsg);
      db_unlock(jcr->db);

      if (ret) {
         bs->fsend("1000 Snapshot deleted\n");

      } else {
         bs->fsend("1999 Snapshot not deleted ERR=%s\n", err);
      }
      goto bail_out;
   }
   ret = 0;

bail_out:
   free_pool_memory(vol);
   free_pool_memory(dev);
   free_pool_memory(err);
   return ret;
}
/* Called from the FD, in catreq.c */
Called from the FD, in catreq.c
Called from the FD in catreq . c
int snapshot_catreq(JCR *jcr, BSOCK *bs)
{
   SNAPSHOT_DBR snapdbr;
   char Job[MAX_NAME_LENGTH], ed1[50];
   POOLMEM *vol = get_memory(bs->msglen);
   POOLMEM *dev = get_memory(bs->msglen);
   POOLMEM *err = get_pool_memory(PM_MESSAGE);
   int n, ret = 1, expired;
   *vol = *dev = 0;
   Dmsg1(DT_SNAPSHOT|10, "Get snapshot catalog request %s\n", bs->msg);
   n = sscanf(bs->msg, CreateSnap, Job, snapdbr.Name, vol, dev, 
              &snapdbr.CreateTDate, snapdbr.Type, ed1);
   if (n == 7) {
      snapdbr.Volume = vol;
      snapdbr.Device = dev;
      snapdbr.JobId = jcr->JobId;
      unbash_spaces(snapdbr.Name);
      unbash_spaces(snapdbr.Volume);
      unbash_spaces(snapdbr.Device);
      snapdbr.Retention = str_to_uint64(ed1);
      bstrftimes(snapdbr.CreateDate, sizeof(snapdbr.CreateDate), snapdbr.CreateTDate);
      unbash_spaces(snapdbr.Type);
      bstrncpy(snapdbr.Client, jcr->client->hdr.name, sizeof(snapdbr.Client));
      bstrncpy(snapdbr.FileSet, (jcr->fileset)?jcr->fileset->hdr.name:"", sizeof(snapdbr.FileSet));
      Dmsg1(DT_SNAPSHOT|10, "Creating snapshot %s\n", snapdbr.Name);
      snapdbr.debug(20);
      db_lock(jcr->db);
      ret = db_create_snapshot_record(jcr, jcr->db, &snapdbr);
      pm_strcpy(err, jcr->db->errmsg);
      db_unlock(jcr->db);
      if (ret) {
         bs->fsend("1000 Snapshot created\n");
      } else {
         bs->fsend("1999 Snapshot not created ERR=%s\n", err);
      }
      goto bail_out;
   }
   n = sscanf(bs->msg, ListSnap, Job, snapdbr.Name, vol, dev, &snapdbr.CreateTDate, snapdbr.Type,
              snapdbr.created_before, snapdbr.created_after, &expired);
   if (n == 8) {
      snapdbr.Volume = vol;
      snapdbr.Device = dev;
      unbash_spaces(snapdbr.Name);
      unbash_spaces(snapdbr.Volume);
      unbash_spaces(snapdbr.Device);
      bstrftimes(snapdbr.CreateDate, sizeof(snapdbr.CreateDate), snapdbr.CreateTDate);
      unbash_spaces(snapdbr.Type);
      unbash_spaces(snapdbr.created_before);
      unbash_spaces(snapdbr.created_after);
      bstrncpy(snapdbr.Client, jcr->client->hdr.name, sizeof(snapdbr.Client));
      snapdbr.expired = (expired != 0);
      Dmsg0(DT_SNAPSHOT|10, "List snapshots\n");
      snapdbr.debug(20);
      db_list_snapshot_records(jcr, jcr->db, &snapdbr, send_list, bs, ARG_LIST);
      bs->signal(BNET_EOD);
      goto bail_out;
   }
   n = sscanf(bs->msg, DelSnap, Job, snapdbr.Name, dev);
   if (n == 3) {
      snapdbr.Device = dev;
      unbash_spaces(snapdbr.Name);
      unbash_spaces(snapdbr.Device);
      bstrncpy(snapdbr.Client, jcr->client->hdr.name, sizeof(snapdbr.Client));
      Dmsg2(DT_SNAPSHOT|10, "Delete snapshot %s from %s\n", snapdbr.Name, snapdbr.Client);
      snapdbr.debug(20);      
      db_lock(jcr->db);
      ret = db_delete_snapshot_record(jcr, jcr->db, &snapdbr);
      pm_strcpy(err, jcr->db->errmsg);
      db_unlock(jcr->db);
      if (ret) {
         bs->fsend("1000 Snapshot deleted\n");
      } else {
         bs->fsend("1999 Snapshot not deleted ERR=%s\n", err);
      }
      goto bail_out;
   }
   ret = 0;
bail_out:
   free_pool_memory(vol);
   free_pool_memory(dev);
   free_pool_memory(err);
   return ret;
}
int snapshot_catreq ( JCR * jcr , BSOCK * bs ) { SNAPSHOT_DBR snapdbr ; char Job [ MAX_NAME_LENGTH ] , ed1 [ 50 ] ; POOLMEM * vol = get_memory ( bs -> msglen ) ; POOLMEM * dev = get_memory ( bs -> msglen ) ; POOLMEM * err = get_pool_memory ( PM_MESSAGE ) ; int n , ret = 1 , expired ; * vol = * dev = 0 ; Dmsg1 ( DT_SNAPSHOT | 10 , " \n " , bs -> msg ) ; n = sscanf ( bs -> msg , CreateSnap , Job , snapdbr . Name , vol , dev , & snapdbr . CreateTDate , snapdbr . Type , ed1 ) ; if ( n == 7 ) { snapdbr . Volume = vol ; snapdbr . Device = dev ; snapdbr . JobId = jcr -> JobId ; unbash_spaces ( snapdbr . Name ) ; unbash_spaces ( snapdbr . Volume ) ; unbash_spaces ( snapdbr . Device ) ; snapdbr . Retention = str_to_uint64 ( ed1 ) ; bstrftimes ( snapdbr . CreateDate , sizeof ( snapdbr . CreateDate ) , snapdbr . CreateTDate ) ; unbash_spaces ( snapdbr . Type ) ; bstrncpy ( snapdbr . Client , jcr -> client -> hdr . name , sizeof ( snapdbr . Client ) ) ; bstrncpy ( snapdbr . FileSet , ( jcr -> fileset ) ? jcr -> fileset -> hdr . name : " " , sizeof ( snapdbr . FileSet ) ) ; Dmsg1 ( DT_SNAPSHOT | 10 , " \n " , snapdbr . Name ) ; snapdbr . debug ( 20 ) ; db_lock ( jcr -> db ) ; ret = db_create_snapshot_record ( jcr , jcr -> db , & snapdbr ) ; pm_strcpy ( err , jcr -> db -> errmsg ) ; db_unlock ( jcr -> db ) ; if ( ret ) { bs -> fsend ( " \n " ) ; } else { bs -> fsend ( " \n " , err ) ; } goto bail_out ; } n = sscanf ( bs -> msg , ListSnap , Job , snapdbr . Name , vol , dev , & snapdbr . CreateTDate , snapdbr . Type , snapdbr . created_before , snapdbr . created_after , & expired ) ; if ( n == 8 ) { snapdbr . Volume = vol ; snapdbr . Device = dev ; unbash_spaces ( snapdbr . Name ) ; unbash_spaces ( snapdbr . Volume ) ; unbash_spaces ( snapdbr . Device ) ; bstrftimes ( snapdbr . CreateDate , sizeof ( snapdbr . CreateDate ) , snapdbr . CreateTDate ) ; unbash_spaces ( snapdbr . Type ) ; unbash_spaces ( snapdbr . created_before ) ; unbash_spaces ( snapdbr . created_after ) ; bstrncpy ( snapdbr . Client , jcr -> client -> hdr . name , sizeof ( snapdbr . Client ) ) ; snapdbr . expired = ( expired != 0 ) ; Dmsg0 ( DT_SNAPSHOT | 10 , " \n " ) ; snapdbr . debug ( 20 ) ; db_list_snapshot_records ( jcr , jcr -> db , & snapdbr , send_list , bs , ARG_LIST ) ; bs -> signal ( BNET_EOD ) ; goto bail_out ; } n = sscanf ( bs -> msg , DelSnap , Job , snapdbr . Name , dev ) ; if ( n == 3 ) { snapdbr . Device = dev ; unbash_spaces ( snapdbr . Name ) ; unbash_spaces ( snapdbr . Device ) ; bstrncpy ( snapdbr . Client , jcr -> client -> hdr . name , sizeof ( snapdbr . Client ) ) ; Dmsg2 ( DT_SNAPSHOT | 10 , " \n " , snapdbr . Name , snapdbr . Client ) ; snapdbr . debug ( 20 ) ; db_lock ( jcr -> db ) ; ret = db_delete_snapshot_record ( jcr , jcr -> db , & snapdbr ) ; pm_strcpy ( err , jcr -> db -> errmsg ) ; db_unlock ( jcr -> db ) ; if ( ret ) { bs -> fsend ( " \n " ) ; } else { bs -> fsend ( " \n " , err ) ; } goto bail_out ; } ret = 0 ; bail_out : free_pool_memory ( vol ) ; free_pool_memory ( dev ) ; free_pool_memory ( err ) ; return ret ; }
Called from the FD, in catreq.c
Called from the FD in catreq . c
/* We need to create a snapshot record in the catalog */ /* We lock the db before to keep the error message */ /* We lock the db before to keep the error message */