home *** CD-ROM | disk | FTP | other *** search
/ MACup: Giveaway 1996 / Image.iso / Shareware & Demos / Web-Publishing / SNAP PrimeBase / PrimeBase™ Server PPC / Setup / Scripts / adminhelp.dal next >
Encoding:
Text File  |  1996-07-13  |  12.5 KB  |  427 lines  |  [TEXT/ds30]

  1. /*
  2. execute file "AdminHelp";
  3.  
  4. SIMPLE SERVER MANAGEMENT MODEL
  5. ==============================
  6. */
  7.  
  8. /* ******************************************************************************************** */
  9. /*                                             DEVICES                                                */
  10. /* ******************************************************************************************** */
  11.  
  12. execute file "DeviceHelp";
  13.  
  14. /* ******************************************************************************************** */
  15. /*                                             LOCATIONS                                            */
  16. /* ******************************************************************************************** */
  17.  
  18. PROCEDURE help_locations()
  19. {
  20.     print "";
  21.     print "LOCATIONS:";
  22.     print "----------";
  23.     print "These locations indicate where all new databases and logs files are";
  24.     print "placed. Devices can be selected for the data and index files of all";
  25.     print "new databases. A single device can be selected for placing new online";
  26.     print "log files. Two devices can be selected for the restart files.";
  27.     print "";
  28.     print "PROCEDURE list_locations()";
  29.     print "List all locations that have been set.";
  30.     print "";
  31.     print "PROCEDURE set_database_location(devicename [, path ])";
  32.     print "Set the both data and index location for new databases.";
  33.     print "";
  34.     print "PROCEDURE set_log_location(devicename [, path ])";
  35.     print "Set the location for new log files.";
  36.     print "";
  37.     print "PROCEDURE set_log_archive_location(devicename [, path ])";
  38.     print "Set the location for archived log files.";
  39.     print "";
  40.     print "PROCEDURE set_restart_locations(devicea, deviceb)";
  41.     print "Set the locations for the restart files.";
  42.     print "";
  43.     print "PROCEDURE set_data_location(devicename [, path ])";
  44.     print "Set the data location for new databases.";
  45.     print "";
  46.     print "PROCEDURE set_index_location(devicename [, path ])";
  47.     print "Set the index location for all new databases.";
  48.     print "";
  49. } END PROCEDURE help_locations;
  50.  
  51. PROCEDURE check_name(name)
  52. RETURNS boolean;
  53. ARGUMENT generic name;
  54. {
  55.     if (name is null or ($typeof(name) != $varchar and $typeof(name) != $char))
  56.         return($FALSE);
  57.     return($TRUE);
  58. } END PROCEDURE check_name;
  59.  
  60. PROCEDURE find_location(name, print_error)
  61. RETURNS integer;
  62. ARGUMENT generic name = $null;
  63. ARGUMENT boolean print_error = $TRUE;
  64. {
  65.     if (not check_name(name)) {
  66.         print "ERROR: Please specify the name of a location.";
  67.         return(0);
  68.     }
  69.  
  70.     open_master;
  71.     select * from $sm_master!syslocations
  72.     where .name = name
  73.     order by id
  74.     into  $sm_cursor1 for extract;
  75.     if ($rows($sm_cursor1) == 0) {
  76.         if (print_error)
  77.             print "ERROR: A location called '" + name + "' does not exists.";
  78.         return(0);
  79.     }
  80.  
  81.     fetch first of $sm_cursor1;
  82.     return($sm_cursor1->id);
  83. } END PROCEDURE find_location;
  84.  
  85. PROCEDURE set_location(devicename, path, locationname, locationtype, storetype)
  86. RETURNS boolean;
  87. ARGUMENT generic devicename = $null, path = $null;
  88. ARGUMENT varchar locationname, locationtype, storetype = "FutureStorage";
  89. {
  90.     integer dev_id;
  91.     integer loc_id;
  92.  
  93.     if (not check_name(devicename)) {
  94.         print "ERROR: Please specify the name of a device.";
  95.         return($FALSE);
  96.     }
  97.  
  98.     if (path is null)
  99.         dev_id = find_device(devicename);
  100.     else {
  101.         if (not check_name(path)) {
  102.             print "ERROR: You may only specify a file-system path after the device name.";
  103.             return($FALSE);
  104.         }
  105.         dev_id = add_device(devicename, path);
  106.     }
  107.     if (dev_id == 0)
  108.         return($FALSE);
  109.  
  110.     loc_id = find_location(locationname, $FALSE);
  111.     if (loc_id == 0)
  112.         ADD LOCATION (locationname, locationtype, storetype, dev_id);
  113.     else
  114.         ALTER LOCATION (loc_id, DEVICEID = dev_id);
  115.     return($TRUE);
  116. } END PROCEDURE set_location;
  117.  
  118. PROCEDURE set_data_location(devicename, path)
  119. RETURNS boolean;
  120. ARGUMENT generic devicename = $null, path = $null;
  121. {
  122.     return(set_location(devicename, path, "DatabaseDataFiles", "Data"));
  123. } END PROCEDURE set_data_location;
  124.  
  125. PROCEDURE set_index_location(devicename, path)
  126. RETURNS boolean;
  127. ARGUMENT generic devicename = $null, path = $null;
  128. {
  129.     return(set_location(devicename, path, "DatabaseIndexFiles", "Index"));
  130. } END PROCEDURE set_index_location;
  131.  
  132. PROCEDURE set_database_location(devicename, path)
  133. RETURNS boolean;
  134. ARGUMENT generic devicename = $null, path = $null;
  135. {
  136.     integer dev_id;
  137.     
  138.     if (set_data_location(devicename, path))
  139.         return(set_index_location(devicename));
  140.     return($FALSE);
  141. } END PROCEDURE set_database_location;
  142.  
  143. PROCEDURE set_log_location(devicename, path)
  144. RETURNS boolean;
  145. ARGUMENT generic devicename = $null, path = $null;
  146. {
  147.     return(set_location(devicename, path, "LogFiles", "log"));
  148. } END PROCEDURE set_log_location;
  149.  
  150. PROCEDURE set_log_archive_location(devicename, path)
  151. RETURNS boolean;
  152. ARGUMENT generic devicename = $null, path = $null;
  153. {
  154.     return(set_location(devicename, path, "ArchiveLogFiles", "log","FutureBackup"));
  155. } END PROCEDURE set_log_archive_location;
  156.  
  157.  
  158. PROCEDURE set_restart_locations(devicea, deviceb)
  159. RETURNS boolean;
  160. ARGUMENT varchar devicea, deviceb;
  161. {
  162.     print "NOTE: This function call will not have the  correct affect unless you place";
  163.     print "the restart files in the locations specified on input. If the server currently";
  164.     print "has one restart file,  move it the first location  specified here.   If the";
  165.     print "server already has two restart files, place them in the locations specified";
  166.     print "here as input.";
  167.     print "";
  168.     print "WARNING! If this function fails, the transaction manager may be remain down.";
  169.     print "If this is the case, move the restart file/s back to where it was and enter:";
  170.     print "server restart;";
  171.     print "";
  172.     trans shutdown;
  173.     server restart in location device_path(find_device(devicea)), device_path(find_device(devicea));
  174. } END PROCEDURE set_restart_locations;
  175.  
  176. PROCEDURE list_locations()
  177. {
  178.     open_master;
  179.     select l.name, d.name as device, path
  180.     from $sm_master!syslocations as l, $sm_master!sysdevices as d
  181.     where FilePurpose = "FutureStorage"
  182.     and   Allocation = "Automatic"
  183.     and   l.DeviceID = d.ID
  184.     into $sm_cursor1 for extract;
  185.     print 'Name:                   Device:                 Path:';
  186.     print '----------------------- ----------------------- ----------------------------';
  187.     for each $sm_cursor1
  188.         print $format("%-24s%-24s%s", $sm_cursor1->name, $sm_cursor1->device, $sm_cursor1->path);
  189. } END PROCEDURE list_locations;
  190.  
  191. /* ******************************************************************************************** */
  192. /*                                             PARTITIONS                                            */
  193. /* ******************************************************************************************** */
  194.  
  195. PROCEDURE help_partitions()
  196. {
  197.     print "";
  198.     print "PARTITIONS:";
  199.     print "-----------";
  200.     print "Existing databases are located on partitions.";
  201.     print "";
  202.     print "PROCEDURE list_partitions([ dbname ])";
  203.     print "List partition of a particular database (or all databases if";
  204.     print "database name ommitted).";
  205.     print "";
  206.     print "PROCEDURE add_database_partition(dbname, devicename)";
  207.     print "Place both data and index files on a particular device.";
  208.     print "";
  209.     print "PROCEDURE remove_database_partition(dbname, devicename)";
  210.     print "No longer locate a database on a particular device.";
  211.     print "";
  212.     print "PROCEDURE add_data_partition(dbname, devicename)";
  213.     print "Place the data files of a database on a particular device";
  214.     print "";
  215.     print "PROCEDURE add_index_partition(dbname, devicename)";
  216.     print "Place the index files on the given database and the given device.";
  217.     print "";
  218.     print "PROCEDURE remove_data_partition(dbname, devicename)";
  219.     print "Remove a data partition of a particular database.";
  220.     print "";
  221.     print "PROCEDURE remove_index_partition(dbname, devicename)";
  222.     print "Remove an index partition from a particular database.";
  223.     print "";
  224. } END PROCEDURE help_partitions;
  225.  
  226. PROCEDURE find_database(name, print_error)
  227. RETURNS integer;
  228. ARGUMENT varchar name = $null;
  229. ARGUMENT boolean print_error = $TRUE;
  230. {
  231.     if (not check_name(name)) {
  232.         print "ERROR: Please specify the name of a database.";
  233.         return(0);
  234.     }
  235.  
  236.     open_master;
  237.     select id
  238.     from $sm_master!sysdatabases
  239.     where .name = :name
  240.     into $sm_cursor1 for extract;
  241.     if ($rows($sm_cursor1) == 0) {
  242.         if (print_error)
  243.             print "ERROR: A database called '" + name + "' does not exists.";
  244.         return 0;
  245.     }
  246.  
  247.     fetch first of $sm_cursor1;
  248.     return($sm_cursor1->id);
  249.     
  250. } END PROCEDURE find_database;
  251.  
  252. PROCEDURE find_partition(db_id, dev_id)
  253. RETURNS integer;
  254. ARGUMENT integer db_id, dev_id;
  255. {
  256.     open_master;
  257.     select id
  258.     from $sm_master!syspartitions
  259.     where databaseid = db_id
  260.     and deviceid = dev_id
  261.     into $sm_cursor1 for extract;
  262.     if ($rows($sm_cursor1) == 0)
  263.         return(0);
  264.     fetch first of $sm_cursor1;
  265.     return($sm_cursor1->id);
  266. } END PROCEDURE find_partition;
  267.  
  268. PROCEDURE alter_partition(dbname, devicename, data, index)
  269. RETURNS integer;
  270. ARGUMENT varchar dbname, devicename;
  271. ARGUMENT boolean data, index;
  272. {
  273.     integer db_id;
  274.     integer dev_id;
  275.     integer part_id;
  276.     
  277.     db_id = find_database(dbname);
  278.     if (db_id == 0)
  279.         return(0);
  280.     
  281.     dev_id = find_device(devicename);
  282.     if (dev_id == 0)
  283.         return(0);
  284.     
  285.     part_id = find_partition(db_id, dev_id);
  286.     if (part_id == 0) {
  287.         if (data is null)
  288.             data = $FALSE;
  289.         if (index is null)
  290.             index = $FALSE;
  291.         if (data or index) {
  292.             ADD PARTITION (db_id, dev_id, data = data, index = index, blob = $FALSE);
  293.             part_id = find_partition(db_id, dev_id);
  294.         }
  295.     }
  296.     else {
  297.         if (data is not null)
  298.             ALTER PARTITION (part_id, data = data);
  299.         if (index is not null)
  300.             ALTER PARTITION (part_id, index = index);
  301.  
  302.         select * from $sm_master!syspartitions
  303.         where id = part_id
  304.         into $sm_cursor1 for extract;
  305.         if ($rows($sm_cursor1) == 0)
  306.             return(0);
  307.         fetch first of $sm_cursor1;
  308.         if (not $sm_cursor1->data and
  309.             not $sm_cursor1->index and
  310.             not $sm_cursor1->blob)
  311.             REMOVE PARTITION (part_id);
  312.     }
  313.     return(part_id);
  314. } END PROCEDURE alter_partition;
  315.  
  316. PROCEDURE add_data_partition(dbname, devicename)
  317. RETURNS integer;
  318. ARGUMENT generic dbname, devicename;
  319. {
  320.     return(alter_partition(dbname, devicename, $TRUE, $NULL));
  321. } END PROCEDURE add_data_partition;
  322.  
  323. PROCEDURE add_index_partition(dbname, devicename)
  324. RETURNS integer;
  325. ARGUMENT generic dbname, devicename;
  326. {
  327.     return(alter_partition(dbname, devicename, $NULL, $TRUE));
  328. } END PROCEDURE add_index_partition;
  329.  
  330. PROCEDURE add_database_partition(dbname, devicename)
  331. RETURNS integer;
  332. ARGUMENT generic dbname, devicename;
  333. {
  334.     if (add_data_partition(dbname, devicename) != 0)
  335.         return(add_index_partition(dbname, devicename));
  336.     return(0);
  337. } END PROCEDURE add_database_partition;
  338.  
  339. PROCEDURE remove_data_partition(dbname, devicename)
  340. RETURNS integer;
  341. ARGUMENT generic dbname, devicename;
  342. {
  343.     return(alter_partition(dbname, devicename, $FALSE, $NULL));
  344. } END PROCEDURE remove_data_partition;
  345.  
  346. PROCEDURE remove_index_partition(dbname, devicename)
  347. RETURNS integer;
  348. ARGUMENT generic dbname, devicename;
  349. {
  350.     return(alter_partition(dbname, devicename, $NULL, $FALSE));
  351. } END PROCEDURE remove_index_partition;
  352.  
  353. PROCEDURE remove_database_partition(dbname, devicename)
  354. RETURNS integer;
  355. ARGUMENT generic dbname, devicename;
  356. {
  357.     if (remove_data_partition(dbname, devicename) != 0)
  358.         return(remove_index_partition(dbname, devicename));
  359.     return(0);
  360. } END PROCEDURE remove_database_partition;
  361.  
  362. PROCEDURE list_partitions(dbname)
  363. ARGUMENT varchar dbname = "*";
  364. {
  365.     open_master;
  366.     select db.name as dbname, dev.name as devname, part.data, part.index, part.blob
  367.     from $sm_master!syspartitions as part,
  368.          $sm_master!sysdatabases as db,
  369.          $sm_master!sysdevices as dev
  370.     where db.name like dbname
  371.     and part.backupid is null
  372.     and part.databaseid = db.id
  373.     and part.deviceid = dev.id
  374.     order by db.name
  375.     into $sm_cursor1 for extract;
  376.     if ($rows($sm_cursor1) == 0) {
  377.         print "ERROR: A database called '" + dbname + "' does not exists.";
  378.         return;
  379.     }
  380.     
  381.     print 'Database:               Device:                 Data:        Index:';
  382.     print '----------------------- ----------------------- ------------ -----------';
  383.     for each $sm_cursor1 {
  384.         if (not $sm_cursor1->data and
  385.             not $sm_cursor1->index and
  386.             $sm_cursor1->blob)
  387.             continue;
  388.         printf("%-24s%-24s", $sm_cursor1->dbname, $sm_cursor1->devname);
  389.         if ($sm_cursor1->data)
  390.             printf("YES          ");
  391.         else
  392.             printf(" -           ");
  393.         if ($sm_cursor1->index)
  394.             print "YES          ";
  395.         else
  396.             print " -           ";
  397.     }
  398. } END PROCEDURE list_partitions;
  399.  
  400. /* ******************************************************************************************** */
  401. /*                                             HELP                                                */
  402. /* ******************************************************************************************** */
  403.  
  404. PROCEDURE help_all()
  405. {
  406.     help_devices;
  407.     help_locations;
  408.     help_partitions;
  409. } END PROCEDURE help_all;
  410.  
  411. PROCEDURE help()
  412. {
  413.     print "";
  414.     print "SERVER ADMINSTRATION:";
  415.     print "---------------------";
  416.     print "The folowing help functions are available:";
  417.     print "help_devices;";
  418.     print "help_locations;";
  419.     print "help_partitions;";
  420.     print "help_all;";
  421.     print "";
  422. } END PROCEDURE help;
  423.  
  424. print "Server adminstration help functions defined.";
  425. print "Enter: 'help;' for help.";
  426.  
  427.