home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 January / Chip_2001-01_cd1.bin / tema / interb / InterBase_WI-V6.0-server.exe / server / examples / services / start_backup.c < prev    next >
C/C++ Source or Header  |  2000-06-23  |  3KB  |  131 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <malloc.h>
  4. #include "/usr/interbase/../super/jrd/ibase.h"
  5.  
  6. #define RESPBUF    1024
  7.  
  8. void main (argc, argv)
  9. int    argc;
  10. char    *argv[];
  11. {
  12. char    *user = "SYSDBA",
  13.         *pass = "masterkey";
  14. long    status [20];
  15. long    *svc_handle = NULL;
  16. char    *buffer;
  17. char    send_buff[32], *pSendBuff;
  18. char    svc_name[RESPBUF], spb_buff[RESPBUF], thd_buff[RESPBUF];
  19. char    sendbuf[] = {isc_info_svc_line};
  20. char    respbuf[RESPBUF], *p = respbuf, *spb = spb_buff, *thd = thd_buff,*x;
  21. short    path_length, spblen, thdlen, sendBuffLen;
  22. int    i = 0;
  23.  
  24.  
  25. if (argc != 3)
  26.     {
  27.     printf ("Usage: %s dbfile backupfile\n", argv[0]);
  28.     exit (1);
  29.     }
  30.  
  31. *spb++ = isc_spb_version;
  32. *spb++ = isc_spb_current_version;
  33.  
  34. *spb++ = isc_spb_user_name;
  35. *spb++ = strlen (user);
  36. for (x = user; *x;)
  37.   *spb++ = *x++;
  38.  
  39. *spb++ = isc_spb_password;
  40. *spb++ = strlen (pass);
  41. for (x = pass; *x;)
  42.   *spb++ = *x++;
  43.  
  44. sprintf (svc_name, "typhoon:service_mgr");
  45.  
  46. spblen = spb - spb_buff;
  47.  
  48. if (isc_service_attach (status, 0, svc_name, &svc_handle, spblen, spb_buff))
  49.     {
  50.     isc_print_status (status);
  51.     exit (1);
  52.     }
  53.  
  54. *thd++ = isc_action_svc_backup;
  55. *thd++ = isc_spb_dbname;
  56. *thd++ = strlen (argv[1]);
  57. *thd++ = strlen (argv[1]) >> 8;
  58. for (x = argv[1]; *x;)
  59.   *thd++ = *x++;
  60. *thd++ = isc_spb_bkp_file;
  61. *thd++ = strlen (argv[2]);
  62. *thd++ = strlen (argv[2]) >> 8;
  63. for (x = argv[2]; *x;)
  64.   *thd++ = *x++;
  65. *thd++ = isc_spb_verbose;
  66.  
  67. thdlen = thd - thd_buff;
  68.  
  69. printf ("Attach succeed\n");
  70.  
  71. if (isc_service_start(status, &svc_handle, NULL, thdlen, thd_buff))
  72.     {
  73.     isc_print_status (status);
  74.     isc_service_detach (status, &svc_handle);
  75.     exit(1);
  76.     }
  77. printf ("Start succeed\n");
  78.  
  79. do
  80.     {
  81.     if (isc_service_query (status, &svc_handle, NULL, 0, NULL,
  82.     sizeof (sendbuf), sendbuf, RESPBUF, respbuf))
  83.     {
  84.     isc_print_status (status);
  85.     isc_service_detach (status, &svc_handle);
  86.     exit(1);
  87.     }
  88.  
  89.     x = p = respbuf;
  90.  
  91.     if (*p++ == isc_info_svc_line)
  92.     {
  93.     ISC_USHORT len = 0, chTmp = 0, key;
  94.  
  95.     len = (ISC_USHORT)isc_vax_integer(p, sizeof(ISC_USHORT));
  96.     p += sizeof (ISC_USHORT);
  97.     if (!len)
  98.         if (*p ==  isc_info_data_not_ready)
  99.         {
  100.         printf ("no data available at this moment\n");
  101.         continue;
  102.         }
  103.         else
  104.         {
  105.         if (*p != isc_info_end)
  106.             printf ("Format error ... <%d>\n", *p);
  107.         break;
  108.         }
  109.     for (chTmp = 0; chTmp < len; chTmp++)
  110.         printf("%c",p[chTmp]);
  111.     p += len;
  112.     if (*p != isc_info_truncated && *p != isc_info_end)
  113.         {
  114.         printf ("Format error ... encountered <%d>\n", *p);
  115.         break;
  116.         }
  117.     else
  118.         {
  119.         /* printf ("\nisc_info_truncated  || isc_info_end\n"); */
  120.         }
  121.     }
  122.     else
  123.     printf ("not a isc_info_svc_line, but %d\n", *x);
  124.     }
  125. while (*x == isc_info_svc_line);
  126.  
  127.  
  128.  
  129. isc_service_detach(status, &svc_handle);
  130. }
  131.