Page 1 of 1

Cleanup Archive Docs

Posted: Tue Feb 28, 2012 12:34 pm
by RElliott63
(GAD v4.0.0)

If you save inbound/outbound documents for Archiving and sometimes forget to go back and weed out the older ones, here's a way to take care of that by adding this to the end of your Project.

It's a cleanup utility Project that will take 2 parameters ( RetainDays & CleanDIR )

RetainDays = Number of days for Cutoff of documents to retain.
CleanDIR = The root Directory that you want to start cleaning from.

The Project is recursive, so the cleanup will process all sub-folders under the "CleanDir" location as well.

This utility will also print a list of the files removed for reference.

I usually just call this from a Project Module (as in):
Code: Select all
	
<project>
<module name="Main">
...
     <callModule module="Cleanup"  label="(Module) Cleanup"  version="1.0" />
...
</module>

<module name="Cleanup" description="Clean up Older Documents from Archive">

		<callProject label="Cleanup Archive Docs" project="/Utilities/Cleanup Archive Docs" runInSameJob="true" inheritUserVariables="true" version="1.0">
			<variable name="RetainDays" value="${ RetainDays }" />
			<variable name="CleanDIR"   value="${ DirectorDIR }" />
		</callProject>

</module>
</project>
You may want to perform this Project Call as a Batch job instead of interactive. Just to remove it from the current job stream and treat it as a separate function.



Code: Select all
<project name="Cleanup Archive Docs" mainModule="Main" version="2.0" logLevel="debug" onError="call:Error Handler">

  <!-- Passed Parms -->
	<variable name="RetainDays" value="60" description="No of Days to retain (Default = 60)" />
	<variable name="CleanDIR"   value=""   description="Directory to Clean" />

	<module name="Main">

    <if label="Check RetainDays Value" condition="${ ( RetainDays eq system.emptyString ) or ( RetainDays eq 0 ) }">
  		<print label="(Status) Invalid RetainDays" version="1.0">
  			<![CDATA[
*===============================================================================*
 *** Cleaning Up Archive ***
 "RetainDays" Parameter must be Greater than Zero.
 Change value and retry.
*===============================================================================* 
        ]]>
  		</print>
      <exitModule/>
    </if>

    <if label="Check CleanDIR Value" condition="${ CleanDIR eq system.emptyString }">
  		<print label="(Status) Invalid CleanDIR" version="1.0">
  			<![CDATA[
*===============================================================================*
 *** Cleaning Up Archive ***
 "CleanDIR" Parameter must not be blank.
 Change value to a valid directory and retry.
*===============================================================================* 
        ]]>
  		</print>
      <exitModule/>
    </if>

    <!-- Get Cutoff Date -->
		<timestamp label="Set TimeStamp" version="1.0">
			<format outputVariable="CutOffDate" pattern="yyyy-MM-dd" dayOfMonth="-${ RetainDays }" />
		</timestamp>

		<print label="(Status) Cleanup Cutoff" version="1.0">
			<![CDATA[
*===============================================================================*
*   Clean Dir:  ${ CleanDIR } 
* CutOff Date:  ${ CutOffDate } -- Removing files over ${ RetainDays } Days Old
*===============================================================================* 
      ]]>
		</print>

    <!-- Get list of files to be removed -->
		<createFileList label="Get Files to Remove" fileListVariable="RemoveFiles" numFilesFoundVariable="NoFiles" version="1.0">
			<fileset dir="${ CleanDIR }" recursive="true">
				<dateFilter>
					<include to="${ CutOffDate }" />
				</dateFilter>
			</fileset>
		</createFileList>

    <!-- Remove files - Generate File Removal List -->
    <setVariable label="Set FileList" name="FileList" value="${ system.emptyString }" version="1.0" />
		<forEachLoop label="Remove Outdated Files" itemsVariable="${RemoveFiles}" currentItemVariable="ThisFile">
      <setVariable label="Get FileList" name="FileList" value="${ FileList }${ system.carriageReturn }Removing ${ ThisFile:name } - ${ ThisFile:lastModifiedDate }" version="1.0" />
  		<delete label="Remove File" file="${ ThisFile }" version="1.0" />
    </forEachLoop>

		<print label="(Status) Cleanup List" version="1.0">
			<![CDATA[
*===============================================================================*
* Clean Dir:  ${ CleanDIR }
*===============================================================================*
${ FileList }    
*===============================================================================* 
${ NoFiles } file(s) removed
*===============================================================================* 
      ]]>
		</print>

	</module>

	<module name="Error Handler" description="Handle Process Errors">

		<timestamp label="Set TimeStamp" version="1.0">
			<format outputVariable="DateSent" pattern="yyyy-MM-dd" />
			<format outputVariable="TimeSent" pattern="hh:mm:ss" />
		</timestamp>

		<print label="Error Status" version="1.0">
			<![CDATA[  
*================================================*
*************** ERROR HANDLER ********************
*================================================*
*   Job Step:  ** Process Error **
*       Date:  ${DateSent} 
*       Time:  ${TimeSent}
*      Error:  ${system.job.error}
*================================================* 
      ]]>
		</print>

	</module>

	<description>Cleanup Archive Directory</description>

</project>
You always have the option to manually call this Utility from an "Execute Advanced" prompt and give it the folder you need to clean with number of days to retain.

As always .. if you have any questions, please let me know.

-Rick