If you have a cluster share that contains temporary data in separate top-level directories, this post may help you automate the security and purging of that shared data. This is useful for transient data such as drop directories for scanners and faxes, or scratch directories for general sharing.
To summarise, this will provide:
- A cluster-based scheduled task that runs each day, dependant on the network name and physical disk resource currently hosting the directory
- A batch file run by the scheduled task that secures each directory, and purges files older than 30 days, logging results to the physical node hosting the resource.
Creating the Scheduled Task
- Create the scheduled task cluster resource:
cluster /cluster:%cluster% res "%resource_name%" /create /group:"%cluster_group%" /type:"Volume Shadow Copy Service Task"
cluster /cluster:%cluster% res "%resource_name%" /priv ApplicationName="cmd.exe"
cluster /cluster:%cluster% res "%resource_name%" /priv ApplicationParams="/c c:\admin\SecureAndPurge.bat"
cluster /cluster:%cluster% res "%resource_name%" /priv CurrentDirectory=""
cluster /cluster:%cluster% res "%resource_name%" /prop Description="%resource_name%"
cluster /cluster:%cluster% res "%resource_name%" /AddDep:"%network_name_resource%"
cluster /cluster:%cluster% res "%resource_name%" /AddDep:"%disk_resource%"
cluster /cluster:%cluster% res "%resource_name%" /On
cluster /cluster:%cluster% res "%resource_name%" /prop RestartAction=1 - Set the schedule for the cluster resource:
• Use the cluster administrator GUI, this cannot currently be set with cluster.exe with the VSS scheduled task cluster resource - Restart the resource to pickup the schedule change:
cluster /cluster:%cluster% res "%resource_name%" /Off
cluster /cluster:%cluster% res "%resource_name%" /On
Note that the cluster resource providing scheduled task capability is the ‘Volume Shadow Copy Service Task’ resource. This is a recommended solution from Microsoft for providing scheduled task capability on a cluster. See the ‘Cluster Resource’ document in the references below.
The LooksAlive and IsAlive functions for the VSSTask.dll simply check that the scheduled task is known to the local task scheduler. To further reduce the impact of resource failure, the resource should be marked as not affecting the cluster, preventing potential failover if this task were to fail more than three times (by default).
The scheduled task should run a simple batch file on the local disk of the cluster node. Keeping the batch file local further reduces the risk that problems with the batch file could cause the cluster group to fail. The theory is that if the batch file is on local disk, it can be modified/deleted before bringing the cluster resources online.
Creating the batch file
Create a batch file and set some environment variables for %directory%, %purgeDir%, %domain%, %logFile%, %AdminUtil%, %FileAge% to fit your environment, and then include at least the three commands below:
- Set the security on each directory within the directory. Note that this assumes that for each directory, there is a matching same-named security group, prefixed with l (for local), eg lDirectory1.
for /d %%i in (%Directory%\*) do cacls %%i /e /g %Domain%\l%%~ni:C >> %LogFile% - Move the files with robocopy that are older than %FileAge% days:
%AdminUtil%\robocopy %Directory% "%PurgeDir%" *.* /minage:%FileAge% /v /fp /ts /mov /e /r:1 /w:1 /log+:%LogFile% - Delete the files that were moved:
If Exist "%PurgeDir%" rd /s /q "%PurgeDir%"
Note that depending on the size of data, you might want to ensure that the purgedir is on the same volume as the source files, which won't use any disk space as the files are moved. If the purgedir was on a different drive you would temporarily need as much free space as the size of data being purged.
References:
Cluster resource
http://technet2.microsoft.com/windowsserver/en/library/f6b35982-b355-4b55-8d7f-33127ded5d371033.mspx?mfr=true
Volume Shadow Copy Service resource type
http://technet2.microsoft.com/windowsserver/en/library/bc7b7f3a-d477-42b8-8f2d-a99748e3db3b1033.mspx?mfr=true
Using Shadow Copies of Shared Folders in a server cluster
http://technet2.microsoft.com/windowsserver/en/library/66a9936d-2234-411f-87b4-9699d5401c8c1033.mspx?mfr=true
Scheduled task does not run after you push the task to another computer
http://support.microsoft.com/kb/317529
Scheduled Task for the Shadow Copies of Shared Folders Feature May Not Run on a Windows Server 2003 Cluster
http://support.microsoft.com/kb/828259
Behavior of the LooksAlive and IsAlive functions for the resources that are included in the Windows Server Clustering component of Windows Server 2003
http://support.microsoft.com/kb/914458
Generic Cluster-enabled Scheduled Tasks:
http://waynes-world-it.blogspot.com/2008/04/2003-cluster-enabled-scheduled-tasks.html
Wayne's World of IT (WWoIT), Copyright 2008 Wayne Martin.
No comments:
Post a Comment