//============================================================================= // // Task: SYNC-3YR.TSK // (SYNC selected files less than 3 years old with activity log) // Author: Avanti Technology, Inc. // http://www.avanti-tech.com // Version: 1.1 - Updated Release // (15 April 2002) // // Description: // ============ // This task is designed to synchronize a select group of files meeting the // following criteria between directories at separate remote Sites (each // considered a source) and the local host Site (destination) directory: // // 1). Only process source files matching *.xls,*.mdb,*.doc,*.pdf and *.ppt // 2). If the source file matching #1 is more than three years old, exclude it. // 3). If the source file matching #1 is less than three years old and // newer than the destination file, sync the source to the destination. // 4). Once all of the files matching 1-3 are processed, delete any extraneous // destination files (i.e., files without matching source files). // // To accomodate rule #3, we will use the Exclusion File option in SYNC to // exclude all files not meeting rule #3. // // Since this task is going to be used to consolidate the files from several // remote Site (source) directories into a single host Site (destination) // directory, this task will require parameters to be passed on the command // line which specify the remote Site (source) directory (on the Server // actually running the task) and the host Site (destination) directory // (where the files will be copied). The command line parameter method // was chosen to allow a single task to be used for all the remote Sites, // maximizing task maintenance efficiency and reducing the chance of errors. // // This task should be submitted to the remote Sites using the TMSCMD either // from the TMConsole (Shell) prompt or within a scheduled task as follows: // // TMSCMD [remoteServer] TMRUN SYNC-3YR.TSK [sVol:\sPath] [dServer/dVol:\dPath] // // Example: TMSCMD AUSTIN TMRUN SYNC-3YR.TSK APPS:DATA HOST/APPS:DATA // Synchronizes the files on AUSTIN/APPS:DATA -> HOST/APPS:DATA // based upon the criteria described above in items 1 - 4 // // Notes: sVol:\sPath is the local (source) directory for the TMSCMD Server. // A valid Volume name and Path specification is required (no file spec). // // dServer/dVol:\dPath is the host (destination) directory (Server, // Volume, and Path) where the matching files are to be copied. // // Upon completion, the destination directory should contain a SYNC-3YR.LOG // file documenting the processing which transpired. // // Via a scheduled task at the host Site which contains an appropriate TMSCMD // for each remote Site, the updates can be scheduled and processed using a // single task. // // Notes: Each remote Site Server must have a TaskMaster NLM loaded. // // This task will have to reside on each remote Site's Server or be // copied to the remote Site prior to executing the TMSCMD command. // // System Environment Variables (%0 - %9) used/usage: // -------------------------------------------------- // %0 Remote Site source directory (first parameter following task name) // %1 Host Site destination directory (second parameter following task name) // %2 First/Next dir match in source (set by %DIR_SUB_%) // %3 First/Next file match in source (set by %DIR_FILE_%) // %7 Date three years ago today (set using CALC/DEFINE) // %8 SYNC Exclusion File log (set by DEFINE) // %9 Temporary LOG file (set by DEFINE) // // The internal System Environment Variables are used to simplify processing // and maintenance on the script. For example, using %9 in place of the LOG // file name allows us to easily change the LOG file throughout the task // merely by changing the DEFINE which sets its value. // // Compatibility: // ============== // This task has been tested on the following platforms without demonstrating // any compatibility issues or any other reported/confirmed conflicts: // TaskMaster v3.15b (or later), TaskMaster Lite v3.15b (or later) // NetWare v3.12 / v3.2 / v4.1x / v5.x / v6.0 // // 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 //============================================================================= // Check that the version of TaskMaster loaded is compatible (3.15b or later) IF "%TM_VERSION%.%TM_SUBVERSION%%TM_REVISION%"<"3.15b" // Echo the problem message to the screen ECHO. ECHO Error: Incompatible TaskMaster release (requires v3.15b or later)! ECHO. ABORT ENDIF // Set the temporary LOG file name to track the processing DEFINE %9 SYS:SYSTEM\SYNC-3YR.LOG // Set the Exclusion List file name used to exclude files from SYNC processing DEFINE %8 SYS:SYSTEM\SYNC-3YR.EXC // Create the processing status file (TRUNCATE overwrites) OPEN_WRITE %9 TRUNCATE // Record a header record to log start time WRITE *************************************** WRITE SYNC-3YR started: %MONTH%/%DAY%/%YEAR% @ %HOUR%:%MINUTE%%AM_PM% WRITE *************************************** // Check that the remote Site (source) directory was specified IF "%0"=="" ECHO_WRITE ERROR: No Remote Site (source) directory specified! ECHO_WRITE ABORT: Processing terminated! CLOSE GOTO EOJ ENDIF // Check for a valid remote Site (source) directory IF NOT EXIST %0 ECHO_WRITE ERROR: %0 - Invalid Remote Site (source) directory! ECHO_WRITE ABORT: Processing terminated! CLOSE GOTO EOJ ENDIF // Check that the host Site (destination) directory was specified IF "%1"=="" ECHO_WRITE ERROR: No Host Site (destination) directory specified! ECHO_WRITE ABORT: Processing terminated! CLOSE GOTO EOJ ENDIF // First, change the Current Working Directory (CWD) to the source directory CD %0 // Define %7 as the same date three years ago using CALC to set %7 to the year // (i.e., current year - 3) then appending the current month & day fields to %7 CALC %7 %YEAR%-3 DEFINE %7 %7/%MONTH%/%DAY% // Record our status WRITE Exclude files not matching the specified patterns or older than %7 WRITE %CWD% - Processing... // Create Exclusion List for SYNC file exclusions (TRUNCATE overwrites) // Note: Processing status file is closed by re-use of OPEN_WRITE OPEN_WRITE %8 TRUNCATE // Base WHILE/LOOP for processing subdirectory tree // Initial pass of embedded WHILE/LOOP defaults to the base directory (%0). // Subsequent passes process the %DIR_TREE_% returned directories (%2). WHILE // Main WHILE/LOOP for all processing... WHILE // Check if first WHILE/LOOP pass (%3 == NULL) in this directory // If so, we must specify the search pattern to use (FIND FIRST) // If not, resume processing previous specified pattern (FIND NEXT) IF "%3"=="" DEFINE %3 %DIR_FILE_%CWD%\*.*% ELSE DEFINE %3 %DIR_FILE_% ENDIF // Check that a file was returned else no more matching files exist IF "%3"=="" THEN BREAK // Check returned file (%3) against desired pattern AND if < 3 yrs old // If both criteria match, advance to next file (only write exclusions) IF SCAN_STRING ".DOC" "%3" AND "%FILE_UPDATE_%CWD%\%3%">"%7" THEN CONTINUE IF SCAN_STRING ".MDB" "%3" AND "%FILE_UPDATE_%CWD%\%3%">"%7" THEN CONTINUE IF SCAN_STRING ".PDF" "%3" AND "%FILE_UPDATE_%CWD%\%3%">"%7" THEN CONTINUE IF SCAN_STRING ".PPT" "%3" AND "%FILE_UPDATE_%CWD%\%3%">"%7" THEN CONTINUE IF SCAN_STRING ".XLS" "%3" AND "%FILE_UPDATE_%CWD%\%3%">"%7" THEN CONTINUE // Either does not match desired patterns or > 3 yrs old so exclude it WRITE %CWD%\%3 LOOP // Check if embedded WHILE/LOOP processed base directory (%2 == NULL) // If so, we must specify the search pattern to use (FIND FIRST) // If not, continue processing previously specified pattern (FIND NEXT) IF "%2"=="" DEFINE %2 %DIR_TREE_%CWD%% ELSE DEFINE %2 %DIR_TREE_% ENDIF // Check that a directory was returned else no more matching files exist IF "%2"=="" THEN BREAK LOOP // We're ready to SYNC the files so let's close the Exclusion List file // by re-opening the Processing Status file and recording our status then // close the Processing Status file so the SYNC output can be redirected to it OPEN_WRITE %9 WRITE Updating the directories/files using SYNC... CLOSE // At this point, the exclusion list should contain the files not matching // the specified patterns or more than three years old so now use SYNC to // synchronize the source and destination directories (specifying the // exclusion list of files which should be ignored by SYNC). // Note: The /A option will add to the destination any new files which // only exist on the source, the /D option will delete any files // and directories on the destination but not on the source, and // the /S option will traverse the subdirectory tree. // The Excluded List of files (%8) are redirected into the SYNC while // the SYNC output is appended to the Processing Status file (%9). SYNC %CWD%\*.* %1 /A /D /I /L /M /S <%8 >>%9 // Re-open the Processing Status file to record the completion :EOJ // Copy the LOG file to the destination (host) Server SCOPY %9 %1\*.* // If the copy was successful, delete the LOG file IF NOT ERRORLEVEL DELETE %9 ENDIF // Delete the Exclusion List file (if it exists, i.e., no early errors) IF EXIST %8 DELETE %8 ENDIF