Solved

Automatically delete files based on last accessed time

Posted on 2011-03-01
5
839 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 77

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 77

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
If your app took Google’s lash recently, here are the 5 most likely reasons.
This video demonstrates basic masking and how to edit the mask to reveal the desired image.
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

911 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now