home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
netbck01.zip
/
NETBACK.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1994-05-19
|
29KB
|
467 lines
/* */
PARSE ARG ArgGroup
/* ***************************************************************************** *
* Schedule. stem record as follows: *
* Schedule.UserCount <- # Users in BACKUP.DAT schedule list *
* .{UserIndex}.DiskCount <- Number of disks user has *
* .Disk{1} <- First Disk name *
* : *
* .Disk{DiskCount} <- last disk name *
* .ReqId <- Requester Id *
* .Status <- Marked as PENDING | NOT ONLINE *
* .UserId <- User ID for this ReqId *
* .NickName <- Users nickname for msgs *
* ------------------------------------------------------------------------------*
* HISTORY: *
* *
* 1/Oct/93 : Fixed problem where a defined user had peer running but did not *
* have any peer disks defined. I was 'PULL'ing from an empty queue *
* in this case and so system would 'hang' waiting for input from *
* the keyboard. *
* *
* Effected routine: FindRemoteDisks() *
* Change: Added check for first line in queue containing *
* the word 'THERE' (Hard coded response from NET *
* cmd indicating 'THERE ARE NO ENTRIES IN THE LIST*
* If LS NET.EXE changes is return command this *
* probably break again. Unfor. NET.EXE does not *
* use RC to indicate if the net command found real*
* data, just that the NET.EXE cmd did execute. *
* *
* *
* Added the 'EchoCh' variable. If it is set to '@' then system cmds *
* are NOT echoed to console. If it is set to ''(null) then cmds *
* ARE ECHOED to console. For debugging purposes.. *
* *
* 15/Nov/93: Due to another change in the NET output of error data I've *
* changed the FindRemoteDisks() function once again. *
* NET no longer directs error data to STDIO when a \\server is *
* not found. Now it just goes to STDERR which is not trapped *
* by RXQUEUE. So I now test for an empty queue and treat that *
* as an error condition as well. *
* *
* 07/Mar/94: Added two lines to start of exec to FORCE a change to the correct *
* DRIVE and DIRECTORY where Sytos lives. Apparently Clock starts *
* all apps from C: and when we moved Sytos to D: the exec would fail.*
* ***************************************************************************** */
signal on halt name ProgErr
signal on syntax name ProgErr
/* *************************************************************************** *
* Change the following settings based on your Lan server setup *
* *************************************************************************** */
'C:' /* Select home drive where SYPLUS is found */
'CD \SYPLUS' /* Switch to the SYPLUS directory */
AdminID = 'ADMIN' /* Admin ID used for PEER backups */
AdminPW = 'SMITH' /* Admin ID Password used to logon to ID */
RemoteDiskId = 'M:' /* DiskID defined in APPEND/NEWTAPE.MAC */
EchoCh = '' /* -DEBUG- '@':no con echo, '':= con echo */
/* *************************************************************************** *
* End of site customized variables *
* *************************************************************************** */
LogRc = Log("Starting NETBACK.CMD") /* Log start of execution */
BackupGroup = 0 /* Group of users to backup */
Online. = '' /* User's currently on line */
Schedule. = '' /* User's scheduled for backup */
CurBackupId = 0 /* Current user ID being processed */
CurBackupDiskId = 1 /* Current users disk ID being processed */
MsgPending = ', Your system is scheduled for backup at', /* MSG: Warn user of pending backup */
' this time. DO NOT LOGOFF till you are',
' told it is safe to do so. Thanks.. '
MsgStarting= ', Your system is being backed up RIGHT', /* MSG: Warn user of ACTIVE backup */
' NOW! Do NOT LOGOFF till you are',
' told it is safe to do so. Thanks.. '
MsgAllDoneOk=', Your system has been successfully', /* MSG: OK Completed backup */
' backed up. You may now LOGOFF safely.'
CurMsg = ''
IF ArgGroup <> '' THEN /* If group is NOT blank, set to specific */
BackupGroup = ArgGroup /* group, else do everyone. */
CurDate = DATE() /* Tag current date */
CurTime = TIME() /* Tag current time */
CurMacroName = 'CURRENT NET BACKUPS' /* Change MACRO NAME */
EchoCh||'LOGOFF /D' /* Do a logoff JIC */
EchoCh||'LOGON 'AdminID' /P:'AdminPW' /V:D' /* Do a LOGON to the backup id (ADMIN) */
IF (RC <> 0) THEN /* FAILED? */
DO
SAY "UNABLE TO LOGON TO REQUIRED MASTER ID. TERMINATING" /* YES: ABORT */
LogRc = Log("UNABLE TO LOGON TO REQUIRED MASTER ID. TERMINATING" )
EXIT
END
MyRc = LoadBackupList() /* Read the list of backup REQUESTERS */
MyRc = PullLoggedOnUsers() /* Get net info on who's logged on NOW */
MyRc = MarkMissingUsers() /* Verify list against logged on users */
MyRc = FindRemoteDisks() /* Locate remote disks and record for bkup */
MyRc = DebugDumpSchedule()
MyRc = SetupNewTapeMacro() /* Create NEW TAPE macro for SYTOS */
/* *************************************************** *
* FIRST backup is special as we must use a macro that *
* will ERASE the tape first, then setup a VOL NAME *
* *************************************************** */
CurBackupId = FindFirst() /* Find first PENDING backup in list */
IF( CurBackupId = 0) THEN /* Handle NO PENDINGs found */
DO
SAY "NO USERS FOUND PENDING TO DO BACKUPS"
LogRc = Log("NO USERS FOUND PENDING TO DO BACKUPS" )
EXIT
END
MyRc = DebugDumpSchedule()
MyRc = PostNetMsg(CurBackupId, MsgStarting ) /* Build STARTING msg */
MyRc = SetTapeSetName( Schedule.CurBackupId.ReqId,Schedule.CurBackupId.Disk1 )
LogRc = Log("Backing up user "|| Schedule.CurBackupId.UserId||" Disk: "||Schedule.CurBackupId.Disk1)
EchoCh||'NET USE 'RemoteDiskId' \\'Schedule.CurBackupId.ReqId'\'Schedule.CurBackupId.Disk1 ' > NUL'
'SYPLUS "'CurMacroName'"' /* Do the FIRST backup for this user. */
'NET USE 'RemoteDiskId' /D > NUL' /* RELEASE from users disk */
LogRc = Log("END BACKUP user "|| Schedule.CurBackupId.UserId||" Disk: "||Schedule.CurBackupId.Disk1)
/* *************************************************** *
* NEXT backup onward are normal in that we just walk *
* the list of drives to be backed up and keep append *
* to the tape volume using an APPEND macro. *
* *************************************************** */
MyRc = DebugDumpSchedule()
MyRc = SetupAppTapeMacro() /* Create APPEND tape macro for SYPLUS */
NextDisk = FindNext() /* Locate next available disk to backup */
DO WHILE (NextDisk <> 'DONE')
MyRc = SetTapeSetName( Schedule.CurBackupId.ReqId,Schedule.CurBackupId.NextDisk )
LogRc = Log("Backing up user "|| Schedule.CurBackupId.UserId||" Disk: "||Schedule.CurBackupId.NextDisk)
EchoCh||'NET USE 'RemoteDiskId' \\'Schedule.CurBackupId.ReqId'\'Schedule.CurBackupId.NextDisk ' > NUL'
'SYPLUS "'CurMacroName'"' /* Do the FIRST backup for this user. */
EchoCh||'NET USE 'RemoteDiskId' /D > NUL' /* RELEASE from users disk */
LogRc = Log("END BACKUP user "|| Schedule.CurBackupId.UserId||" Disk: "||Schedule.CurBackupId.NextDisk)
NextDisk = FindNext() /* Locate next available disk to backup */
END
MyRc = DebugDumpSchedule() /* just a debug dump */
LogRc = Log("ENDED NETBACK.CMD") /* Log start of execution */
ProgErr:
EchoCh||'LOGOFF /D' /* Do a logoff JIC */
EXIT
/* ============================================================================= */
/* LoadBackupList: Reads the BACKUP.DAT file to determine which stations */
/* should be backed up in this pass */
/* ============================================================================= */
LoadBackupList: PROCEDURE EXPOSE Schedule. BackupGroup EchoCh
DatFile = 'NETBACK.DAT'
SIGNAL ON NOTREADY /* Do this when EOF */
count = 0
DO FOREVER
line = LINEIN( DatFile ) /* Get line from file */
IF (STRIP( line) \= '') THEN /* Valid line ? */
DO /* YES: */
IF (BackupGroup = 0) THEN /* Is group set to EVERYONE? */
DO /* YES: */
count = count + 1 /* Pull/parse user backup record */
Schedule.Count.UserId = WORD(Line,2) /* UserId */
Schedule.Count.ReqId = WORD(Line,3) /* ReqId */
Schedule.Count.NickName = WORD(Line,4) /* NickName */
Schedule.Count.Status = 'NOT ONLINE' /* Default status of NOT ONLINE */
Schedule.Count.DiskCount= 0 /* Default to NO DISKS AVAILABLE (0) */
END
ELSE /* NO: */
DO
TmpGroup = WORD(Line,1) /* Get this record's group identifier */
IF (TmpGroup = BackupGroup) THEN /* Is it EQ to specified group? */
DO /* YES: */
count = count + 1 /* Normal Pull/Parse user backup rec */
Schedule.Count.UserId = WORD(Line,2)
Schedule.Count.ReqId = WORD(Line,3)
Schedule.Count.NickName = WORD(Line,4)
Schedule.Count.Status = 'NOT ONLINE'
Schedule.Count.DiskCount= 0 /* Default to NO DISKS AVAILABLE (0) */
END
END /* else */
END /* if strip() */
END /* forever */
NOTREADY: /* EOF reached */
Schedule.UserCount = Count /* Save user records count */
RETURN 0
/* ============================================================================= */
/* FindNext: This locates the next available disk/user id, returns */
/* his schedule ID# and flags him as 'PROCESSING' */
/* ============================================================================= */
FindNext: PROCEDURE EXPOSE Schedule. CurBackupId CurBackupDiskId MsgAllDoneOk MsgStarting EchoCh
/* ======================================= *
* Handle possible multi drives per user *
* ======================================= */
IF CurBackupDiskId <> Schedule.CurBackupId.DiskCount THEN /* More DISKS for this user ? */
DO /* YES: */
CurBackupDiskId = CurBackupDiskId + 1 /* set next disk id # */
RETURN 'DISK'||CurBackupDiskId /* return DISK# */
END
/* ======================================= *
* Handle NEXT 'PENDING' user id backup *
* ======================================= */
MyRc = PostNetMsg(CurBackupId, MsgAllDoneOk) /* Send OLD user BACKUP ENDED msg */
CurBackupId = FindFirst() /* Locate NEXT pending user is */
IF (CurBackupId = 0) THEN /* Was there another user PENDING? */
DO /* NO: */
CurBackupDiskId = 0 /* set disk # to 0 */
LogRc = Log("No more users to backup")
RETURN 'DONE' /* return flag DONE */
END
MyRc = PostNetMsg(CurBackupId, MsgStarting) /* Send NEW USER BACKUP STARTING msg */
CurBackupDiskId = 1 /* Mark default FIRST disk */
RETURN 'DISK'||CurBackupDiskId /* return DISK# */
/* ============================================================================= */
/* FindFirst: This locates the first available backup user, returns */
/* his schedule ID# and flags him as 'PROCESSING' */
/* ============================================================================= */
FindFirst: PROCEDURE EXPOSE Schedule. EchoCh
DO x=1 TO Schedule.UserCount /* Scanning the Schedule list */
IF (Schedule.x.Status == 'PENDING') THEN /* IS this user's status PENDING */
DO /* YES: */
Schedule.x.Status = 'PROCESSING' /* Mark status now PROCESSING */
RETURN x /* return user's index # */
END
END
RETURN 0 /* DEFAULT: 0 = NO PENDINGS FOUND */
/* ============================================================================= */
/* SetTapeVolName: This alters a machro template by changing the VOL NAME */
/* so we can identify the ReqId this backup belongs to. */
/* ============================================================================= */
SetTapeVolName: PROCEDURE EXPOSE CurDate CurTime CurMacroName EchoCh
x = SETLOCAL() /* save current directory info */
/* EchoCh||'CD \SYPLUS\SYFILES\SYMAC' Switch to SYTOS macro dir */
EchoCh||'CD SYFILES\SYMAC' /* Switch to SYTOS macro dir */
x = CHAROUT( 'CURNET.MAC',CurMacroName,1 ) /* Change MACRO NAME */
x = CHAROUT( 'CURNET.MAC',CurDate,77) /* Change VOLUME NAME */
x = CHAROUT( 'CURNET.MAC',CurDate||" "||CurTime,97) /* Change VOLUME DESC */
x = CHAROUT( 'CURNET.MAC' ) /* Close file */
x = ENDLOCAL() /* Restore previous dir location */
RETURN 0
/* ============================================================================= */
/* SetTapeSetName: This alters a machro template by changing the SET NAME */
/* so we can identify the ReqId this backup belongs to. */
/* ============================================================================= */
SetTapeSetName: PROCEDURE EXPOSE EchoCh
PARSE ARG ReqId, DiskName
x = SETLOCAL() /* save current directory info */
/* EchoCh||'CD \SYPLUS\SYFILES\SYMAC' Switch to SYTOS macro dir */
EchoCh||'CD SYFILES\SYMAC' /* Switch to SYTOS macro dir */
Buff = ' ' /* Buff set to 18 SPACES !NO MORE! */
x = CHAROUT( 'CURNET.MAC', OVERLAY(DiskName,Buff),151) /* Change SET NAME */
x = CHAROUT( 'CURNET.MAC', OVERLAY(ReqId,Buff),171) /* Change SET DESC */
x = CHAROUT( 'CURNET.MAC' ) /* Close file */
x = ENDLOCAL() /* Restore previous dir location */
RETURN 0
/* ============================================================================= */
/* SetupNewTapeMacro: This sets up a NEW TAPE macro to use as the FIRST */
/* MACRO in a tape set. It erases, create new VOLUME. */
/* It then sets up the first backup SET NAME. */
/* ============================================================================= */
SetupNewTapeMacro: PROCEDURE EXPOSE CurDate CurTime CurMacroName EchoCh
x = SETLOCAL() /* save current directory info */
/* EchoCh||'CD \SYPLUS\SYFILES\SYMAC' Switch to SYTOS macro dir */
EchoCh||'CD SYFILES\SYMAC' /* Switch to SYTOS macro dir */
EchoCh||'COPY NEWTAPE.MAC CURNET.MAC > NUL' /*create working copy of macro */
MyRc = SetTapeVolName() /* Set vol name to todays date */
x = ENDLOCAL() /* Restore previous dir location */
RETURN 0
/* ============================================================================= */
/* SetupAppTapeMacro: This sets up an APPEND macro to use as the NEXT */
/* MACRO in a tape set. It uses the same VOL name defined */
/* in NEW so that ALL backups now are in same VOLUME. */
/* ============================================================================= */
SetupAppTapeMacro: PROCEDURE EXPOSE CurDate CurTime CurMacroName EchoCh
x = SETLOCAL() /* save current directory info */
/* EchoCh||'CD \SYPLUS\SYFILES\SYMAC' Switch to SYTOS macro dir */
EchoCh||'CD SYFILES\SYMAC' /* Switch to SYTOS macro dir */
EchoCh||'COPY APPEND.MAC CURNET.MAC > NUL' /* create working copy of macro */
MyRc = SetTapeVolName() /* Set vol name to todays date */
x = ENDLOCAL() /* Restore previous dir location */
RETURN 0
/* ============================================================================= */
/* MarkMissingUsers: Compares logged on users with those sceduled for backup */
/* Missing users are flagged as such, others flagged as */
/* ready for backup (PENDING) */
/* ============================================================================= */
MarkMissingUsers: PROCEDURE EXPOSE OnLine. Schedule. MsgPending EchoCh
DO x=1 TO Schedule.UserCount /* Compare Schedule list */
DO y=1 TO OnLine.UserCount /* against Online list */
IF (Schedule.x.ReqId == OnLine.y.ReqId) THEN /* And if MATCHING ReqId are found */
DO
Schedule.x.Status = 'PENDING' /* Mark user in Schedule as PENDING */
MyRc = PostNetMsg( x, MsgPending ) /* Warn user of backup process */
END
END
END
RETURN 0
/* ============================================================================= *
* FindRemoteDisks: Uses the NET VIEW command to find out what disks each *
* user has available for backup. Each disk is added to the *
* Schedule. stem record as follows: *
* Schedule.{UserIndex}.DiskCount <- Number of disks user has *
* .Disk{1} <- First Disk name *
* : *
* .Disk{DiskCount} <- last disk name *
* .ReqId <- Requester Id *
* .Status <- Marked as PENDING | NOT ONLINE *
* ============================================================================= */
FindRemoteDisks: PROCEDURE EXPOSE Schedule. EchoCh
DiskIdBase = 'DISK' /* Define the variable base name */
DiskId = '' /* Define a working variable */
EchoCh||'RXQUEUE /clear' /* Clear the REXX QUEUE */
DO x=1 to Schedule.UserCount /* Scan list of users */
IF (Schedule.x.Status = 'PENDING') THEN /* This user PENDING? */
DO /* YES: */
EchoCh||'RXQUEUE /clear' /* Clear the REXX queue */
EchoCh||'NET VIEW \\'Schedule.X.ReqId' | RXQUEUE' /* Net request */
Schedule.x.DiskCount = 0 /* Set disks to default of 0 */
IF ( QUEUED() \= 0 ) THEN
DO
PULL line
IF WORD(line,1) == 'THERE' THEN
Schedule.x.Status = 'NO DISKS FOUND'
ELSE
DO
PULL .
PULL .
PULL .
DO QUEUED()
PULL line
IF WORD(line,2) == 'DISK' THEN
DO
Schedule.x.DiskCount = Schedule.x.DiskCount + 1
DiskId = DiskIdBase||Schedule.x.DiskCount
Schedule.x.DiskId = WORD(line,1)
END
END
END
END
ELSE
Schedule.x.Status = 'NO DISKS FOUND'
END
END
RETURN 0
/* ============================================================================= */
/* PullLoggedOnUsers: Uses the NET WHO command to find out who is logged on */
/* and adds each user to the stem 'OnLine' */
/* ============================================================================= */
PullLoggedOnUsers: PROCEDURE EXPOSE OnLine. Schedule. EchoCh
EchoCh||'RXQUEUE /clear'
EchoCh||'NET WHO | RXQUEUE'
PULL .
PULL .
PULL .
PULL .
count = 0
DO QUEUED()
PULL line
IF QUEUED() = 0 THEN
DO
OnLine.UserCount = count
RETURN 0
END
count = count+1
OnLine.Count.UserId = WORD(Line,1)
OnLine.Count.ReqId = WORD(Line,2)
END
RETURN 0
/* ============================================================================= */
/* DebugDumpSchedule: This just dumps the formatted contents of the internal */
/* stem record containing the user list/status etc. */
/* ============================================================================= */
DebugDumpSchedule: PROCEDURE EXPOSE Schedule. BackupGroup EchoCh
SAY '[GROUP SET : 'BackupGroup ']'
SAY '[USER COUNT : 'Schedule.UserCount' ]'
SAY '===================================='
DO x=1 TO Schedule.UserCount
SAY '[REQ:'Schedule.x.ReqId '] [USER: 'Schedule.x.UserId '][STATUS: 'Schedule.x.Status' ]'
SAY '[DISKS FOUND:'Schedule.x.DiskCount '] '
DO y=1 TO Schedule.x.DiskCount
disk = 'DISK'||y
SAY Schedule.x.disk
END
SAY '===================================='
END
RETURN 0
/* ============================================================================= */
/* PostNetMsg: Send a msg to the user informing them of system status */
/* */
/* ============================================================================= */
PostNetMsg: PROCEDURE EXPOSE Schedule. EchoCh
PARSE ARG Id, MsgText
CurMsg = Schedule.Id.NickName||MsgText /* Build STARTING msg */
EchoCh||'NET SEND 'Schedule.Id.ReqId CurMsg /* Tell user backup is starting NOW! */
RETURN 0
/* ============================================================================= */
/* Log: Logs data line to a execution log file */
/* */
/* ============================================================================= */
Log: PROCEDURE EXPOSE EchoCh
PARSE ARG Line
LogFile = 'NETBACK.LOG' /* Processing log file name */
LogLine = DATE()||" "||TIME()||" - "||Line /* Add Date/Time to output */
x = LINEOUT( LogFile, LogLine ) /* Dump to log file */
x = LINEOUT( LogFile ) /* Close the Log file */
RETURN 0
/* ============================================================================= */
/* END OF FILE END OF FILE END OF FILE END OF FILE */
/* ============================================================================= */