.enable substitution
.enable timeout
.disable lowercase
.enable decimal
.; These are the devices to back up
.sets devs "vd0,vd1,DM1,DR0"
.; This is where the backup date file is kept
.sets dirbak "1,2"
.; This is where the directorys are kept
.sets dirloc "1,100"
.sets os "000"
;
; Automatic backup procedure
;
.iff <PRIVIL> .goto 100
.setf dcl
.test <cli> "DCL"
.if <strlen> <> 0 .sett dcl
set /mcr=ti:
.;set /nologon
.sets months "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC"
.xqt bro log:Please log off...We are starting BACKUP
;
; Now we wait while they logout...
;
.5:
	.asks [::"'devs'":2M] dev1 Disk(s) to backup
.10:
	.parse dev1 "," dev dev1
	.test dev
	.if <strlen> <> 0 .goto 15
	.test dev1
	.if <strlen> = 0 .goto 50
	.sets dev dev1
	.sets dev1 ""
.15:
	.testdevice 'dev':
	.test <exstri> "nsd"	! No such device
	.if <strlen> <> 0 .goto 20
	.test <exstri> "unl"	! Device driver is unloaded
	.if <strlen> <> 0 .goto 20
	.test <exstri> "npu"	! Device is not public
	.if <strlen> <> 0 .goto 20
	.test <exstri> "mtd"	! Device is mounted
	.if <strlen> <> 0 .goto 30
.20:
;
; Cannot backup from device 'dev'
;
	.goto 5
.30:
	.sets today "'<date>' '<time>'"
	.testfile 'dev':['dirbak']backup.dat
	.if <filerr> <> 1 .goto 35
	.openr 'dev':['dirbak']backup.dat
	.read start
	.close
	.goto 40
.35:
	.asks [::"'<date>'":15S] start Starting date of files to be backed up
	.parse start "-- " day mon year junk
	.gosub chkdat
	.if month > 12 .goto 35
	.if <filerr> = 230 .goto 36
	.gosub errfil
	.goto 30
.36:
	.; Does an uic exist?
	.parse <filspc> ":].;" a1 a2 a3 a4 a5
	.; If the file backup.dat does not exist, continue
	.if a3 = "BACKUP" .if a4 = "DAT" .goto 40
	.; If the file 001002.dir does not exist make one
	.parse dirbak "," b1 b2
	.test b1
	.if <strlen> < 3 .sets b1 os[1:3-<strlen>]+b1
	.test b2
	.if <strlen> < 3 .if <strlen> <> 0 .sets b2 os[1:3-<strlen>]+b2
	.if a3 = "'b1''b2'" .if a4 = "DIR" .goto 37
	.gosub errfil
	.goto 30
.37:
	.ifnins ...ufd ins $ufd
	ufd 'dev':['dirbak']
	.if <exstat> = 1 .goto 38
	.gosub ufderr
	.goto 37
.38:
	rem ...ufd
.40:
	.parse today "-- " day mon year junk
	.gosub chkdat
	.sets month1 ""
	.if month < 10 .sets month1 "0"
	.sets end "'year''month1''month''day'"
;
; Files located on 'dev': created/revised between
; 'start' and 'today' will be saved
;
	.ask [<true>:15S] null Is this correct
	.iff null .goto 35
	.ifdf type .goto 45
;
; Mount backup tape on MT0
;
	.ask null Ready
	.sets app ""
	.ask [<false>:15S] type Is this a new tape
	.iff type .sets app  "/a"
	.ifnins BRU ins $bru
.45:
bru'app'/mo/rev:a:('start')/bac:'dev''end'/rew/v 'dev':[*,*] mt0:
.; Check to see if the task has any drastic errors
	.if <exstat> <= 1 .goto 46
.;	If we fall thru then error or greater.
	.gosub bruerr
	.goto 45
.46:
.;	.ifnins ...srd ins $srd
	.parse dirloc "," b1 b2
	.test b1
	.if <strlen> < 3 .sets b1 os[1:3-<strlen>]+b1
	.test b2
	.if <strlen> < 3 .if <strlen> <> 0 .sets b2 os[1:3-<strlen>]+b2
	.testfile 'dev':[0,0]'b1''b2'.dir
	.if <filerr> = 1 .goto 47
	.if <filerr> = 230 .goto 48
	.gosub direrr
	.goto 46
.48:
	.ifnins ...ufd ins $ufd
	ufd 'dev':['dirloc']
	.if <exstat> = 1 .goto 49
	.gosub ufderr
	.goto 48
.49:
	rem ...ufd
.47:
.;srd 'dev':['dirloc']'dev''end'.SRD='dev':[*,*]/mi/rd/ae:'start'
	.ifnins ...pos ins $pos
	.ifnins ...rec ins $rec
	pos mt: -3
	rec mt: -2
run $brudir/cmd=" mt:/-rw 1600 list 'dev':['dirloc']'dev''end'.dru"
	.if <exstat> = 1 .goto 481
	.gosub srderr
	.goto 47
.481:
	pip 'dev':['dirbak']backup.dat;*/de/nm
	.if <exstat> = 1 .goto 491
	.gosub piperr
	.goto 48
.491:
	.open 'dev':['dirbak']backup.dat
	.data 'today'
	.close
	.sets app "/a"
	.test dev1
	.if <strlen> <> 0 .goto 10
	.ask [<false>:30S] rept Repeat procedure
	.ift rept .goto 5
.50:
	.xqt bro all:You may log on again...The backup is done
	set /logons
	.ift dcl .xqt set /dcl=ti:
;
; Backup operation is done
;
	.exit
.chkdat:
	.setn index 1
	.setn month 1
.70:
	.sets temp months[index:index+2]
	.if temp = mon .goto 75
	.setn index index+3
	.inc month
	.if month <= 12 .goto 70
.75:
	.return
.100:
;
; You must be a privileged user to do the backup
;
	.exit
.bruerr:
;
; BRU task exit with status '<exstat>'
;
.ask yn "Do you want to correct the error"
.iff yn .goto 200
;
; We will pause while you correct the error
;
	.ifnins ...pos ins $pos
	.sets time <time>
	.parse time "::" t1 t2 t3
	.setn tb1 't1'
	.setn tb2 't2'
	.setn tb3 't3'
	pos mt: -1
	.sets time2 "::" t1 t2 t3
	.setn te1 't1'
	.setn te2 't2'
	.setn te3 't3'
	.setn tb tb2*60.+tb3
	.setn te te2*60.+tb3
	.if te1 <> tb1 .setn te te+3600.
	.if te-tb lt 2 pos mt: -1
	pos mt: -1
	pos mt: 1
	.pause
	rem pos
	.return
.srderr:
;
; SRD task exit with status '<exstat>'
;
.ask [<FALSE>:60S] yn "Do you want to correct the error"
.iff yn .goto 200
;
; We will pause while you correct the error
;
	.pause
	.return
.piperr:
;
; PIP task exit with status '<exstat>'
;
.ask [<FALSE>:60S] yn "Do you want to correct the error"
.iff yn .goto 200
;
; We will pause while you correct the error
;
	.pause
	.return
.errfil:
;
; We could not open or make the backup date file
;
.ask [<FALSE>:60S] yn "Do you want to correct the error"
.iff yn .goto 200
;
; We will pause while you correct the error
;
	.pause
	.return
.direrr:
;
; We could not find out about the directory
;
.ask [<FALSE>:60S] yn "Do you want to correct the error"
.iff yn .goto 200
;
; We will pause while you correct the error
;
	.pause
	.return
.ufderr:
;
; We could not make the ufd
;
.ask [<FALSE>:60S] yn "Do you want to correct the error"
.iff yn .goto 200
;
; We will pause while you correct the error
;
	.pause
	.return
.200:
	.ift dcl .xqt set /dcl=ti:
	.exit

