PROCEDURE create_full_backup, crefb, full_backup, fulb (
  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
  increment_scheme, is: key
      (alphabetic, a)
      (decimal, d)
    keyend = decimal
  vsn_list, vsnl: list 1..$max_list of any of
      string 1..6
      name 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
  backup_catalogs, bc: boolean = TRUE
  backup_system_family, bsf: boolean = TRUE
  output_disposition, odi: any of
      key
        (discard_all_output, dao),(discard_standard_output, dso),
        (printer, p),(wait_queue, wt, wq)
      keyend
      file
    anyend = puv$create_full_backup, printer
  status)

"  The purpose of this procedure is to create a batch job to backup
"  all files on the system to a set of backup tapes or to a permanent backup
"  file.
"
"  The files are backed up in alphabetic order sorted by family and user.
"  The files in the catalog $system.aam.shared_recovery_log are
"  backed up last because AAM stores backup information in this catalog.
"
"  After the backup is complete the HPA monitor job will be restarted.
"
"  A file, $system.date_of_full_backup, is created that contains the
"  date and time the full backup began. This information is used by the
"  partial_backup procedure to determine what files it should back up.
"
"  To support the use of labelled backup tapes the list of VSN's for the
"  backup tapes are generated by the procedure. The value of the VSN's
"  depends on the values for vsn_prefix, vsn_count and increment_scheme.
"
"  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. The number of
"      tapes actually required for a backup will be unknown until the
"      backup is complete; however, this parameter must be specified to
"      provide enough information to generate a list of VSN's for labelled
"      tapes. The value specified should be larger than the actual amount
"      required. The backup will stop after all the data has been backed up
"      and use only the number of tapes required to hold the data.
"
"    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 generatated by
"      an 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 create 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
"
"    backup_catalogs, bc: This parameter specifies if the catalog information
"      should be included in the backup. The default for this parameter is TRUE.
"
"    backup_system_family, bsf: This parameter specifies if the $system
"      family should be included in the backup. The defualt for this parameter
"      is TRUE.
"
"    output_disposition, odi: This parameter specifies the destination of the
"      output generated.  The default for this parameter is 'PRINTER'
"
" 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

  VAR
    backup_file_created: 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
        create_file f=backup_file
        detach_file f=backup_file
        backup_file_created = TRUE
      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 ..
            volume_list=volume_list
    IFEND
  IFEND

  IF $specified(backup_file) THEN
    attach_or_request_command = 'attach_file am=write local_file_name=backup_file file= '//$string(backup_file)
  ELSE
    attach_or_request_command = 'request_magnetic_tape file=$local.backup_file ring=yes type='//$string(type)// ..
          ' external_vsn='//$string(volume_list, source)// ..
          '; set_file_attributes file=$local.backup_file file_label_type='//$string(file_label_type)
  IFEND

"Create a file containing a batch job to do the actual backup.
COLLECT_TEXT output=job_file sm='?' until='**END_COLLECT**'
  JOB job_name=fullback job_class=system magnetic_tape_limit=unlimited output_disposition=?output_disposition?
    ?attach_or_request_command?
    date=$date(mdy)
    time=$time(hms)

    WHEN any_fault DO
     IF ?backup_file_created? THEN
       change_file_attributes file=$local.backup_file ring_attributes=(11,11,11)
     IFEND
     detach_file file=$local.backup_file
     display_value osv$status
     send_operator_message ' CREATE_FULL_BACKUP aborting -check listing '
    WHENEND

    SYSTEM_OPERATOR_UTILITY CAPABILITIES=(SYSTEM_ADMINISTRATION SYSTEM_DISPLAYS)

    VAR
      empty_list: list 0 .. 0 of string
      exclude_status: status
      family_list: list of name = ()
      rml_is_active: boolean
      rms_status: status
    VAREND

    LOGICAL_CONFIGURATION_UTILITY
      FOR each set in $active_sets() DO
        family_list = $join($active_set_families(set), family_list)
      FOREND
    QUIT

    rml_is_active = FALSE
    IF $file($system.rms.rsf$command_library, permanent) THEN
      PUSH command_list
      create_command_list_entry $system.rms.rsf$command_library status=rms_status
      IF $library(active)<>empty_list THEN
        rml_is_active = TRUE
        rml_catalog = $path($array($library(active))(1), catalog)
        rml = $array($library(active))(1)
        IF $string($file_attributes(rml, log_residence)) <> 'NONE' THEN
          exclude_recovery_logs_cmd = 'exclude_catalog catalog = '//..
                $string($file_attributes(rml, log_residence))
          backup_recovery_logs_cmd = 'backup_catalog catalog = '//..
                $string($file_attributes(rml, log_residence))
        ELSE
          exclude_recovery_logs_cmd = '"No recovery logs configured."'
          backup_recovery_logs_cmd = '"No recovery logs configured."'
        IFEND
      IFEND
      POP command_list
    IFEND;

    TASK ring=3
      backup_permanent_files backup_file=$local.backup_file
        set_backup_options include_archive_information=TRUE
        set_backup_options exclude_catalog_information=?$NOT(backup_catalogs)?
        IF "include $system catalog =" ?backup_system_family? THEN
          "$system family included in backup.
        ELSE
          exclude_catalog catalog=:$system status=exclude_status
        IFEND

        FOR EACH family_name IN family_list DO
          exclude_catalog catalog=$fname(':'//$string(family_name)//'.$SYSTEM.$JOB_INPUT_QUEUE')..
                status=exclude_status
        FOREND

        exclude_catalog catalog=$system.$df$client_mainframes status=exclude_status
        exclude_catalog catalog=$system.aam.shared_recovery_log status=exclude_status

        IF rml_is_active THEN
          exclude_catalog catalog=$fname(rml_catalog)
          include_line exclude_recovery_logs_cmd
        IFEND

        backup_all_files

        IF exclude_status.normal THEN
          backup_catalog catalog=$system.aam.shared_recovery_log
        IFEND

        IF rml_is_active THEN
          close_volume
          backup_catalog catalog=$fname(rml_catalog)
          include_line backup_recovery_logs_cmd
        IFEND;

      QUIT
      IF ?backup_file_created? THEN
        change_file_attributes file=$local.backup_file ring_attributes=(11,11,11)
      IFEND
      detach_file file=$local.backup_file
    TASKEND
    QUIT

    put_line line=date output=$user.date_of_full_backup.$boi
    put_line line=time output=$user.date_of_full_backup.$eoi

    include_file file=$system.hardware_maintenance.hpa.hpf$start_monitor_job
  JOBEND
**END_COLLECT**

  include_file file=job_file
  detach_file file=job_file

PROCEND create_full_backup
