Koozali.org: home of the SME Server

Automatic deletion of files older than x days.

Arne

Automatic deletion of files older than x days.
« on: December 31, 2003, 05:26:59 AM »
A few days ago I had a question about how to make backup copies of the file system to harddisk media.

This gave me some exelent good answears that I could work further on with.

There vere posted a script how to dump the database tables, and tips how to use the dd, the rsync command and the flexbackup system.

All of them worked, but I think the use of the flexbackup system modified for Harddisk storage gave the best ressult.

I used theese two howto's while working with the flexbackup (on e-smith 5.6):

http://www.e-smith.org/docs/howto/contrib/flexbackup-to-disk-howto.htm

http://mirror.contribs.org/smeserver/contribs/dmay/mitel/howto/flexbackup-howto.html

It apears, as far as I can see that the resore has to be don mannually using the howto no 2, but it seems to work ok.

The flexbackup used for storing datas on a harddisk gives a very nice storage format:

root.0.200312301800.dump.gz (With year an date as a part of the file name.)

This is a dated dump of all the files and directories on the root directory, allmost 100 % of it all (exept for a few files/directories that should not be there.)

The backup of the root directory is compressed in such a way that the datas that fills ca 520 MB at my testserver is compressed down to ca 185 MB as a backup. If I had a backup harddisk that were lets say twice as big as the root harddisk I would have room for 6 ea 100 % full backups.

I now the question:

If I just had an automatic prosedure, a cronjob that just checked the backup directory for the age of the stored files, and deleted all that were older than a certain number of day, I could have a backup system that could run 100 % automatic.

The problem just know is that the backup harddisk will run full of backup datafiles after a certain number of days.

Does anyboudy of you know how to make a script that can make an automatic deletion of files in a directory when the files is older than a certain number of days ??

jpk

Re: Automatic deletion of files older than x days.
« Reply #1 on: December 31, 2003, 05:58:52 AM »
search forums under Recycle Bin, or here's one line of what works for me at least (I have it in /etc/cron.daily (within a file))

find /home/e-smith/files/users/*/home/Recycler -type f -mtime +7 -exec rm \{} \;

to delete files older than 7 days (modification time) in users' Recycle Bins (Samba)

Arne

Re: Automatic deletion of files older than x days.
« Reply #2 on: December 31, 2003, 08:41:08 AM »
Sems to be working:

 find /test -type f -mtime +7 -exec rm \{} \;

Remove all files older than 7 days from directory test.

Thanks a lot !

Arne.




From man page, for later ref:


SYNOPSIS
       
find [path...] [expression]


 -type f .. regular file

 -mtime n  .. File's data was last modified n*24 hours ago.

 -exec command ;
             
Execute  command;  true if 0 status is returned.  All following arguments to find are taken to be arguments to the command until an argument consisting of ;' is encountered.  The string {}' is replaced by the current file name being  processed  everywhere it  occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find.  Both of these constructions might need to be escaped (with a ') or quoted to protect them from expansion by the shell.  The command is  exe­ cuted in the starting directory.