.ONERR ERROR
.ENABLE GLOBAL
.ENABLE SUBSTITUTION
;.ENABLE QUIET
.DISABLE LOWERCASE
.SETF DIE
.SETN EXSTAT 0
.; TO SEE IF WE ARE CONTINUING EXECUTION FROM THE MAIN SYSTEM DISK
.IFDF $UIC .GOTO CONTIN
.SETS $REWIN "/REW"
.SETS $APPEN ""
.SETS $UIC <UIC>
.SETS $SYDSK <SYDISK>
.SETN $UNIT <SYUNIT>
.SETT $NEW
.SETS $CR ""
.ASK $INCBK INCREMENTAL BACKUP OF DISK
.5:.ASKS DSK ENTER THE DISK DRIVE WITH THE FILES TO BE BACKED UP(DDU)
.SETS $DISK DSK[1:3]+":"
.SETS $ACSBL ""
.IF $DISK EQ "DB0:" .SETS $ACSBL "1024."
.IF $DISK EQ "DB0:" .GOTO 7
.IF $DISK EQ "DB1:" .GOTO 7
.IF $DISK EQ "DK0:" .GOTO 7
.IF $DISK EQ "DK1:" .GOTO 7
; Invalid DISK, try again !!
.GOTO 5


;;;;;;;;;; ERRORS ;;;;;;;;
.ERROR:
.IFNDF $REWIN ; $REWIN NOT DEFINED
/


.7:
.SETS $TYP $DISK[1:2]
.SETS $WHO "ALL"
.IF $TYP EQ "DK" .SETS $WHO "TI"
.ASKS $DSKNA WHAT IS THE VOLUME-LABEL OF THE DISK
.IFF $INCBK .SETT $NEW

.ATNAM:
.ASKS $TAPNA ENTER THE NAME OF THE BRU MAG TAPE
.IFT <ALPHAN> .AND .IF <STRLEN> LE 12 .GOTO AMTN
.DISABLE QUIET
; ERROR -- Must be alphanumeric & less than 13 characters.
.ENABLE QUIET
.GOTO ATNAM

.AMTN:
.ASKS $TPNM WHAT IS THE MAGTAPE NUMBER
.IFT <ALPHAN> .AND .IF <STRLEN> LE 12 .GOTO ATELL
.DISABLE QUIET
; ERROR -- Must be alphanumeric & less than 13 characters.
.ENABLE QUIET
.GOTO AMTN

.ATELL:
.ASK $ANN Do you want to tell all terminals about the backup
.IFT $INCBK .ASK $NEW START A NEW BRU TAPE
.IFF $NEW .SETS $REWIN ""
.IFF $NEW .SETS $APPEN "/APP"
.SETS $FILNA "DB0:"+$TAPNA+".BRU"
.IFT $INCBK .AND .IFT $NEW PIP '$FILNA';*/DE/NM
.IFF $NEW TYP '$FILNA'
.IFF $NEW .TESTFILE '$FILNA'
.IFF $NEW .IF <FILERR> NE 1 .SETT DIE
.IFT DIE .DISABLE QUIET
.IFT DIE ; NO RECORD EXISTS OF A PREVIOUS BACKUP WITH THIS TAPE NAME
.IFT DIE ; PERCHANCE, THE TAPE NAME IS WRONG. -- EXITING
.IFT DIE /
.IFF $NEW .ASKN [1:100] $NVERS WHAT IS THE NEXT VERSION NUMBER
.IFT $NEW .SETN $NVERS 1
.SETS $VERSN "'$NVERS'"
.SETS $BCKSE $DSKNA+";"+$VERSN
.IFF $INCBK .SETS $DATE ""

.IFF $INCBK .GOTO 12
.10:.ASKS $DATE WHAT IS THE DATE TO BACKUP AFTER(DD-MMM-YY)
.IF $DATE EQ $CR .SETS $DATE "01-JAN-76"
.12:
.ASK $CMP Verify it (a seperate operation)
.SETS $TDATE <DATE>
.SETS $WHOLE ""
.IFF $INCBK .SETS $WHOLE "$WHOLE DISK BACKUP"
.IFF $INCBK .SETS $MOUNT ""
.IFT $INCBK .SETS $MOUNT "/MOUNTED"
.IFF $INCBK .SETS $REVIS ""
.IFT $INCBK .SETS $REVIS "/CR:AFTER:"
 
.; IF WE ARE DOING A $WHOLE DISK BACKUP OF THE SYSTEM DISK,
.; SWITCH OVER TO THE OTHER PUBLIC DISK, SO WE CAN DISMOUNT THIS ONE.
.IFT $INCBK .OR .IF $DISK NE "DB0:" .GOTO CONTIN
PIP DB1:=INCBKP.CMD
.IF <EXSTAT> = 1 .GOTO CON1
.DISABLE QUIET
; CANNOT COPY THE NECESSARY FILES TO DB1, EXITTING
/
.CON1:
ASN DB1:=SY:
.CHAIN SY:INCBKP/DEL
;
;
.; RE-START POINT ON THE OTHER DISK
.CONTIN: 
PIP BRUBACKUP.CMD;*/DE/NM,BRUCMP.CMD;*
.OPEN BRUBACKUP.CMD
.DATA /DEN:1600'$REWIN''$APPEN''$MOUNT'-
.DATA /INVOLUME:'$DSKNA''$REVIS''$DATE'-
.DATA /BACKUP_SET:'$BCKSE'-
.DATA  '$DISK'[*,*]*.*;* MM0:
.CLOSE
 
.IFNINS BRU INS $BRU/TASK=...BRU
ALL MM0:
.IF <EXSTAT> GT 1 .SETT DIE
.IFT DIE .DISABLE QUIET
.IFT DIE ; MAG TAPE COULD NOT BE ALLOCATED -- EXITING
.IFT DIE /
.SETS STTIM <TIME>
.IFF $INCBK .AND .IF $ACSBL NE "" ACS '$DISK'/BLKS=0
.IF $TYP = "DK" MOU '$DISK''$DSKNA'
.ENABLE QUIET
.GODMO:
.IFF $INCBK DMOU '$DISK'/DEV
.IF <EXSTAT> EQ 1 .GOTO DMOK
.DISABLE QUIET
.IF $ACSBL EQ "" .GOTO DMOERR
; The disk did not dismount, Probably because there are things still in
; the checkpoint file. Examine the following listing & enter the task-names
; of those that are out ("OUT"). Enter blank line when done. Enter ^Z to die.
ACT /ALL
.TSKUNS:
.ASKS TSK Give me a task that is out
.IF <STRLEN> = 0 .GOTO GODMO
UNS 'TSK'
.GOTO TSKUNS


.DMOERR:
; DISK WILL NOT DISMOUNT -- EXITING
.GOTO EXIT
.DMOK:
.IFT $ANN .AND .IFT $INCBK BRO '$WHO':INCREMENTAL BACKUP IN PROGRESS ON '$DISK'
.IFT $ANN .AND .IFF $INCBK BRO '$WHO':$WHOLE DISK BACKUP IN PROGRESS ON '$DISK'
.SETS $ERR "Successfully"
BRU @BRUBACKUP.CMD
.IF <EXSTAT> GT 1 .SETS $ERR "But BRU had fatal error"
.IF <EXSTAT> EQ 0 .SETS $ERR "But BRU had *WARNING* error"
.SETN EXSTAT <EXSTAT>
.IFT $ANN BRO '$WHO':BACKUP COMPLETED ON '$DISK'
.; check to see if we should verify
.IFF $CMP .GOTO 15
.IF EXSTAT GT 1 .GOTO 15
.OPEN BRUCMP.CMD
.DATA /DEN:1600'$REWIN''MOUNT'/COMPARE-
.DATA /INVOLUME:'$DSKNA''$REVIS''$DATE'-
.DATA /BACKUP_SET:'$BCKSE'-
.DATA  '$DISK'[*,*]*.*;* MM0:
.CLOSE
BRU @BRUCMP.CMD
.IF <EXSTAT> NE 1 .SETS $ERR $ERR+", Verify failed"
.15:
.IFF $INCBK MOU '$DISK''$DSKNA'
.IFF $INCBK .AND .IF <EXSTAT> GT 1 .SETS $ERR $ERR+", but re-MOUNT failed"
.IFF $INCBK .SETN EXSTAT EXSTAT!<EXSTAT>
.IFF $INCBK .AND .IF $ACSBL NE "" ACS '$DISK'/BLKS='$ACSBL'
.IFF $INCBK .SETN EXSTAT EXSTAT!<EXSTAT>
ASN DB0:=SY:
.SETS STPTIM <TIME>
.IF EXSTAT GT 1 .DISABLE QUIET
.IF EXSTAT GT 1 ; FATAL BACKUP ERROR, EXIT STATUS = 'EXSTAT'

.; MAKE AN INFO FILE FOR THE TAPE
.SETT $FILEI
.TESTFILE '$FILNA'
.IF <FILERR> GT 1 .SETF $FILEI
.OPENA '$FILNA'
.IFF $FILEI .DATA TAPE    DISK_NAME  VERSN TAPE #    BACKUP DATES	
.IFT $INCBK .DATA '$TAPNA'  '$DISK''$DSKNA'  '$NVERS'    '$DATE' - '$TDATE' '$ERR'
.IFF $INCBK .DATA '$TAPNA'  '$DISK''$DSKNA'  '$NVERS'     '$TPNM'     '$TDATE'  '$WHOLE' '$ERR'
.CLOSE
.; MAKE AN INFO FILE FOR THE DISK
.SETT $FILEI
.TEST $DSKNA
.SETS DNAM9 $DSKNA[1:9.]
.SETS $FILNA "DB0:"+DNAM9+".BRU"
.TESTFILE '$FILNA'
.IF <FILERR> GT 1 .SETF $FILEI
.OPENA '$FILNA'
.IFF $FILEI .DATA TAPE    DISK_NAME  VERSN TAPE #    BACKUP DATES	
.IFT $INCBK .DATA '$TAPNA'  '$DISK''$DSKNA'  '$NVERS'    '$DATE' - '$TDATE' '$ERR'
.IFF $INCBK .DATA '$TAPNA'  '$DISK''$DSKNA'  '$NVERS'     '$TPNM'     '$TDATE'  '$WHOLE' '$ERR'
.CLOSE
.EXIT:
.ENABLE QUIET
.IF EXSTAT NE 1 TYP BRUBACKUP.CMD
PIP DB0:BRUBACKUP.CMD;*/DE
.500:DEA MM0:
SET /UIC='$UIC'
ASN  '$SYDSK''$UNIT':=SY:
.IF EXSTAT LE 1 PRINT /FORM:1/NOFLAG='$TAPNA'.BRU,'$FILNA'
