//============================================================================= // // Task: TRSTBKUP.TSK // (Parse Trustee Rights list into a .TSK to recreate/replicate them) // Author: Avanti Technology, Inc. // http://www.avanti-tech.com // Version: 1.6 - Optimized for TaskMaster v4 // // Description: // ============ // Generate a listing of the Trustee Rights for a volume (or directory tree) // then parse the information to create a .TSK file which could be used as // backup/disaster recovery to recreate or replicate them on another Server. // // This example generates two files: SYS:\RIGHTS.LOG and SYS:\RIGHTS.TSK // SYS:\RIGHTS.LOG documents the Trustee Rights for the SYS: volume // SYS:\RIGHTS.TSK is a TaskMaster .TSK script to recreate/replicate the rights // // Objective: // ========== // Document and backup the Trustee Rights for a volume or tree in a manner // which makes it easy to recreate or replicate them. // // Usage: // ====== // Script can be manually executed using the TaskMaster TMRUN command // at the TMConsole (Shell) Screen: // // Example: TMRUN [vol:path\]TRSTBKUP.TSK // // Note: [vol:path\] is not required if the task resides either // in SYS:SYSTEM or the TaskMaster NLM load directory. // // Script can be scheduled for automatic execution using Client interface or // using the TaskMaster TMSCHEDULE command at the TMConsole (Shell) Screen: // // Examples: TMSCHEDULE ADD TRSTBKUP.TSK 01 02:00 // (Executes the 1st of each month at 2:00am) // // TMSCHEDULE ADD TRSTBKUP.TSK YNNNNNN 02:00 // (Executes every Sunday [SMTWTFS] at 2:00am) // // Note: Scheduled tasks must reside either in SYS:SYSTEM or the // TaskMaster NLM load directory for security reasons. // // Compatibility: // ============== // This task has been tested on the following platforms without demonstrating // any compatibility issues or any other reported/confirmed conflicts: // TaskMaster v4.11 (or later), TaskMaster Lite v4.11 (or later) // NetWare v4.1x / v5.x / v6.x (OES) // // Warning: // ======== // AS WITH ANY NEW SOFTWARE PROGRAM, BATCH SCRIPT, OR AUTOMATED PROCESSING // PROCEDURE, CAUTION SHOULD BE EXERCISED AND DUE DILIGENCE OBSERVED DURING // INITIAL IMPLEMENTATION. WHERE POSSIBLE, TESTING SHOULD BE PERFORMED ON // NON-PRODUCTION SYSTEMS PRIOR TO FULL IMPLEMENTATION. // // Comments: // ========= // This task script is provided free of charge and without any warranty or // guarantee of fitness of purpose or performance. // // For additional TaskMaster script examples, visit the Sample Tasks page // on the Avanti Technology, Inc. WEB Site: // // http://www.avanti-tech.com/taskmstr/smpltask.htm // //============================================================================= // Alias Defined Variables using more meaningful variable names for this task VARALIAS %VAR11% %ERR_MSG% VARALIAS %VAR12% %LOG% VARALIAS %VAR20% %ENTRY% VARALIAS %VAR21% %LONGPATH% VARALIAS %VAR22% %DIR_PATH% VARALIAS %VAR23% %RIGHTS% VARALIAS %VAR24% %TRUSTEE% VARALIAS %VAR30% %DATA% VARALIAS %VAR31% %POS% VARALIAS %VAR32% %TEMP% // Check if error log exists and delete it IF EXIST %TASK_PATH%\%TASK_FILE%.ERR THEN DELETE %TASK_PATH%\%TASK_FILE%.ERR // Check that the version of TaskMaster loaded is compatible (v4.11 or later) IF "%TM_VERSION%.%TM_SUBVERSION%%TM_REVISION%"<"4.11" DEFINE %ERR_MSG% Error: Incompatible TaskMaster NLM (req. v4.11 or later)! ENDIF IF NOT "%ERR_MSG%"=="" THEN GOTO EOJ // ***** Logic used by TaskMaster NLM v4.11 and later ***** // ============================================================================ // Determine the Trustee Rights processing desired (base directory and options) // Base: The starting point and subdirectory option (/S) determines // whether the listing is for a Volume (start at SYS:\ and use // the /S option), subdirectory tree (start at SYS:\SYSTEM and use // the /S option), directory (start in SYS:\PUBLIC and do not use // the /S option) or file (use a specific file pattern, no /S option). // Opts: /D Data option (outputs each information item as separate record) // /R Trustee and Rights information // /S Subdirectory recursion // >SYS:\RIGHTS.LOG Redirect the console output to the named file. // // Examples: // SYS:\ /D /R /S (start in SYS: root, entire traverse volume) // SYS:\*.* /D /R /S (start in SYS: root, entire traverse volume) // SYS:\PUBLIC /D /R /S (start in SYS:\APPS, traverse directory tree) // SYS:\PUBLIC\*.* /D /R /S (start in SYS:\APPS, traverse directory tree) // VOL:\APPS /D /R (start in VOL:\APPS, no subdirs processed) // VOL:\APPS\*.DAT /D /R (VOL:\APPS entries matching *.DAT, no subdirs) // // [MODIFY] Make sure the base path/file name (no extension) to use for // creating the .TMP / .LOG / .TSK files is defined correctly. DEFINE %LOG% SYS:\RIGHTS // [MODIFY] Make sure to change the Volume:Path (SYS:\) starting point for the // DIR command as appropriate for your processing requirements. DIR SYS:\ /D /R /S >%LOG%.TMP IF ERRORLEVEL THEN DEFINE %ERR_MSG% Error: DIR processing -> Failed! // IF NOT EXIST %LOG%.TMP THEN DEFINE %ERR_MSG% Error: DIR processing -> Failed! IF NOT "%ERR_MSG%"=="" THEN GOTO EOJ // Open the temporary (output redirected) file for READ processing OPEN READ #0 %LOG%.TMP IF ERRORLEVEL THEN DEFINE %ERR_MSG% Error: OPEN READ #0 %LOG%.TMP Failed! IF NOT "%ERR_MSG%"=="" THEN GOTO EOJ // Open the .LOG file to receive the Trustee Rights documentation OPEN WRITE #0 %LOG%.LOG TRUNCATE IF ERRORLEVEL THEN DEFINE %ERR_MSG% Error: OPEN WRITE #0 %LOG%.LOG Failed! IF NOT "%ERR_MSG%"=="" THEN GOTO EOJ // Open the .TSK file to receive the Trustee Rights restoration commands OPEN WRITE #1 %LOG%.TSK TRUNCATE IF ERRORLEVEL THEN DEFINE %ERR_MSG% Error: OPEN WRITE #0 %LOG%.TSK Failed! IF NOT "%ERR_MSG%"=="" THEN GOTO EOJ // WRITE ECHO header describing the date/time and source of the last execution WRITE #0 // WRITE #0 // Trustee Rights List: %MONTH%/%DAY%/%YEAR% @ %HOUR%:%MINUTE%%AM_PM% WRITE #0 // // WRITE ECHO header describing the date/time and source of the last execution WRITE #1 // WRITE #1 // Trustee Rights Task: %MONTH%/%DAY%/%YEAR% @ %HOUR%:%MINUTE%%AM_PM% WRITE #1 // // READ .TMP (DIR output) and parse the data then write the .LOG / .TSK files WHILE // Read the first/next directory processed (in native Name Space) READ #0 %DIR_PATH% // Check if ERRORLEVEL (indicates EOF, no more data) and BREAK the LOOP IF ERRORLEVEL THEN BREAK // Check if NULL record and CONTINUE the processing (i.e., next record) IF "%DIR_PATH%"=="" THEN CONTINUE // Check data (must have : to be valid path and to have been logged) IF NOT SCAN_STRING ":" "%DIR_PATH%" DEFINE %ERR_MSG% Error: Invalid record in %LOG%.TMP (Directory)! ENDIF IF NOT "%ERR_MSG%"=="" THEN BREAK // Quick work around to retrieve DOS path for %DIR_PATH% DEFINE %TEMP% %CWD% CD "%DIR_PATH%" IF NOT ERRORLEVEL THEN DEFINE %DIR_PATH% %CWD% CD "%TEMP%" // Nested WHILE/LOOP for processing entries in this directory WHILE // Read entire record into temp variable for processing READ #0 %DATA% // Check for End Of File (EOF) IF ERRORLEVEL THEN BREAK // Check if no more trustees IF "%DATA%"=="" THEN BREAK // Check if entry or trustee record IF SCAN_STRING "Trustee:" "%DATA%" // PARSE the Trustee field then REFORMAT it using the PACK option // (i.e. strip trailing spaces) then REPLACE embedded spaces with // underscores. PARSE %TRUSTEE% %DATA% 24-68 REFORMAT %TRUSTEE% PACK REPLACE %TRUSTEE% " _" // Parse the Rights field one character at a time to build %RIGHTS%. // Clear any previously defined Trustee Rights parsed into %RIGHTS%. // Set %POS% to first possible Trustee Right position in %DATA%. // If Trustee Right is enabled (i.e., not '-'), append to %RIGHTS%. // Increment %POS% to next %DATA% position then LOOP to WHILE check. DEFINE %RIGHTS% DEFINE %POS% 71 WHILE "%POS%"<"79" PARSE %TEMP% %DATA% %POS%-%POS% IF NOT "%TEMP%"=="-" THEN DEFINE %RIGHTS% %RIGHTS% %TEMP% DEFINE %POS% %POS%+=01 LOOP // Write the .LOG record WRITE #0 %DATA% // Since GRANT ORs the specified Rights against those that already // exist, first REVOKE ALL Rights then GRANT the specified Rights // to make sure the proper Rights are set. // WRITE a spacer record then the .TSK records WRITE #1 WRITE #1 REVOKE ALL "%LONGPATH%" %TRUSTEE% WRITE #1 GRANT %RIGHTS% "%LONGPATH%" %TRUSTEE% ELSE // Isolate the valid Entry name (i.e., no trailing spaces) then // PARSE the Entry name from %DATA% into %ENTRY%. // Note: Cannot use PARSE / REFORMAT with PACK option as above // as it might strip valid leading zeroes in Entry name. // // Set %POS% beyond last valid Entry name character (which should // be a space) then check each character position and decrement // %POS% if a space is found until %POS% is at the last valid // Entry name character then use %POS% to parse the exact // (DOS) Entry name from %DATA% into %ENTRY%. DEFINE %POS% 14 WHILE "%POS%">"00" PARSE %TEMP% %DATA% %POS%-%POS% IF NOT "%TEMP%"==" " THEN BREAK DEFINE %POS% %POS%-=01 LOOP // If %POS% == 00 then an invalid Entry exists in DIR output IF "%POS%"=="00" DEFINE %ERR_MSG% Error: Invalid Entry in %LOG%.TMP (Entry)! ENDIF // Parse the packed (DOS) Entry name from %DATA% into %ENTRY% PARSE %ENTRY% %DATA% 1-%POS% // Combine %DIR_PATH% & DOS %ENTRY% then convert to Long Name Space DEFINE %LONGPATH% %DIR_PATH%\%ENTRY% DEFINE %LONGPATH% %FILE_NAME_LONG_%LONGPATH%% // WRITE a spacer record then the converted path to the .LOG file WRITE #0 WRITE #0 %LONGPATH% ENDIF // BREAK the WHILE/LOOP if any processing errors exist IF NOT "%ERR_MSG%"=="" THEN BREAK LOOP // BREAK the WHILE/LOOP if any processing errors exist IF NOT "%ERR_MSG%"=="" THEN BREAK LOOP IF NOT "%ERR_MSG%"=="" THEN GOTO EOJ // Either finished processing or had an error (log any error then exit) :EOJ // Close any OPEN READ or OPEN WRITE files CLOSE // Check for and log any errors IF NOT "%ERR_MSG%"=="" // Echo to the screen and log (%TASK_FILE%.ERR) the error message OPEN WRITE #0 %TASK_PATH%\%TASK_FILE%.ERR TRUNCATE ECHO_WRITE. ECHO_WRITE %ERR_MSG% ECHO_WRITE. CLOSE ENDIF