PROCEDURE restore_unreconciled_catalogs, resuc, restore_missing_catalogs, resmc (
  vsn_prefix, vsnp, vp: any of
      name 1..5
      string 1..5
      integer 1..99999
    anyend = $optional
  vsn_count, vsnc, vc: integer 1..11881376 = 9
  vsn_suffix, vsns, vs: any of
      name 1..5
      string 1..5
      integer 1..99999
    anyend = $optional
  increment_scheme, is: key
      (alphabetic, a)
      (decimal, d)
    keyend = decimal
  vsn_list, vsnl: list of any of
      name 1..6
      string 1..6
    anyend = $optional
  file_label_type, flt: key
      (labeled, labelled, l)
      (unlabeled, unlabelled, u)
    keyend = labeled
  type, t: key
      mt9$800, mt9$1600, mt9$6250, mt18$38000
    keyend = mt9$6250
  backup_file, bf: file = $optional
  restore_excluded_file_cycles, refc: list of key
      none
      (media_missing, mm)
      (no_data_defined, ndd)
      (volume_unavailable, vu)
    keyend = (no_data_defined media_missing volume_unavailable)
  execution_mode, em: key
      (batch_job, bj)
      (asynchronous_task, at)
      (synchronous_task, st)
    keyend = batch_job
  output, o: file = $list
  status)


"   The purpose of this procedure is to restore catalogs from a set
"   of backup tapes or from a permanent backup file in the event of the
"   loss of a catalog device.  This procedure will restore the catalogs
"   that were on the failing device (or devices) to the remaining devices
"   from the latest backup tapes or from the specified permanent backup file.
"
"   This procedure is only available from the console.
"
"   This procedure may not be used to restore catalogs on the system
"   device.
"
"   Cycles residing on catalogs so restored  will be marked with the  damage
"   condition of 'parent_catalog_restored', and 'respf_modification_mismatch' .
"   Users may use the  change_catalog_entry command to clear this
"   damage condition.
"
"   When the operator has ensured that the catalog restoration has completed
"   the operator should type from the console:
"   respf
"     set_restore_missing_catalogs operation=end
"   quit
"
"  PARAMETERS:
"    vsn_prefix, vsnp: Specify a one to five character name, string or integer
"      that will become the leftmost characters in the list of VSN's generated
"      by the procedure.
"
"    vsn_count, vsnc: The number of backup tapes in the set. This parameter
"      determines how many VSN's will be in the list generated by the
"      procedure.
"
"    vsn_suffix, vsns: This parameter specifies the rightmost characters of
"      the first vsn in the set you wish to restore. A name or string value
"      should be supplied for an alphabetic increment scheme and an integer
"      for a decimal increment scheme. This parameter should only be used when
"      problems are encountered during a restore that make it necessary to
"      restart the restore at a point other than the first reel.
"
"    increment_scheme, is: This parameter determines the format for the
"      rightmost characters of the VSN's generated by this procedure.
"      Decimal mode is the default. Alphabetic mode is for situations
"      where a decimal increment scheme does not allow enough tapes.
"
"    vsn_list, vsnl: A list of magnetic tape external VSNs generated by
"      a calling procedure such as SELECT_OPERATOR_MENU.  This parameter
"      value overrides the vsn_prefix, vsn_count, and increment_scheme VSN
"      generation parameters.
"
"    file_label_type, flt: This parameter specifies the type of label
"      on the backup tapes you are using. If this parameter is not specified,
"      then LABELED is used.
"
"    type, t: This parameter specifies the density of the backup tapes
"      you are using.
"
"    backup_file: This parameter is used to restore from a permanent backup
"      file, which can be either a permanent mass storage file or a permanent
"      tape file.  If this parameter is specified, the following parameters
"      will be ignored.
"
"          file_label_type
"          increment_scheme
"          type
"          vsn_count
"          vsn_list
"          vsn_prefix
"          vsn_suffix
"
" Note: If the execution mode is asynchronous_task or synchronous_task and
"       the backup file is attached prior to calling this procedure, the
"       backup file must be attached with a LOCAL_FILE_NAME of BACKUP_FILE.
"
"    restore_excluded_file_cycles,refc: The purpose of
"       this parameter is to direct the restore process whether to
"       restore any data found on the set of backup tapes used when
"       restoring missing catalogs.  This is useful, for example, when
"       the site's most recent catalog backup is a partial backup and
"       contains both the most recent catalog image and data.
"
"       Data will be restored under the same criteria as the
"       RESTORE_EXCLUDED_FILE_CYCLES subcommand;  namely if the
"       cycle has no data defined for it, or if the cycle data resides
"       on a media missing or volume that is unavailable.
"       INCLUDE_VOLUMES subcommand affect the operation of this parameter.
"
"       Omission will cause data to be restored if it is on the backup file,
"       and is no described in the catalog, or is in on a device that is
"       missing.
"
"    execution_mode, em: This parameter specifies the mode of execution for
"      the task restoring the data.  When a file or catalog required for job
"      initiation is missing a batch job cannot be used to restore the data.
"      The default is to execute as a batch job.
"
"    output, o: This parameter specifies the file to which the output from
"      the restore session will be written.  When an EXECUTION_MODE of
"      asynchronous_task or synchronous_task is selected the output
"      parameter must be specified. The default is $LIST.
"
" VSN Generation Examples:
"   vsn_prefix=part vsn_count=12 increment_scheme=decimal    ==>part01-part12
"   vsn_prefix=part vsn_count=12 increment_scheme=alphabetic ==>partaa-partal
"
"   vsn_prefix=A1 vsn_count=27 increment_scheme=decimal    ==>A10001-A10027
"   vsn_prefix=A1 vsn_count=27 increment_scheme=alphabetic ==>A1AAAA-A1AABA
"
"   vsn_prefix=full vsn_count=4 vsn_suffix=7 is=decimal    ==> FULL07-FULL10
"   vsn_prefix=full vsn_count=4 vsn_suffix=E is=alphabetic ==> FULLAE-FULLAH
"

  VAR
    backup_file_already_attached: boolean = FALSE
    job_file: file = $unique(:$local)
    volume_list: list 1 .. $max_list of string 6
  VAREND

  IF $specified(backup_file) THEN
    IF $string($file_attributes(backup_file, lifetime)) <> 'UNLIMITED'  THEN
      EXIT procedure WITH $status(false, 'PU', 3330, 'The file specified '//..
'by the BACKUP_FILE parameter must be a permanent mass storage file or a permanent tape file.')
    ELSE
      IF NOT $string($file_attributes(backup_file, registered))='YES' THEN
        EXIT procedure WITH $status(false, 'PU', 3330, 'The file specified '//..
'by the BACKUP_FILE parameter must be an existing permanent mass storage file or a permanent tape file.')
      IFEND
    IFEND
  ELSE
    IF $specified(vsn_list) THEN
      delete_variable volume_list
      volume_list = $apply(vsn_list, $string(x))
    ELSE
      pup$construct_volume_list vsn_count=vsn_count vsn_prefix=vsn_prefix increment_scheme=increment_scheme ..
            vsn_suffix=vsn_suffix volume_list=volume_list
    IFEND
  IFEND

  IF $string(execution_mode)(1) = 'B' THEN
    execution_mode_command = 'JOB job_name=restore_missing_catalog job_class=system magnetic_tape_limit=unlimited'
    terminate_execution_command = 'JOBEND'
  ELSEIF $string(execution_mode)(1) = 'S' THEN
    execution_mode_command = ''
    terminate_execution_command = ''
  ELSE
    execution_mode_command = 'TASK task_name=restore_missing_catalog'
    terminate_execution_command = 'TASKEND'
  IFEND

  IF ($string(execution_mode)(1) <> 'B') AND NOT $specified(output) THEN
    EXIT procedure WITH $status(false, 'PU', 0, ..
'The OUTPUT parameter must be specified when an EXECUTION_MODE other than BATCH_JOB is selected.')
  IFEND

  IF $specified(backup_file) THEN
    IF $string($file_attributes(backup_file, attached)) = 'YES' AND ..
         $string(execution_mode)(1) <> 'B' THEN
      IF NOT $nil($select_string($string($file_attributes(backup_file, potential_job_access)),'READ')) THEN
        IF NOT $string($file_attributes($local.backup_file, registered))='YES' THEN
          EXIT procedure WITH $status(false, 'PU', 3330, 'If the file specified '//..
'by the BACKUP_FILE parameter is already attached, the LOCAL_FILE_NAME must be BACKUP_FILE.')
        IFEND
        attach_or_request_command = ''
        backup_file_already_attached = TRUE
      ELSE
        attach_or_request_command = 'attach_file am=read local_file_name=backup_file file= '//$string(backup_file)
      IFEND
    ELSE
      attach_or_request_command = 'attach_file am=read local_file_name=backup_file file= '//$string(backup_file)
    IFEND
  ELSE
    attach_or_request_command = 'request_magnetic_tape file=$local.backup_file ring=no type='//$string(type)// ..
          ' external_vsn='//$string(volume_list, source)// ..
          '; set_file_attributes file=$local.backup_file file_label_type='//$string(file_label_type)
  IFEND

  RESTORE_PERMANENT_FILES
    set_restore_missing_catalogs operation=start
  QUIT

"Create a file containing a batch job to do the actual restore.
COLLECT_TEXT output=job_file sm='?' until='**END_COLLECT**'
  ?execution_mode_command?
    IF NOT $variable(ignore_status, local) THEN
      VAR
        ignore_status: status
      VAREND
    IFEND
    create_command_list_entry entry=$system.osf$builtin_library status=ignore_status
    create_command_list_entry entry=$system.osf$sou_library status=ignore_status
    ?attach_or_request_command?

    WHEN any_fault DO
     IF NOT ?backup_file_already_attached? THEN
       detach_file file=$local.backup_file
     IFEND
     display_value osv$status
     send_operator_message ' RESTORE_UNRECONCILED_CATALOGS aborting -check listing '
    WHENEND

    SYSTEM_OPERATOR_UTILITY CAPABILITY=SYSTEM_ADMINISTRATION
    TASK ring=3
      restore_permanent_files list=?output?
        set_restore_options update_cycle_statistics=FALSE restore_archive_information=TRUE
        set_restore_options require_matching_modification=FALSE
        restore_missing_catalogs backup_file=$local.backup_file ..
           restore_excluded_file_cycles=?$string($parameter_value(restore_excluded_file_cycles), source)?
        send_operator_message 'RESTORE END-IF last job do:RESPF;SET_RESTORE_MISSING_CATALOG END'
      QUIT
      change_file_attributes file=?output? ring_attributes=(11 11 11) status=ignore_status
    TASKEND
    IF NOT ?backup_file_already_attached? THEN
      detach_file file=$local.backup_file
    IFEND
    QUIT
  ?terminate_execution_command?
**END_COLLECT**

  include_file file=job_file
  detach_file file=job_file

PROCEND restore_unreconciled_catalogs
