Solved

Automatically delete files based on last accessed time

Posted on 2011-03-01
5
841 Views
Last Modified: 2012-05-11
I'm looking for a way to automatically delete files from our SAN based on last accessed time. SAN vendor doesn't have a method to do this but suggested a program called Delete Files by Date Software. I attempted to test this software but they don't offer any trial period, you can download and view files but in order to test it's functionality you must purchase a license, so while I was uninstalling that waste of time I decided to ask the experts.
I had also tried a program called Delenda, which seems to do what I want but doesn't seem to work. I pointed it at a directory (12k files, 3.5GB) and let it run for 24 hours with no progress.
So what I need is a decent program that can run automatically (as a service preferably) that can delete files based on their last accessed time.

Any suggestions?
0
Comment
Question by:js479
  • 2
  • 2
5 Comments
 
LVL 78

Accepted Solution

by:
arnold earned 250 total points
ID: 35011389
To what server is the LUN allocated?
There is a fairly simple perl script that can run through using stat("$filename")[8] will have the atime for the file. Note that if you mount the LUN with noatime option, the atime will not be current/valid.

It will make matters simpler if there is a specific location where you want to check for files.

A similar mechanism can be setup with a Vbscript/C# using fileobject.
You did not specify the platform your server is on and the use of service suggests a windows based platform.
Out of caution, you migh want to consider an intermediary storage location. I.e. move the files to another directory and then after another period of time delete those files from the other directory.

Might Scheduled task also be an option?
0
 
LVL 5

Assisted Solution

by:group0
group0 earned 250 total points
ID: 35015291
If you're running a *nix-based OS and are trying to recursively delete all files from a starting directory that haven't been accessed in at least n days, this can be easily done with find (the syntax varies between the different flavors):

To see the list of affected files (to verify the affected file list is correct)

find /path-to-start-in -atime +n


To delete the affected files:

find /path-to-start-in -atime +n -exec rm -f {} \;


The {} signifies the filename found, so the exec command can easily be changed to just move the file to a temporary location as suggested earlier:

find /path-to-start-in -atime +n -exec mv -f {} /tmp \;


This may work even on a Windows platform, if you have cygwin or its equivalent installed
0
 
LVL 5

Expert Comment

by:group0
ID: 35015305
As I said, the syntax varies between the different platforms, the examples I provided above are for Linux under CentOS.  Make sure to consult the man pages to be sure if you use this.
0
 
LVL 1

Author Comment

by:js479
ID: 35017503
My apologies for not being more specific in the original question.

The SAN is creating CIFS shares that we can connect to via our windows machines. So the SAN is called DC-BA-01 and I create a CIFS share called Work, I can then access and map that CIFS share from any of my windows servers using \\DC-BA-01\work. All of our servers are either windows 2003 or 2008.


0
 
LVL 78

Expert Comment

by:arnold
ID: 35019896
The san is then running a linux based os with samba shares.
Do you have an option to run jobs on the SAN?
If you are a windows shop, you would use vbscript and fileobject to traverse the directoreis looking at each files atime.

There are many examples of using VBscript to list files in directories, etc. that you can use and incorporate into a script that you need to run as a scheduled task to delete these files.
A simple search for "vbscript list files in directory" will provide several examples.
Using the vbscript guide for fileobject access will provide info on how to use it to access the access time, modify time, create time of the file and then compare and perform action on the file as you see fit.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
This video will demonstrate how to find the puppet warp tool from the edit menu and where to put the points to edit.
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question