Script of the week: how to expire files with Classification
It is an eye opening experience to sit at our FCI booth and see customer after customer telling us their biggest problem with managing file servers today: lots of old data sitting on their file servers. When I tell them how that our classification feature solves this problem, it something that always brings a sincere smile on their face.
Creating a file expiration policy is super easy:
- Open FSRM management console
- Go to the "File Management Tasks" view
- Create a file management task to expire your files. You need to specify the following settings:
- The source directory of files to be expired
- The target directory (containing expired files)
- A condition for expiration (such as files created ten years ago (or files that were not modified in the last year)
- A schedule (say, weekly)
Here is an example of the Action tab:
That's it. One simple task to solve the "old files lying around" problem.
Now, a note to be added: the effect of this command will be the to move these expired files into the target location (while trying to keep the original path). One effect though is that the original files will "disappear" from the original location, which in rare cases it might cause confusion to the end users. If you are concerned about that problem, the solution is easy: as part of the file management task you can run your own custom "move" command which leaves in the original path a "stub" (a text file) explaining where the files have gone. Or, you can replace the original files with a symbolic link (or some other form of link) pointing to the target location.
To do this, you need to do a few things:
- In the File Management Task dialog, in the Action tab, change the task type from "File expiration" to "Custom". Several more options appear (such as the path to the custom script, the account the script will run under, etc)
- Add the [Source File path] macro to the script arguments
- Run the command as "local system" (so it will be able to perform the move operation).
Here is an example of how the task will look like:
The move_file_and_leave_link.cmd (located in c:\windows\system32) file is simple:
if exist "c:\protected\%~pnx1" @echo Target file already exists! & goto :EOF
move %1 "c:\protected\%~p1"
mklink %1 "c:\protected\%~pnx1"
The last command (mklink) has the role of creating a symbolic link from the source to the target. That’s it!